Adding start of an editor.

This commit is contained in:
Brad Nelson
2021-01-26 12:43:54 -08:00
parent 3448da192d
commit 87a2262fe3
2 changed files with 37 additions and 0 deletions

5
ueforth/common/editor.fs Normal file
View File

@ -0,0 +1,5 @@
include posix/termios.fs
create keymap
: edit raw-mode begin key . again ;

32
ueforth/posix/termios.fs Normal file
View File

@ -0,0 +1,32 @@
( Terminal Handling )
z" tcgetattr" 2 sysfunc tcgetattr
z" tcsetattr" 3 sysfunc tcsetattr
z" fcntl" 3 sysfunc fcntl
( Blocking )
4 constant F_SETFL
2048 constant FNDELAY
: nodelay-mode stdin F_SETFL FNDELAY fcntl throw ;
: delay-mode stdin F_SETFL 0 fcntl throw ;
( Raw Mode )
4 16 * 20 + constant sizeof(termios)
create old-termios sizeof(termios) allot
create new-termios sizeof(termios) allot
: .c_lflag 3 4 * + ;
: .c_cc[] 4 4 * + + ;
2 constant ICANON
8 constant _ECHO
2 constant TCSAFLUSH
5 constant VTIME
6 constant VMIN
: termios@ ( a -- ) stdin swap tcgetattr drop ;
: termios! ( a -- ) stdin TCSAFLUSH rot tcsetattr throw ;
old-termios termios@
: raw-mode new-termios termios@
_ECHO ICANON or invert new-termios .c_lflag l@ and new-termios .c_lflag l!
0 VTIME new-termios .c_cc[] c!
0 VMIN new-termios .c_cc[] c!
new-termios termios! ;
: normal-mode old-termios termios! ;