/* Links to VT100 emulation specs: http://en.wikipedia.org/wiki/ANSI_escape_code http://www.xfree86.org/current/ctlseqs.html http://vt100.net/docs/vt220-rm/chapter4.html */ // Enable system() using startup option '--caution-to-the-wind'. //Std.system("stty -echo"); //Std.system("stty echo"); // Class for VT100 terminal commands. class VT100 { // In order to avoid the type being written, these commands write an initial empty // string, which then causes a space being written. The cursor is then moved back by the // following backspace \b. When better writing commands are available, this can be changed. fun static void clear() { <<< "", "\b\033[2J" >>>; } // Clear screen. fun static void cleartop() { <<< "", "\b\033[2J\033[1;1H" >>>; } // Also set cursor top. fun static void hide_cursor() { <<< "", "\b\033[?25l" >>>; } fun static void show_cursor() { <<< "", "\b\033[?25h" >>>; } fun static void lock_off() { <<< "", "\b\033[2l" >>>; } // Keyboard lock off. fun static void lock_on() { <<< "", "\b\033[2h" >>>; } // Keyboard lock on. fun static void echo_off() { <<< "", "\b\033[12h" >>>; } // Echo off. fun static void echo_on() { <<< "", "\b033[12l" >>>; } // Echo on. fun static void insert() { <<< "", "\b\033[4h" >>>; } // Insert mode: move cursor after write. fun static void replace() { <<< "", "\b\033[4l" >>>; } // Replace mode: keep cursor position after write. // Write string s at (x, y) in default color; (1, 1) is top left. fun static void write(int x, int y, string s) { <<< "", "\b\033[" + Std.itoa(y) + ";" + Std.itoa(x) + "H" + s >>>; } /* Write string s at (x, y), where (1, 1) is top left, in foreground color f with brightness fb and background color b with brightness bb. The brightness number is 0 fro normal, and 1 for bright. The color numbers are as follows: 0 black 1 red 2 green 3 yellow 4 blue 5 magenta 6 cyan 7 white 9 default (original) */ fun static void write(int x, int y, int f, int fb, int b, int bb, string s) { 30 + f + 60*fb => int f0; 40 + b + 60*bb => int b0; // The initial empty string is needed so that the program does not write out the // type; then, the backspace \b takes away the space that Chuck writes. <<< "", "\b\033[" + Std.itoa(y) + ";" + Std.itoa(x) + "H\033[" + Std.itoa(f0) + "m\033[" + Std.itoa(b0) + "m" + s + "\033[39m\033[49m" >>>; } // Write string s at (x, y), where (1, 1) is top left, in foreground color f and bacground color // with normal brightness; color numbers as above. fun static void write(int x, int y, int f, int b, string s) { 30 + f => int f0; 40 + b => int b0; <<< "", "\b\033[" + Std.itoa(y) + ";" + Std.itoa(x) + "H\033[" + Std.itoa(f0) + "m\033[" + Std.itoa(b0) + "m" + s + "\033[39m\033[49m" >>>; } // Write string s at (x, y), where (1, 1) is top left, in foreground color f with normal // brightness; color numbers as above. fun static void write(int x, int y, int f, string s) { 30 + f => int f0; <<< "", "\b\033[" + Std.itoa(y) + ";" + Std.itoa(x) + "H\033[" + Std.itoa(f0) + "m" + s >>>; } } VT100.clear(); VT100.show_cursor(); while(true) { Std.rand2(1, 60) => int x; Std.rand2(1, 10) => int y; Std.rand2(0, 7) => int f; Std.rand2(0, 1) => int fb; Std.rand2(0, 7) => int b; Std.rand2(0, 1) => int bb; VT100.write(x, y, "Hello World!"); 400::ms => now; VT100.write(x, y, f, "Hello World!"); 400::ms => now; VT100.write(x, y, f, b, "Hello World!"); 400::ms => now; VT100.write(x, y, f, fb, b, bb, "Hello World!"); 400::ms => now; }