xref: /illumos-gate/usr/src/boot/forth/screen.4th (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1\ Copyright (c) 2003 Scott Long <scottl@FreeBSD.org>
2\ Copyright (c) 2015 Devin Teske <dteske@FreeBSD.org>
3\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
4\ All rights reserved.
5\
6\ Redistribution and use in source and binary forms, with or without
7\ modification, are permitted provided that the following conditions
8\ are met:
9\ 1. Redistributions of source code must retain the above copyright
10\    notice, this list of conditions and the following disclaimer.
11\ 2. Redistributions in binary form must reproduce the above copyright
12\    notice, this list of conditions and the following disclaimer in the
13\    documentation and/or other materials provided with the distribution.
14\
15\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25\ SUCH DAMAGE.
26
27marker task-screen.4th
28
29\ emit Esc-[
30: escc ( -- ) 27 emit [char] [ emit ;
31
32\ Home cursor ( Esc-[H )
33: ho ( -- ) escc [char] H emit ;
34
35\ Clear from current position to end of display ( Esc-[J )
36: cld ( -- ) escc [char] J emit ;
37
38\ clear screen
39: clear ( -- ) ho cld ;
40
41\ move cursor to x rows, y cols (1-based coords) ( Esc-[%d;%dH )
42: at-xy ( x y -- ) escc .# [char] ; emit .# [char] H emit ;
43
44\ Set foreground color ( Esc-[3%dm )
45: fg ( x -- ) escc 3 .# .# [char] m emit ;
46
47\ Set background color ( Esc-[4%dm )
48: bg ( x -- ) escc 4 .# .# [char] m emit ;
49
50\ Mode end (clear attributes)
51: me ( -- ) escc [char] m emit ;
52
53\ Enable bold mode ( Esc-[1m )
54: b ( -- ) escc 1 .# [char] m emit ;
55
56\ Disable bold mode ( Esc-[22m )
57: -b ( -- ) escc 22 .# [char] m emit ;
58
59\ Enable inverse foreground/background mode ( Esc-[7m )
60: inv ( -- ) escc 7 .# [char] m emit ;
61
62\ Disable inverse foreground/background mode ( Esc-[27m )
63: -inv ( -- ) escc 27 .# [char] m emit ;
64
65\ Convert all occurrences of given character (c) in string (c-addr/u) to Esc
66: escc! ( c-addr/u c -- c-addr/u )
67	2 pick 2 pick
68	begin dup 0> while
69		over c@ 3 pick = if over 27 swap c! then
70		1- swap 1+ swap
71	repeat
72	2drop drop
73;
74
75\ Get the number of screen rows/columns
76: sr ( -- y ) 25 s" screen-#rows" getenvn ;
77: sc ( -- x ) 80 s" screen-#cols" getenvn ;
78
79\ Place the cursor at the bottom left of the screen
80: at-bl 0 sr at-xy ;
81
82\ set cursor invisible or normal (civis/cnorm)
83: cursor-invisible ( -- ) [char] l ;
84: cursor-normal ( -- ) [char] h ;
85: cursor-set ( cursor-mode -- ) escc [char] ? emit 25 .# emit ;
86