udamonic.com
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
  • Create
    • Creating PCBs >
      • Designing PCBs
      • Fabricating PCBs
      • Soldering
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • FizzBuzz
    • Adding MRAM
    • Model Train Control
    • Adding a Real Time Clock
    • Scamp Projects on Youtube
  • Resources
  • Store
  • About
  • Contact

Formatting TexT
​

The terminal application that you use to communicate with your Udamonic computer is most likely compatible with the old VT100 terminals used in days of old, and therefore will support ANSI escape codes. By printing the right combination of characters, you can change text attributes on your screen. They start with an escape character, followed by defined codes. Ever wondered why your keyboard has an ESC key? It's an historical artefact dating back to the days of serial terminals and mainframe computers. 
You can use your favourite search engine to find a complete list of ANSI escape codes.​ 

Your Udamonic computer has a few ANSI commands predefined. These are plain, bold, underline, wink (blinking text) and reverse.
Note that these words are used before​ text is printed. As an example:
: fancytext 
   ." This is " 
   bold 
   ." dramatic"  
​   plain  
   ." and " 
   underline 
   ." important" 
   plain 
   ." text. " 
; 
When fancytext is run, it will give an output of:
This is dramatic and important text.


​Colors
​

There are two words that allow you to change text colors. Eight colors are supported by ANSI terminals. Place a value on the stack representing the color, then call fg to set foreground color or bg to set the background color.

You can use fg and bg with a number, or you can define the following constants to make it easier to use:
​0 constant black
1 constant red
2 constant green
3 constant yellow
4 constant blue
5 constant magenta
6 constant cyan
7 constant white
As an example of how to use colors (with the defined constants):
: alert
   red bg
   white fg
   wink      \ blink the text
   cr ." Computer Malfunction!" 
   plain
​;

Moving Around the Screen
​

The word goto will position the cursor at a particular co-ordinate on the screen. The upper left of the screen is position 1,1, known as home.
For example to move the cursor to column 2, row 6:
2 6 goto
The maximum horizontal and vertical size depends on how large the terminal window is on your host computer. Resizing your window changes the number of rows and columns. There is no simple way for Forth to query the terminal app to get this size, unfortunately. Be aware that if you go outside the available space, any text you print will simply wrap back to the onscreen area.

The word hide will hide the cursor, and show will make the cursor visible again. Hiding the cursor can be useful if you're redrawing parts of the screen and don't want to see the cursor jumping around.

DEMO 
​

A quick demo:
: star
   random $ffff 8 u/ u/ fg   \ pick a random color
   42 emit                   \ print an asterisk
; 

: jump
   random $ffff 80 u/ u/     \ random x location (80 columns)
   10 ms                     \ give random a chance to reseed
   random $ffff 20 u/ u/     \ random y location (20 rows)
   goto                      \ jump there
;

: pattern
   cls                       \ clear the screen
   hide                      \ hide the cursor
   begin
      jump                   \ jump to a random location
      star                   \ print a colorful star 
      key?                   \ repeat until a key is typed
   until
   show                      \ restore the cursor
;

Site powered by Weebly. Managed by Hostwinds
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
  • Create
    • Creating PCBs >
      • Designing PCBs
      • Fabricating PCBs
      • Soldering
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • FizzBuzz
    • Adding MRAM
    • Model Train Control
    • Adding a Real Time Clock
    • Scamp Projects on Youtube
  • Resources
  • Store
  • About
  • Contact