Annotation of gforth/ansi.fs, revision 1.10
1.6 crook 1: \ ansi.fs Define terminal attributes 20may93jaw
1.1 pazsan 2:
1.10 ! anton 3: \ Copyright (C) 1995,1996,1997,1998,2001,2003,2007 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
1.9 anton 9: \ as published by the Free Software Foundation, either version 3
1.2 anton 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
1.9 anton 18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.2 anton 19:
20:
1.6 crook 21: \ If you want another terminal you can redefine the colours.
1.1 pazsan 22:
23: \ But a better way is it only to redefine SET-ATTR
24: \ to have compatible colours.
25:
26: \ Attributes description:
1.6 crook 27: \ <A ( -- -1 0 ) Start attributes description
28: \ A> ( -1 x .. x -- attr ) Terminate an attributes description and
29: \ return overall attribute; currently only
30: \ 12 bits are used.
31: \
32: \ >BG ( colour -- x ) x is attribute with colour as Background colour
33: \ >FG ( colour -- x ) x is attribute with colour as Foreground colour
34: \
35: \ SET-ATTR ( attr -- ) Send attributes to terminal
36: \
37: \ BG> ( attr -- colour) extract colour of Background from attr
38: \ FG> ( attr -- colour) extract colour of Foreground from attr
39: \
40: \ See colorize.fs for an example of usage.
1.1 pazsan 41:
1.6 crook 42: \ To do: Make <A A> State smart and only compile literals!
1.1 pazsan 43:
1.3 anton 44: needs vt100.fs
1.1 pazsan 45:
46: decimal
47:
48: 0 CONSTANT Black
49: 1 CONSTANT Red
50: 2 CONSTANT Green
51: 3 CONSTANT Yellow
52: 4 CONSTANT Blue
53: 5 CONSTANT Brown
54: 6 CONSTANT Cyan
55: 7 CONSTANT White
56:
57: 1 CONSTANT Bold
58: 2 CONSTANT Underline
59: 4 CONSTANT Blink
60: 8 CONSTANT Invers
61:
62: \ For portable programs don't use invers and underline
63:
1.6 crook 64: : >BG 4 lshift ;
65: : >FG >BG >BG ;
1.1 pazsan 66:
1.6 crook 67: : BG> 4 rshift 15 and ;
68: : FG> 8 rshift 15 and ;
1.1 pazsan 69:
70: : <A -1 0 ;
71: : A> BEGIN over -1 <> WHILE or REPEAT nip ;
72:
73: VARIABLE Attr -1 Attr !
74:
75: DEFER Attr!
76:
77: : (Attr!) ( attr -- ) dup Attr @ = IF drop EXIT THEN
78: dup Attr !
79: ESC[ 0 pn
1.6 crook 80: dup FG> ?dup IF 30 + ;pn THEN
81: dup BG> ?dup IF 40 + ;pn THEN
1.1 pazsan 82: dup Bold and IF 1 ;pn THEN
83: dup Underline and IF 4 ;pn THEN
84: dup Blink and IF 5 ;pn THEN
85: Invers and IF 7 ;pn THEN
86: [char] m emit ;
87:
88: ' (Attr!) IS Attr!
89:
1.6 crook 90: : BlackSpace Attr @ dup BG> Black =
1.1 pazsan 91: IF drop space
92: ELSE 0 attr! space attr! THEN ;
93:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>