xref: /illumos-gate/usr/src/boot/forth/screen.4th (revision 5e897995)
122028508SToomas Soome\ Copyright (c) 2003 Scott Long <scottl@FreeBSD.org>
222028508SToomas Soome\ Copyright (c) 2015 Devin Teske <dteske@FreeBSD.org>
322028508SToomas Soome\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
422028508SToomas Soome\ All rights reserved.
522028508SToomas Soome\
622028508SToomas Soome\ Redistribution and use in source and binary forms, with or without
722028508SToomas Soome\ modification, are permitted provided that the following conditions
822028508SToomas Soome\ are met:
922028508SToomas Soome\ 1. Redistributions of source code must retain the above copyright
1022028508SToomas Soome\    notice, this list of conditions and the following disclaimer.
1122028508SToomas Soome\ 2. Redistributions in binary form must reproduce the above copyright
1222028508SToomas Soome\    notice, this list of conditions and the following disclaimer in the
1322028508SToomas Soome\    documentation and/or other materials provided with the distribution.
1422028508SToomas Soome\
1522028508SToomas Soome\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1622028508SToomas Soome\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1722028508SToomas Soome\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1822028508SToomas Soome\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1922028508SToomas Soome\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2022028508SToomas Soome\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2122028508SToomas Soome\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2222028508SToomas Soome\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2322028508SToomas Soome\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2422028508SToomas Soome\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2522028508SToomas Soome\ SUCH DAMAGE.
2622028508SToomas Soome
2722028508SToomas Soomemarker task-screen.4th
2822028508SToomas Soome
2922028508SToomas Soome\ emit Esc-[
3022028508SToomas Soome: escc ( -- ) 27 emit [char] [ emit ;
3122028508SToomas Soome
3222028508SToomas Soome\ Home cursor ( Esc-[H )
3322028508SToomas Soome: ho ( -- ) escc [char] H emit ;
3422028508SToomas Soome
3522028508SToomas Soome\ Clear from current position to end of display ( Esc-[J )
3622028508SToomas Soome: cld ( -- ) escc [char] J emit ;
3722028508SToomas Soome
3822028508SToomas Soome\ clear screen
3922028508SToomas Soome: clear ( -- ) ho cld ;
4022028508SToomas Soome
4122028508SToomas Soome\ move cursor to x rows, y cols (1-based coords) ( Esc-[%d;%dH )
4222028508SToomas Soome: at-xy ( x y -- ) escc .# [char] ; emit .# [char] H emit ;
4322028508SToomas Soome
4422028508SToomas Soome\ Set foreground color ( Esc-[3%dm )
4522028508SToomas Soome: fg ( x -- ) escc 3 .# .# [char] m emit ;
4622028508SToomas Soome
4722028508SToomas Soome\ Set background color ( Esc-[4%dm )
4822028508SToomas Soome: bg ( x -- ) escc 4 .# .# [char] m emit ;
4922028508SToomas Soome
5022028508SToomas Soome\ Mode end (clear attributes)
5122028508SToomas Soome: me ( -- ) escc [char] m emit ;
5222028508SToomas Soome
5322028508SToomas Soome\ Enable bold mode ( Esc-[1m )
5422028508SToomas Soome: b ( -- ) escc 1 .# [char] m emit ;
5522028508SToomas Soome
5622028508SToomas Soome\ Disable bold mode ( Esc-[22m )
5722028508SToomas Soome: -b ( -- ) escc 22 .# [char] m emit ;
5822028508SToomas Soome
5922028508SToomas Soome\ Enable inverse foreground/background mode ( Esc-[7m )
6022028508SToomas Soome: inv ( -- ) escc 7 .# [char] m emit ;
6122028508SToomas Soome
6222028508SToomas Soome\ Disable inverse foreground/background mode ( Esc-[27m )
6322028508SToomas Soome: -inv ( -- ) escc 27 .# [char] m emit ;
6422028508SToomas Soome
6522028508SToomas Soome\ Convert all occurrences of given character (c) in string (c-addr/u) to Esc
6622028508SToomas Soome: escc! ( c-addr/u c -- c-addr/u )
6722028508SToomas Soome	2 pick 2 pick
6822028508SToomas Soome	begin dup 0> while
6922028508SToomas Soome		over c@ 3 pick = if over 27 swap c! then
7022028508SToomas Soome		1- swap 1+ swap
7122028508SToomas Soome	repeat
7222028508SToomas Soome	2drop drop
7322028508SToomas Soome;
7422028508SToomas Soome
7522028508SToomas Soome\ Get the number of screen rows/columns
7622028508SToomas Soome: sr ( -- y ) 25 s" screen-#rows" getenvn ;
7722028508SToomas Soome: sc ( -- x ) 80 s" screen-#cols" getenvn ;
7822028508SToomas Soome
7922028508SToomas Soome\ Place the cursor at the bottom left of the screen
8022028508SToomas Soome: at-bl 0 sr at-xy ;
8122028508SToomas Soome
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