xref: /illumos-gate/usr/src/boot/forth/screen.4th (revision 5e897995)
1199767f8SToomas Soome\ Copyright (c) 2003 Scott Long <scottl@FreeBSD.org>
2199767f8SToomas Soome\ Copyright (c) 2015 Devin Teske <dteske@FreeBSD.org>
31ea94c75SAndy Fiddaman\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
4199767f8SToomas Soome\ All rights reserved.
51ea94c75SAndy Fiddaman\
6199767f8SToomas Soome\ Redistribution and use in source and binary forms, with or without
7199767f8SToomas Soome\ modification, are permitted provided that the following conditions
8199767f8SToomas Soome\ are met:
9199767f8SToomas Soome\ 1. Redistributions of source code must retain the above copyright
10199767f8SToomas Soome\    notice, this list of conditions and the following disclaimer.
11199767f8SToomas Soome\ 2. Redistributions in binary form must reproduce the above copyright
12199767f8SToomas Soome\    notice, this list of conditions and the following disclaimer in the
13199767f8SToomas Soome\    documentation and/or other materials provided with the distribution.
141ea94c75SAndy Fiddaman\
15199767f8SToomas Soome\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16199767f8SToomas Soome\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17199767f8SToomas Soome\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18199767f8SToomas Soome\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19199767f8SToomas Soome\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20199767f8SToomas Soome\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21199767f8SToomas Soome\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22199767f8SToomas Soome\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23199767f8SToomas Soome\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24199767f8SToomas Soome\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25199767f8SToomas Soome\ SUCH DAMAGE.
26199767f8SToomas Soome
27199767f8SToomas Soomemarker task-screen.4th
28199767f8SToomas Soome
29199767f8SToomas Soome\ emit Esc-[
30199767f8SToomas Soome: escc ( -- ) 27 emit [char] [ emit ;
31199767f8SToomas Soome
32199767f8SToomas Soome\ Home cursor ( Esc-[H )
33199767f8SToomas Soome: ho ( -- ) escc [char] H emit ;
34199767f8SToomas Soome
35199767f8SToomas Soome\ Clear from current position to end of display ( Esc-[J )
36199767f8SToomas Soome: cld ( -- ) escc [char] J emit ;
37199767f8SToomas Soome
38199767f8SToomas Soome\ clear screen
39199767f8SToomas Soome: clear ( -- ) ho cld ;
40199767f8SToomas Soome
41199767f8SToomas Soome\ move cursor to x rows, y cols (1-based coords) ( Esc-[%d;%dH )
42199767f8SToomas Soome: at-xy ( x y -- ) escc .# [char] ; emit .# [char] H emit ;
43199767f8SToomas Soome
44199767f8SToomas Soome\ Set foreground color ( Esc-[3%dm )
45199767f8SToomas Soome: fg ( x -- ) escc 3 .# .# [char] m emit ;
46199767f8SToomas Soome
47199767f8SToomas Soome\ Set background color ( Esc-[4%dm )
48199767f8SToomas Soome: bg ( x -- ) escc 4 .# .# [char] m emit ;
49199767f8SToomas Soome
50199767f8SToomas Soome\ Mode end (clear attributes)
51199767f8SToomas Soome: me ( -- ) escc [char] m emit ;
52199767f8SToomas Soome
53199767f8SToomas Soome\ Enable bold mode ( Esc-[1m )
54199767f8SToomas Soome: b ( -- ) escc 1 .# [char] m emit ;
55199767f8SToomas Soome
56199767f8SToomas Soome\ Disable bold mode ( Esc-[22m )
57199767f8SToomas Soome: -b ( -- ) escc 22 .# [char] m emit ;
58199767f8SToomas Soome
59199767f8SToomas Soome\ Enable inverse foreground/background mode ( Esc-[7m )
60199767f8SToomas Soome: inv ( -- ) escc 7 .# [char] m emit ;
61199767f8SToomas Soome
62199767f8SToomas Soome\ Disable inverse foreground/background mode ( Esc-[27m )
63199767f8SToomas Soome: -inv ( -- ) escc 27 .# [char] m emit ;
64199767f8SToomas Soome
65199767f8SToomas Soome\ Convert all occurrences of given character (c) in string (c-addr/u) to Esc
66199767f8SToomas Soome: escc! ( c-addr/u c -- c-addr/u )
67199767f8SToomas Soome	2 pick 2 pick
68199767f8SToomas Soome	begin dup 0> while
69199767f8SToomas Soome		over c@ 3 pick = if over 27 swap c! then
70199767f8SToomas Soome		1- swap 1+ swap
71199767f8SToomas Soome	repeat
72199767f8SToomas Soome	2drop drop
73199767f8SToomas Soome;
741ea94c75SAndy Fiddaman
751ea94c75SAndy Fiddaman\ Get the number of screen rows/columns
761ea94c75SAndy Fiddaman: sr ( -- y ) 25 s" screen-#rows" getenvn ;
771ea94c75SAndy Fiddaman: sc ( -- x ) 80 s" screen-#cols" getenvn ;
781ea94c75SAndy Fiddaman
791ea94c75SAndy Fiddaman\ Place the cursor at the bottom left of the screen
801ea94c75SAndy Fiddaman: at-bl 0 sr at-xy ;
811ea94c75SAndy Fiddaman
82*5e897995SToomas Soome\ set cursor invisible or normal (civis/cnorm)
83*5e897995SToomas Soome: cursor-invisible ( -- ) [char] l ;
84*5e897995SToomas Soome: cursor-normal ( -- ) [char] h ;
85*5e897995SToomas Soome: cursor-set ( cursor-mode -- ) escc [char] ? emit 25 .# emit ;
86