Skip to content

Commit

Permalink
set winsize
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsang committed Oct 13, 2018
1 parent ebed58a commit 9393b53
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
42 changes: 32 additions & 10 deletions PTerm-Core/LibPTerm.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,50 @@ Class {
#category : #'PTerm-Core'
}

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> F_GETFL [
^3
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> F_SETFL [
^4
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> O_NONBLOCK [
Smalltalk os isMacOS ifTrue: [ ^4 ].
^4000
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> O_RDWR [
^2
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> SIGKILL [
^ 9
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> ST_WINSIZE [
^8
]

{ #category : #'C-constants' }
LibPTerm class >> TIOCGWINSZ [
Smalltalk os isMacOS ifTrue: [ ^1074295912 ].
^21523
]

{ #category : #'C-constants' }
LibPTerm class >> TIOCSWINSZ [
Smalltalk os isMacOS ifTrue: [ ^2148037735 ].
^21524
]

{ #category : #compilation }
LibPTerm class >> compile [
|cmd arch st fp|
fp := self mksource.
Expand All @@ -50,7 +67,7 @@ LibPTerm class >> compile [
'./libpterm.o' asFileReference delete
]

{ #category : #'as yet unclassified' }
{ #category : #compilation }
LibPTerm class >> mksource [
|file stream|
file := './libpterm.c' asFileReference.
Expand All @@ -71,13 +88,13 @@ LibPTerm class >> singleton [
^ self uniqueInstance
]

{ #category : #'as yet unclassified' }
{ #category : #'C-constants' }
LibPTerm class >> sizeOfFileAction [
"we fix it to 80 for now"
^80
]

{ #category : #'as yet unclassified' }
{ #category : #compilation }
LibPTerm class >> source [
^ '
#define _GNU_SOURCE
Expand Down Expand Up @@ -194,6 +211,11 @@ LibPTerm >> grantpt: fd [
^ self ffiCall: #(int grantpt(int fd)) module: LibC
]

{ #category : #'as yet unclassified' }
LibPTerm >> ioct: fd cmd: cmd arg: arg [
^ self ffiCall: #(int ioctl(int fd, ulong cmd, void* arg)) module: LibC
]

{ #category : #accessing }
LibPTerm >> kill: pid signal: sig [
^ self ffiCall: #(int kill(int pid, int sig)) module: LibC
Expand Down Expand Up @@ -278,7 +300,7 @@ LibPTerm >> ttySpawn: fd argv: argv envs:envs [

{ #category : #'as yet unclassified' }
LibPTerm >> ttyWinSize: fd rows:rows cols:cols [
^ self ffiCall: #(int tty_set_winsize(int fd, int rows, int cols))
^ self ffiCall: #(int tty_set_winsize_(int fd, int rows, int cols))
]

{ #category : #'accessing platform' }
Expand Down
18 changes: 17 additions & 1 deletion PTerm-Core/PTerm.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,23 @@ PTerm >> run [

{ #category : #initialization }
PTerm >> setWinsize: point [
[self lib ttyWinSize: self master rows: point y cols: point x] on: Error do: [ ]
|buf arr st|
[self lib ttyWinSize: self master rows: point y cols: point x] on: Error do: [
Transcript show: 'fallback to in image solution ', point asString; cr.
buf := FFIExternalArray externalNewType: 'uint8' size: self lib class ST_WINSIZE.
arr := point y asByteArrayOfSize: 2.
buf at: 1 put: (arr at:2).
buf at:2 put: (arr at: 1).
arr := point x asByteArrayOfSize: 2.
buf at: 3 put: (arr at: 2).
buf at: 4 put: (arr at:1).
buf at: 5 put: 0.
buf at: 6 put: 0.
buf at: 7 put: 0.
buf at: 8 put:0.
st := self lib ioct: self master cmd: self lib class TIOCSWINSZ arg: buf getHandle.
st = 0 ifFalse:[^self error: 'Cannot set window size']
]
]

{ #category : #'instance creation' }
Expand Down

0 comments on commit 9393b53

Please sign in to comment.