Annotation of gforth/ansi.fs, revision 1.6

1.6     ! crook       1: \ ansi.fs      Define terminal attributes              20may93jaw
1.1       pazsan      2: 
1.4       anton       3: \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
1.2       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 2
                     10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
                     18: \ along with this program; if not, write to the Free Software
1.5       anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.2       anton      20: 
                     21: 
1.6     ! crook      22: \ If you want another terminal you can redefine the colours.
1.1       pazsan     23: 
                     24: \ But a better way is it only to redefine SET-ATTR
                     25: \ to have compatible colours.
                     26: 
                     27: \ Attributes description:
1.6     ! crook      28: \ <A ( -- -1 0 )           Start attributes description
        !            29: \ A> ( -1 x .. x -- attr ) Terminate an attributes description and
        !            30: \                          return overall attribute; currently only
        !            31: \                          12 bits are used.
        !            32: \
        !            33: \ >BG ( colour -- x )      x is attribute with colour as Background colour
        !            34: \ >FG ( colour -- x )      x is attribute with colour as Foreground colour
        !            35: \
        !            36: \ SET-ATTR ( attr -- )     Send attributes to terminal
        !            37: \
        !            38: \ BG> ( attr -- colour)    extract colour of Background from attr
        !            39: \ FG> ( attr -- colour)    extract colour of Foreground from attr
        !            40: \
        !            41: \ See colorize.fs for an example of usage.
1.1       pazsan     42: 
1.6     ! crook      43: \ To do:        Make <A A> State smart and only compile literals!
1.1       pazsan     44: 
1.3       anton      45: needs vt100.fs
1.1       pazsan     46: 
                     47: decimal
                     48: 
                     49: 0 CONSTANT Black
                     50: 1 CONSTANT Red
                     51: 2 CONSTANT Green
                     52: 3 CONSTANT Yellow
                     53: 4 CONSTANT Blue
                     54: 5 CONSTANT Brown
                     55: 6 CONSTANT Cyan
                     56: 7 CONSTANT White
                     57: 
                     58: 1 CONSTANT Bold
                     59: 2 CONSTANT Underline
                     60: 4 CONSTANT Blink
                     61: 8 CONSTANT Invers
                     62: 
                     63: \ For portable programs don't use invers and underline
                     64: 
1.6     ! crook      65: : >BG    4 lshift ;
        !            66: : >FG    >BG >BG ;
1.1       pazsan     67: 
1.6     ! crook      68: : BG>    4 rshift 15 and ;
        !            69: : FG>    8 rshift 15 and ;
1.1       pazsan     70: 
                     71: : <A    -1 0 ;
                     72: : A>    BEGIN over -1 <> WHILE or REPEAT nip ;
                     73: 
                     74: VARIABLE Attr   -1 Attr !
                     75: 
                     76: DEFER Attr!
                     77: 
                     78: : (Attr!)       ( attr -- ) dup Attr @ = IF drop EXIT THEN
                     79:                 dup Attr !
                     80:                 ESC[    0 pn
1.6     ! crook      81:                         dup FG> ?dup IF 30 + ;pn THEN
        !            82:                         dup BG> ?dup IF 40 + ;pn THEN
1.1       pazsan     83:                         dup Bold and IF 1 ;pn THEN
                     84:                         dup Underline and IF 4 ;pn THEN
                     85:                         dup Blink and IF 5 ;pn THEN
                     86:                         Invers and IF 7 ;pn THEN
                     87:                         [char] m emit ;
                     88: 
                     89: ' (Attr!) IS Attr!
                     90: 
1.6     ! crook      91: : BlackSpace    Attr @ dup BG> Black =
1.1       pazsan     92:                 IF drop space
                     93:                 ELSE 0 attr! space attr! THEN ;
                     94: 

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