;
; A DEMO to show all of the practical UNIX/Linux Terminal style useful escape sequences.
; Any colours in the code use the current Workbench colours.
; This will use variables as well as direct numbers for aiding in understanding.
; Original copyright, (C)2013, B.Walker, G0LCU.
;
; This is now issued as Public Domain, CC0, licence and you may do with it as you please.
; 
; Uploader is Lincolnshire AMIGA Group.
;
; http://lincsamiga.org.uk/wordpress/
;
; Important note:- The 'ECHO "*ec"' not ONLY clears the screen but is a terminal
; RESET also. So any text modes set will be lost - be well aware!
;
; If RexxMast is not running remove the semi-colon fron the line below.
;SYS:System/RexxMast
;
; Firstly set up a variable for the AMIGAs escape sequence.
SET esc="*e"
SET mystring=" Printing and plotting DEMO. "
; 'blankline' for this DEMO is 77 spaces for the standard default OS3.x CLI width.
SET blankline="                                                                             "
SET mode="m"
SET vidmode=4
SET fg=31
SET bg=40
SET vert=1
SET horiz=1
SET force="f"
SET vidreset="0m"
;
ECHO "*nImportant note:- The 'ECHO *"**ec*"' not ONLY clears the screen but is a"
ECHO "terminal RESET also. So any text modes set will be lost - be well aware!"
ECHO "*nFirstly a simple hard coded ANSI escape sequence for clearing the screen."
ECHO "(This is the equivalent of the bash 'echo -n -e *"\x1B[2J\x1B[H*"' version.)"
ECHO ""
ASK "Press <CR> to continue:-"
; This clear screen does NOT use the 'ECHO "*ec"' version...
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nNow the text modes and then foreground and background colours DEMO..."
ECHO "*nA) Text modes available for the AMIGA OS3.x, (mode):-"
ECHO "   0=Return/reset to the default CLI mode."
ECHO "   1=Bold text."
ECHO "   3=Italic text."
ECHO "   4=Normal underlined text."
ECHO "   7=Inverse normal text."
ECHO "   8=Invisible text mode."
ECHO "*nAn example hard coded to text mode 4..."
ECHO "$esc[4;31;40m$mystring$esc[0m"
ECHO "*nAn example using the same values as variables..."
ECHO "$esc[$vidmode;$fg;$bg$mode$mystring$esc[$vidreset"
ECHO ""
ASK "Press <CR> to continue:-"
;
SET vidmode=1
SET fg=32
SET bg=43
;
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nB) Foreground colour modes available, 30 to 37."
ECHO "   Background colour modes available, 40 to 47."
ECHO "*nAn example hard coded to text mode 1, BOLD, foreground 32 and background 43."
ECHO "$esc[1;32;43m$mystring$esc[0m"
ECHO "*nAn example using the same values as variables..."
ECHO "$esc[$vidmode;$fg;$bg$mode$mystring$esc[$vidreset"
ECHO ""
ASK "Press <CR> to continue:-"
;
SET vidmode=3
SET fg=33
SET bg=42
SET vert=12
SET horiz=25
;
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nC) Cursor manipulation inside the terminal window."
ECHO "   Useful vertical values from 0 to 255."
ECHO "   Useful horizontal values from 0 to 255."
ECHO "*nAn example hard coded to vertical position 12, horizontal position 25,"
ECHO "mode 3, foreground colour 33 and background colour 42..."
ECHO "$esc[3;33;42m$esc[12;25f$mystring$esc[0m"
ECHO ""
ASK "Press <CR> to continue:-"
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nNow the same example using the same values as variables..."
ECHO "$esc[$vidmode;$fg;$bg$mode$esc[$vert;$horiz$force$mystring$esc[$vidreset"
ECHO ""
ASK "Press <CR> to continue:-"
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nGenerate keyboard input by creating a simple ARexx script."
ECHO "The keyboard input is stored in 'ENV:buffer' and accessed as '*$buffer'."
ECHO "The AMIGAs correct escape character is '**e', so this is how to input it."
ECHO "*nNOTE:- <CR> is the RETURN/ENTER key. Input the data, then press <CR>..."
ECHO "Before pressing <CR> however, try and work out what will happen..."
ECHO "*nEnter some escape codes:- **e[3;33;42m**e[1;33f Some text. **e[0m<CR>"
ECHO ""
; Generate a keyboard input function first using ARexx...
ECHO NOLINE > T:Input.rexx
ECHO "/** $VER: Input.rexx_Version_0.00.10_(C)2013_B.Walker_G0LCU. **/" >> T:Input.rexx
ECHO "/** Usage: SYS:Rexxc/RX C:Input.rexx<CR> **/" >> T:Input.rexx
ECHO "PARSE PULL input" >> T:Input.rexx
ECHO "OPEN('kb', 'ENV:buffer', 'W')" >> T:Input.rexx
ECHO "WRITECH('kb', input)" >> T:Input.rexx
ECHO "CLOSE('kb')" >> T:Input.rexx
ECHO NOLINE "Enter some escape codes:- "
; Now run the new keyboard function...
SYS:Rexxc/RX T:Input.rexx
ECHO "$buffer*n*n*n*n*n*n*n*n*n*n*n"
ASK "Press <CR> to continue:-"
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nCreating a pseudo-background and then printing text of different colours."
ECHO "*n$esc[42m$blankline$esc[0m"
ECHO "$esc[42m$blankline$esc[0m"
ECHO "$esc[42m$blankline$esc[0m"
ECHO NOLINE "$esc[5;32f$esc[30;42mH$esc[31;42me$esc[33;42ml$esc[34;42ml$esc[35;42mo "
ECHO "$esc[36;42mW$esc[37;42mo$esc[31;42mr$esc[30;42ml$esc[31;42md$esc[33;42m!"
ECHO "$esc[0m*n"
ASK "Press <CR> to continue:-"
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nA pseudo-3D box and button with writing inside them..."
ECHO "$esc[0m$esc[5;25f+-------------------------$esc[0;32;40m+"
ECHO "$esc[0m$esc[6;25f|$esc[0;33;40m(C)2013, B.Walker, G0LCU.$esc[0;32;40m|"
ECHO "$esc[0m$esc[7;25f+$esc[0;32;40m-------------------------+$esc[0m"
ECHO "$esc[0;32;40m$esc[9;25f+-------------------------$esc[0m+"
ECHO "$esc[0;32;40m$esc[10;25f|$esc[0;33;40m Issued as Public Domain.$esc[0m|"
ECHO "$esc[0;32;40m$esc[11;25f+$esc[0m-------------------------+"
ECHO "*nA comprehensive list of ANSI escape codes here:-*n"
ECHO "          http://ascii-table.com/ansi-escape-sequences-vt-100.php*n"
ECHO "Some more will work but many will not.*n"
ECHO "You now have the building blocks for AMIGA shell scripting anims and games.*n"
ASK "And finally press <CR> to continue:-"
ECHO NOLINE "$esc[2J$esc[H"
ECHO "*nAlthough not strictly escape codes the addition of a bell to finish.*n"
ECHO "This is saved as the variable 'ENV:bell' and is accessed as 'ECHO *"*$bell*"'."
EVAL 7 LFORMAT %C > ENV:bell
ECHO "$bell"
ECHO "Enjoy finding simple solutions to often very difficult problems...*n"
;
;UNSET buffer
;UNSET bell
UNSET esc
UNSET mystring
UNSET blankline
UNSET mode
UNSET vidmode
UNSET fg
UNSET bg
UNSET vert
UNSET horiz
UNSET force
UNSET vidreset
;