Class TermIO

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class TermIO

Public Methods
TermIO(keybuffering, keyecho, color)
void start(keybuffering, keyecho, color)
void stop()
int getkey(wait)
bool putchar(c, refresh)
bool puts(text)
void inschar(c)
void delchar()
inline int getrow()
inline int getcolumn()
void setScreenSize(newrows, newcolumns, scrolling)
inline int getrows() const
inline int getcolumns() const
inline int getmaxrows() const
inline int getmaxcolumns() const
bool setrow(row)
bool setcolumn(column)
bool setrc(row, column)
void clear()
void clearToEndOfLine()
void clearToEndOfScreen()
vector getScreenText()
unsigned char getScreenChar(row, column)
unsigned char setScreenChar(row, column, c)
void reverse(on)
void bold(on)
void blink(on)
void invisible(on)
void underline(on)
void echo(on)
void beep()
void keyMode(on)
inline void lineMode(on)
void color(color)
void colorbg(color)
void screenbg(color)
inline void normal()
inline void showCursor(show)
inline void hideCursor(hide)
inline void end()
Private Properties
Private Methods
void getScreenSize()
void colorSetup()
static void resizeHandler()

#include <TermIO.h >

Public Methods

TermIO(keybuffering, keyecho, color)

bool keybuffering

true to allow user to type ahead

Default value: true

bool keyecho

true to print input letters to screen

Default value: true

bool color

true if colors will be used

Default value: true


Constructor - initialize the terminal

void start(keybuffering, keyecho, color)

bool keybuffering

true to allow user to type ahead

Default value: true

bool keyecho

true to print input letters to screen

Default value: true

bool color

true if colors will be used

Default value: true


Start terminal I/O. This is automatically called when TermIO

is instantiated. But, you can call it after stop() to restart it.

void stop()

Stop terminal I/O. This is performed by ~TermIO(), but you

can call it to exit terminal mode early.

int getkey(wait)

bool wait

true to wait for a keystroke; false to return immediately

Default value: true


Accept an keystroke from the user

Return value: the keystroke; note that keystrokes have #defines, e.g. KEY_LEFT; -1 if no keystroke

bool putchar(c, refresh)

int c

the character to output

bool refresh

(internal use) refresh TermIO properties

Default value: true


Output a character to the terminal

Return value: key ASCII value of key; 0 if no key

bool puts(text)

const string& text

the text to output


Output text to the terminal

Return value: true upon success

void inschar(c)

char c

character to insert

Default value: ' '


Insert a character at the cursor and shift the remaining text on the line to the right

void delchar()

Delete the character at the cursor and shift the remaining text on the line to the left

inline int getrow()

Get the cursor current row. Top is row 0.

Return value: cursor current row

inline int getcolumn()

Get the cursor current column. Leftmost is column 0.

Return value: cursor current column

void setScreenSize(newrows, newcolumns, scrolling)

unsigned int newrows

max # rows; or 0 for max

unsigned int newcolumns

max # columns; or 0 for max

bool scrolling

true to allow scrolling; false to prevent scrolling

Default value: true


Fix the screen size (ignore user resizes)

inline int getrows() const

Get the total number of current screen rows.

Return value: cursor current row

inline int getcolumns() const

Get the total number of current screen columns.

Return value: cursor current column

inline int getmaxrows() const

Get the maxiumu number of screen rows.

If a window resize event happens, this will change.

Return value: cursor current row

inline int getmaxcolumns() const

Get the maxiumu number of screen columns.

If a window resize event happens, this will change.

Return value: cursor current column

bool setrow(row)

int row

the new current cursor row, from 0 to rows-1.


Set the current cursor row

Return value: true if success; false if invalid row

bool setcolumn(column)

int column

the new current cursor column, from 0 to columns-1.


Set the current cursor column

Return value: true if success; false if invalid column

bool setrc(row, column)

int row

the new current cursor row, from 0 to rows-1.

int column

the new current cursor column, from 0 to columns-1.


Set the current cursor row & column

Return value: true if success; false if invalid column

void clear()

Clear the screen.

void clearToEndOfLine()

Clear to the end of the line.

void clearToEndOfScreen()

Clear to the end of the screen.

vector <string > getScreenText()

Grab the text off the screen.

Spaces to the end of a line are truncated.

Blank lines to the bottom of the screen are truncated.

Return value: A string per line of the screen

unsigned char getScreenChar(row, column)

int row

the row, from 0 to rows-1.

int column

the column, from 0 to columns-1.


Grab a character off the screen at a specific location.

The cursor is not moved.

Return value: character found at provided row, column; 0 if invalid location

unsigned char setScreenChar(row, column, c)

int row

the row, from 0 to rows-1.

int column

the column, from 0 to columns-1.

unsigned char c

the character to display at the location


Grab a character off the screen at a specific location.

The cursor is not moved.

Return value: character found at provided row, column; 0 if invalid location

void reverse(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set reverse character display mode

void bold(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set bold character display mode

bool on

true to turn mode on; false to turn mode off

Default value: true


Set blink character display mode

void invisible(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set invisible character display mode

void underline(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set underline character display mode

void echo(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set keystroke echo mode

void beep()

Make an audible beep sound.

void keyMode(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set keystroke (not line) input mode. No key buffering

inline void lineMode(on)

bool on

true to turn mode on; false to turn mode off

Default value: true


Set line (not keystroke) input mode. Key buffering

void color(color)

int color

character color; -1 = default

Default value: -1


Set character color of the next character to print.

Valid colors: COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE

void colorbg(color)

int color

character color; -1 = default

Default value: -1


Set background of character color of the next character to print.

Valid colors: COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE

void screenbg(color)

int color

character color; -1 = default

Default value: -1


Set background color of the screen.

Valid colors: COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE

inline void normal()

Clear all character display modes

inline void showCursor(show)

bool show

true to show the cursor (default)

Default value: true


Show the cursor.

inline void hideCursor(hide)

bool hide

true to hide the cursor (default)

Default value: true


Hide the cursor.

inline void end()

End curses control of tty

Private Properties

int row

cursor location

int column

cursor location

int rows

current # rows, columns of screen

int columns

current # rows, columns of screen

int maxrows

max # rows, columns of screen

int maxcolumns

max # rows, columns of screen

bool resizeOK

Flag: it's OK for user to resize

long attribute

currently active screen attributes

int colorForeground

Current foreground color

int colorBackground

Current background color

int colorpair

currently after color fg/bg NCurses pair

bool echoKeys

Flag: user-typed key echo is on

bool bufKeys

Flag: user-typed keys buffered (line mode)

bool scrollable

Flag: screen is scrollable

static TermIO* primaryTerminal

Handles stdscr and resize


Private Methods

void getScreenSize()

Query the rows & columns of terminal

void colorSetup()

Setup colors for color screen

static void resizeHandler()

Handle a xterm window resize