Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \ TERMINAL CONTROL
- \ Standard ASCII Codes (not comprehensive)
- \ Emits a bell
- : t-bel 7 emit ;
- \ Emits a backspace
- : t-bs 8 emit ;
- \ Emits a tab
- : t-tab 9 emit ;
- \ Emits a line feed
- : t-lf 10 emit ;
- \ Emits a vertical tab
- : t-tab-v 11 emit ;
- \ Emits a form feed
- : t-ff 12 emit ;
- \ Emits a carriage return
- : t-cr 13 emit ;
- \ Emits an escape
- : t-esc 27 emit ;
- \ Emits a delete
- : t-del 127 emit ;
- \ Control Sequence Introducer (CSI) commands (not comprehensive)
- \ Emit CSI
- : t-csi ( -- ) t-esc '[' emit ;
- \ Returns cursor to top left
- : t-home ( -- ) t-csi 'H' emit ;
- \ Places cursor at the requested column and row
- : t-at ( col row -- ) t-csi .nb ';' emit .nb 'H' emit ;
- \ Erase from cursor until end of screen
- : t-cleol ( -- ) t-csi ." J" ;
- \ Clear the entire screen and move cursor to top left
- : t-cls ( -- ) t-csi ." 2J" t-home ;
- \ Sets cursor to default foreground
- : t-default t-csi ." 0;0m" ;
- \ Sets foreground color to red
- : t-red t-csi ." 0;31m" ;
- \ Sets foreground color to green
- : t-green t-csi ." 0;32m" ;
- \ Sets foreground color to yellow
- : t-yellow t-csi ." 0;33m" ;
- \ Sets foreground color to blue
- : t-blue t-csi ." 0;34m" ;
- \ Sets foreground color to magenta
- : t-magenta t-csi ." 0;35m" ;
- \ Sets foreground color to cyan
- : t-cyan t-csi ." 0;36m" ;
- \ Sets foreground color to white
- : t-white t-csi ." 0;37m" ;
- \ Set custom foreground
- : t-rgb-fg ( r g b -- ) t-csi ." 38;2;" rot .nb ';' emit swap .nb ';' emit .nb 'm' emit ;
- \ Set custom background
- : t-rgb-bg ( r g b -- ) t-csi ." 48;2;" rot .nb ';' emit swap .nb ';' emit .nb 'm' emit ;
- \ Provides the terminal width
- : t-width ( -- cols ) cols ;
- \ Provides the terminal height
- : t-height ( -- rows ) rows ;
- \ Save the terminal position
- : t-save ( -- ) t-csi ." s" ;
- \ Returns position to previously saved
- : t-restore ( -- ) t-csi ." u" ;
- \ GENERAL PURPOSE WORDS
- \ Negative pi for convencience
- : -pi ( -- F: -pi ) pi fnegate ;
- \ Order the top 2 ints on the stack such that the lowest value is tos
- : max-min ( a b -- max min ) 2dup > if swap endif ;
- \ Duplicate the top two floats on the float stack
- : f2dup ( F: a F: b -- F: a F: b F: a F: b ) fover fover ;
- \ Order the top 2 floats on the stack such that the lowest value is tos
- : fmax-min ( F: a F: b -- F: max-ab F: min-ab ) f2dup f> if fswap endif ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement