Fixing terminal

This commit is contained in:
Brad Nelson
2021-02-13 08:03:35 -08:00
parent 13ca4f7f7a
commit c6cd498908
7 changed files with 28 additions and 8 deletions

View File

@ -120,7 +120,7 @@ $(GEN):
mkdir -p $@ mkdir -p $@
POSIX_BOOT = common/boot.fs common/vocabulary.fs common/hide_calls.fs common/ansi.fs \ POSIX_BOOT = common/boot.fs common/vocabulary.fs common/hide_calls.fs common/ansi.fs \
posix/posix.fs posix/posix_highlevel.fs \ posix/posix.fs posix/posix_highlevel.fs posix/termios.fs \
common/utils.fs common/highlevel.fs common/filetools.fs posix/posix_desktop.fs \ common/utils.fs common/highlevel.fs common/filetools.fs posix/posix_desktop.fs \
common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)

View File

@ -5,10 +5,11 @@ internals definitions
: arduino-type ( a n -- ) Serial.write drop ; : arduino-type ( a n -- ) Serial.write drop ;
' arduino-type is type ' arduino-type is type
: arduino-key ( -- n ) : arduino-key ( -- n )
begin Serial.available until 0 >r rp@ 1 Serial.readBytes drop r> ; begin Serial.available if 0 >r rp@ 1 Serial.readBytes drop r> dup 13 <> if exit then then again ;
' arduino-key is key ' arduino-key is key
: arduino-key? ( -- n ) Serial.available ;
' arduino-key? is key?
forth definitions forth definitions
: key? ( -- n ) Serial.available ;
( Map Arduino / ESP32 things to shorter names. ) ( Map Arduino / ESP32 things to shorter names. )
: pin ( n pin# -- ) swap digitalWrite ; : pin ( n pin# -- ) swap digitalWrite ;

View File

@ -19,6 +19,7 @@
: > ( a b -- a>b ) swap - 0< ; : > ( a b -- a>b ) swap - 0< ;
: = ( a b -- a!=b ) - 0= ; : = ( a b -- a!=b ) - 0= ;
: <> ( a b -- a!=b ) = 0= ; : <> ( a b -- a!=b ) = 0= ;
: 0<> ( n -- n) 0= 0= ;
: bl 32 ; : nl 10 ; : bl 32 ; : nl 10 ;
: 1+ 1 + ; : 1- 1 - ; : 1+ 1 + ; : 1- 1 - ;
: 2* 2 * ; : 2/ 2 / ; : 2* 2 * ; : 2/ 2 / ;
@ -140,6 +141,7 @@ variable handler
( Defer I/O to platform specific ) ( Defer I/O to platform specific )
defer type defer type
defer key defer key
defer key?
defer bye defer bye
: emit ( n -- ) >r rp@ 1 type rdrop ; : emit ( n -- ) >r rp@ 1 type rdrop ;
: space bl emit ; : cr nl emit ; : space bl emit ; : cr nl emit ;

View File

@ -1,10 +1,9 @@
include posix/termios.fs also posix
s" /dev/ttyS3" r/w O_NONBLOCK or open-file throw constant remote s" /dev/ttyS3" r/w O_NONBLOCK or open-file throw constant remote
: remote-type ( a n -- ) remote write-file throw ; : remote-type ( a n -- ) remote write-file throw ;
: remote-emit ( ch -- ) >r rp@ 1 remote-type rdrop ; : remote-emit ( ch -- ) >r rp@ 1 remote-type rdrop ;
: remote-key ( -- ch|0 ) : remote-key ( -- ch|0 )
0 >r rp@ 1 remote read-file dup EAGAIN = if rdrop 2drop 0 exit then 0 >r rp@ 1 remote read-file dup EAGAIN = if rdrop 2drop 0 exit then
throw if r> else rdrop 0 then ; throw if r> else rdrop 0 then ;
: terminal nodelay-mode begin key dup if remote-emit else drop then : terminal begin remote-key dup if emit else drop then
remote-key dup if emit else drop then again ; key? if key remote-emit then again ;

View File

@ -1,5 +1,7 @@
( Terminal Handling ) ( Terminal Handling )
vocabulary termios termios definitions also posix
z" tcgetattr" 2 sysfunc tcgetattr z" tcgetattr" 2 sysfunc tcgetattr
z" tcsetattr" 3 sysfunc tcsetattr z" tcsetattr" 3 sysfunc tcsetattr
z" fcntl" 3 sysfunc fcntl z" fcntl" 3 sysfunc fcntl
@ -38,3 +40,17 @@ $5413 constant TIOCGWINSZ
create winsize sizeof(winsize) allot create winsize sizeof(winsize) allot
: form ( -- h w ) stdin TIOCGWINSZ winsize ioctl throw : form ( -- h w ) stdin TIOCGWINSZ winsize ioctl throw
winsize l@ dup $ffff and swap $10000 / ; winsize l@ dup $ffff and swap $10000 / ;
0 value pending
: termios-key? ( -- f ) pending if -1 else stdin-key to pending pending 0<> then ;
: termios-key ( -- n ) begin termios-key? 0= while repeat pending 0 to pending ;
nodelay-mode
' termios-key is key
' termios-key? is key?
forth definitions
: form form ;
only forth definitions

View File

@ -1,3 +1,4 @@
also windows
s" \\.\COM3" r/w open-file throw constant remote s" \\.\COM3" r/w open-file throw constant remote
: remote-type ( a n -- ) remote write-file throw ; : remote-type ( a n -- ) remote write-file throw ;
: remote-emit ( ch -- ) >r rp@ 1 remote-type rdrop ; : remote-emit ( ch -- ) >r rp@ 1 remote-type rdrop ;

View File

@ -80,7 +80,8 @@ stdout console-mode @ ENABLE_VIRTUAL_TERMINAL_PROCESSING or SetConsoleMode drop
: win-type ( a n -- ) stdout -rot NULL NULL WriteFile drop ; : win-type ( a n -- ) stdout -rot NULL NULL WriteFile drop ;
' win-type is type ' win-type is type
: raw-key ( -- n ) 0 >r stdin rp@ 1 NULL NULL ReadFile drop r> ; : raw-key ( -- n ) 0 >r stdin rp@ 1 NULL NULL ReadFile drop r> ;
: key? ( -- f ) stdin 0 WaitForSingleObject 0= ; : win-key? ( -- f ) stdin 0 WaitForSingleObject 0= ;
' win-key? is key?
: win-key ( -- n ) raw-key dup 13 = if drop nl then ; : win-key ( -- n ) raw-key dup 13 = if drop nl then ;
' win-key is key ' win-key is key
: win-bye ( -- ) 0 ExitProcess drop ; : win-bye ( -- ) 0 ExitProcess drop ;