muforth/lib/tty.mu4

( This file is part of muFORTH: http://pages.nimblemachines.com/muforth

  Copyright 2002-2008 David Frech. All rights reserved, and all wrongs
  reversed. (See the file COPYRIGHT for details.)

( Raw/cooked tty modes.)

( We need these words to make dumping memory, decompiling code, and
  disassembling more beautiful. Eventually all console i/o should be
  in raw mode...)

: tty  [ z" /dev/tty" r/w open-file ] ;

: cooked-termios  [ ram  tty ram get-termios allot ] ;

: raw  ( fd)
  dup ram get-termios drop   ram set-termios-raw  ( disallow signals)
  ram 1 0 set-termios-min-time  ( fd)  ram set-termios  ( set to raw!)  ;

: cooked  ( fd)
  cooked-termios set-termios ;

( common key names)
: #BS   [   8 ] ;
: #LF   [  10 ] ;
: #CR   [  13 ] ;
: #ESC  [  27 ] ;  ( aka ctrl [ )
: #DEL  [ 127 ] ;