diff --git a/common/forth_namespace_tests.fs b/common/forth_namespace_tests.fs index 68b5718..0933ba7 100644 --- a/common/forth_namespace_tests.fs +++ b/common/forth_namespace_tests.fs @@ -458,6 +458,7 @@ e: check-ansi e: check-tasks out: start-task out: task + out: pause? out: pause out: tasks ;e @@ -566,13 +567,13 @@ e: test-windows-forth-namespace e: test-posix-forth-voclist internals ' sockets voclist-from out: sockets + out: termios out: internals out: graphics out: ansi out: editor out: streams out: tasks - out: termios out: posix out: structures out: internalized @@ -589,11 +590,11 @@ e: test-posix-forth-namespace out: telnetd out: sockets out: x11 + out: form + out: termios check-desktop check-filetools check-phase2 - out: form - out: termios check-allocation out: ok out: pwd diff --git a/common/tasks.fs b/common/tasks.fs index 96b4ec8..4f8f21f 100644 --- a/common/tasks.fs +++ b/common/tasks.fs @@ -28,6 +28,9 @@ forth definitions tasks also internals task-list @ cell+ @ sp! rp! ; +( Check if there are other tasks. ) +: pause? ( -- f ) task-list @ dup @ <> ; + : task ( xt dsz rsz "name" ) create here >r 0 , 0 , ( link, sp ) swap here cell+ r@ cell+ ! cells allot diff --git a/posix/posix_boot.fs b/posix/posix_boot.fs index 502e2da..8a8bb07 100644 --- a/posix/posix_boot.fs +++ b/posix/posix_boot.fs @@ -15,10 +15,10 @@ needs ../common/phase1.fs needs posix.fs needs allocation.fs -needs termios.fs needs ../common/phase2.fs needs ../common/phase_filetools.fs needs ../common/phase_desktop.fs +needs termios.fs needs x11.fs needs graphics.fs needs sockets.fs diff --git a/posix/termios.fs b/posix/termios.fs index 6564e05..9d06ec6 100644 --- a/posix/termios.fs +++ b/posix/termios.fs @@ -38,12 +38,14 @@ create new-termios sizeof(termios) allot : termios@ ( a -- ) stdin swap tcgetattr drop ; : termios! ( a -- ) stdin TCSAFLUSH rot tcsetattr throw ; old-termios termios@ -: raw-mode new-termios termios@ +: raw-mode stdin isatty 0= if exit then + new-termios termios@ _ECHO ICANON or invert new-termios .c_lflag sl@ 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! ; +: normal-mode stdin isatty 0= if exit then + old-termios termios! ; ( Screen Size ) $5413 constant TIOCGWINSZ @@ -53,12 +55,36 @@ create winsize sizeof(winsize) allot winsize sl@ 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 ; +: termios-key? ( -- f ) + pending if + -1 + else + nodelay-mode + stdin-key to pending + pending 0<> + then +; +: termios-key ( -- n ) + begin termios-key? 0= while + pause? if + pause + else + delay-mode + stdin-key to pending + then + repeat + pending 0 to pending +; + +raw-mode +: termios-terminate ( n -- ) + normal-mode + sysexit +; -nodelay-mode ' termios-key is key ' termios-key? is key? +' termios-terminate is terminate forth definitions