Diff for /gforth/ekey.fs between versions 1.21 and 1.26

version 1.21, 2008/11/08 19:43:50 version 1.26, 2009/12/31 15:32:35
Line 1 Line 1
 \ ekey etc.  \ ekey etc.
   
 \ Copyright (C) 1999,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.  \ Copyright (C) 1999,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 175  table constant esc-sequences \ and prefi Line 175  table constant esc-sequences \ and prefi
   
 create ekey-buffer 8 chars allot  create ekey-buffer 8 chars allot
 2variable ekey-buffered  2variable ekey-buffered
   
 [IFUNDEF] #esc  27 Constant #esc  [THEN]  [IFUNDEF] #esc  27 Constant #esc  [THEN]
   
 : esc-prefix ( -- u )  : esc-prefix ( -- u )
Line 332  s-k6 s" [32~" esc-sequence Line 331  s-k6 s" [32~" esc-sequence
 s-k7 s" [33~" esc-sequence  s-k7 s" [33~" esc-sequence
 s-k8 s" [34~" esc-sequence  s-k8 s" [34~" esc-sequence
   
   \ esc sequences for MacOS X iterm <e7a7c785-3bea-408b-94e9-4b59b008546f@x16g2000prn.googlegroups.com>
   k-left   s" OD" esc-sequence
   k-right  s" OC" esc-sequence
   k-up     s" OA" esc-sequence
   k-down   s" OB" esc-sequence
   
 set-current  set-current
 [ENDIF]  [ENDIF]
   
 : clear-ekey-buffer ( -- )  : clear-ekey-buffer ( -- )
     ekey-buffer 0 ekey-buffered 2! ;      ekey-buffer 0 ekey-buffered 2! ;
   
   [IFDEF] max-single-byte
       : read-xkey ( key -- flag )
           clear-ekey-buffer
           ekey-buffered char-append-buffer
           ekey-buffer 1 u8addrlen 1 +do
               key? 0= ?leave
               key ekey-buffered char-append-buffer
           loop
           ekey-buffer 1 u8addrlen ekey-buffered @ = ;
       : get-xkey ( u -- xc )
           dup max-single-byte u>= if
               read-xkey if
                   ekey-buffer xc@+ nip         else
                   ekey-buffered 2@ unkeys key  then
           then ;
       : xkey? ( -- flag )
           key? dup if
               drop key read-xkey ekey-buffered 2@ unkeys
               clear-ekey-buffer  then ;
   [THEN]
   
 : ekey ( -- u ) \ facility-ext e-key  : ekey ( -- u ) \ facility-ext e-key
     \G Receive a keyboard event @var{u} (encoding implementation-defined).      \G Receive a keyboard event @var{u} (encoding implementation-defined).
     key dup #esc =      key dup #esc =
     if      if
         drop clear-ekey-buffer          drop clear-ekey-buffer
         esc-prefix          esc-prefix  exit
     then ;      then
       [IFDEF] max-single-byte
           get-xkey
       [THEN]
   ;
   
   [IFDEF] max-single-byte
 : ekey>char ( u -- u false | c true ) \ facility-ext e-key-to-char  : ekey>char ( u -- u false | c true ) \ facility-ext e-key-to-char
     \G Convert keyboard event @var{u} into character @code{c} if possible.      \G Convert keyboard event @var{u} into character @code{c} if possible.
       dup max-single-byte u< ; \ k-left must be first!
   : ekey>xchar ( u -- u false | xc true ) \ xchar-ext e-key-to-xchar
       \G Convert keyboard event @var{u} into xchar @code{xc} if possible.
     dup k-left u< ; \ k-left must be first!      dup k-left u< ; \ k-left must be first!
   : ekey>fkey ( u1 -- u2 f ) \ X:ekeys
   \G If u1 is a keyboard event in the special key set, convert
   \G keyboard event @var{u1} into key id @var{u2} and return true;
   \G otherwise return @var{u1} and false.
       ekey>xchar 0= ;
   
   ' xkey? alias ekey? ( -- flag ) \ facility-ext e-key-question
   [ELSE]
   : ekey>char ( u -- u false | c true ) \ facility-ext e-key-to-char
       \G Convert keyboard event @var{u} into character @code{c} if possible.
       dup k-left u< ; \ k-left must be first!
 : ekey>fkey ( u1 -- u2 f ) \ X:ekeys  : ekey>fkey ( u1 -- u2 f ) \ X:ekeys
 \G If u1 is a keyboard event in the special key set, convert  \G If u1 is a keyboard event in the special key set, convert
 \G keyboard event @var{u1} into key id @var{u2} and return true;  \G keyboard event @var{u1} into key id @var{u2} and return true;
Line 357  set-current Line 401  set-current
     ekey>char 0= ;      ekey>char 0= ;
   
 ' key? alias ekey? ( -- flag ) \ facility-ext e-key-question  ' key? alias ekey? ( -- flag ) \ facility-ext e-key-question
   [THEN]
   
 \G True if a keyboard event is available.  \G True if a keyboard event is available.
   
 \  : esc? ( -- flag ) recursive  \  : esc? ( -- flag ) recursive

Removed from v.1.21  
changed lines
  Added in v.1.26


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>