Some useful posters from Berkeley
CS Illustrated
Mildly entertaining extras
Just since playing with ascii terminals isn't all that exciting,
here are some functions that let you
- get keyboard input without making the user hit enter
- change the colour of text and background on the terminal window
- figure out how big the terminal window currently is
- jump the cursor to a specific point in the window
- pause the program for a fixed number of seconds
- clear the screen
The code is provided through a header file, effects.h
To include the set of functions
in a program, just make sure you copy the effects.h file to the
same directory as the rest of your code, and #include "effects.h"
in your .C file.
The actual functions are:
- bool keyQuick(char &c);
Returns true if the user has pressed a key
(false otherwise) and returns the key in parameter c
- void sysPause(float t);
Pauses the system for t seconds, where t can be between 0.05 and 1800
- void getTermSize(long &h, long &w);
Gets the height and width of the terminal window
(e.g. 24 characters high by 80 characters wide)
- void moveCursor(long row, long col);
Moves the cursor to a specific row and column (1,1 is top left)
- void clear();
Clears the screen and moves the cursor to the top left
- void chgText(Colour c);
void chgBack(Colour c);
Change the colour of the text or the background
where the colours can be any of
Black, Red, Green, Yellow, Blue, Purple, Pale, Grey
or DefCol to restore all defaults
- void chgFormat(FormType t);
Changes the display format (highlighting and other effects).
The specified format can be any of the following:
Clear, Bold, Underline, Faint, Negative, Normal, Alt,
or DefForm to restore all defaults.
(Normal and Alt toggle between the two terminal character fonts.)