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,
and the associated C++ file effects.C
To include them in a program, just make sure you #include "effects.h",
and compile effects.C together with your program's other .C file(s).
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.)