Text-based as a GUI

Alon Altman

Haifux Lightning talk

The problem

Want to play a card game on a flight...

Without the cards...

But with a laptop...

Without any knowledge of GUI programming...

and without any docs...

or an Internet connection...

(not even for-pay)

Impossible?

User Interface Options

Command line

Not applicable for a game

Tk/GTK/Qt/Xaw/Xlib GUI

Flight is short – Too much work for a small game

Need to provide images for cards!

curses/ncurses

Need to learn a new library, but docs not available!

Web based

Could have been nice if we had a network.

Need client-side programming to use “buzzers”.

The Solution: Text – Based!

Simple STDIN/STDOUT interface

No libraries needed

No need for X

Can implement many GUI features

Colors and bold via ANSI escapes.

Clear screen too!

ASCII symbols instead of images!

Keyboard handling via stty!

Sharable with screen for network play!

ANSI Escapes

Still valid from the DOS days...

Clear Screen: ESC[2J

Foreground Color: ESC[3xm

Background Color: ESC[4xm

Reverse Video: ESC[7m

To cancel all effects, use ESC[m

To produce ESC in your own code,
use \033 (octal for 27).

ASCII Symbols

~$$$~

(@@)

ASCII Symbols (cont.)

Quattro Board Game

Not the same, but good enough!

Keyboard handling with stty

(or: How to I capture a single key press)

stty - change and print terminal line settings

In English: Control the behavior of STDIN.

For example:

echo – Echo keys back to terminal (default)

icanon – Allow line editing before processing.

To get a key from the terminal (pseudocode):

stty -icanon -echo # Disable echo and editing

read(STDIN,key,1); # Read key

select(NULL,NULL,NULL,0.3); # Delay

stty icanon echo # Restore terminal flags

Final Result

Set

Quattro

2005-06-20T11:36:30