A class implementing a VT100-compatible terminal suitable for command line interaction models. More...
#include <terminal.h>

Public Member Functions | |
| termbuffer (file &in, file &out, int _size=4096, int _wsize=0) | |
| ~termbuffer (void) | |
| void | on (void) |
| void | off (void) |
| void | setidlecb (tbidlecb mycb, void *arg) |
| void | setprompt (const string &prmpt) |
| void | insert (char c) |
| void | insert (const string &str) |
| void | backspace (void) |
| void | del (void) |
| void | eraseword (void) |
| void | crleft (void) |
| void | crright (void) |
| void | wordleft (void) |
| void | wordright (void) |
| void | crend (void) |
| void | crhome (void) |
| void | crup (void) |
| void | crdown (void) |
| void | tohistory (void) |
| int | getkey (void) |
| void | draw (void) |
| void | tprintf (const char *,...) |
| void | tprintf (const string &s) |
| void | tputs (const string &) |
| void | tputc (char) |
| void | set (const string &) |
| void | clear (void) |
| void | clearleft (void) |
| void | clearright (void) |
| string * | getline (void) |
| void | sendconsole (const string &s) |
| void | writeconsole (const string &s) |
| int | crsrpos (void) |
| int | length (void) |
| void | setcrsr (int i) |
| void | redraw (void) |
| void | savehistory (const string &to) |
| void | loadhistory (const string &from) |
Public Attributes | |
| file | fin |
| file | fout |
Protected Member Functions | |
| void | advance (void) |
| void | setpos (int, int) |
Protected Attributes | |
| unsigned int | size |
| unsigned int | wsize |
| unsigned int | len |
| unsigned int | crsr |
| unsigned int | ocrsr |
| unsigned int | wcrsr |
| unsigned int | owcrsr |
| char * | buffer |
| char * | curview |
| string | prompt |
| tbidlecb | idlecb |
| void * | idlearg |
| unsigned int | utf8expect |
| value | events |
| lock< int > | eventlock |
| value | history |
| int | historycrsr |
| struct termios | oldterm |
| struct termios | newterm |
| bool | engaged |
A class implementing a VT100-compatible terminal suitable for command line interaction models.
The class models an input line that automatically scrolls if the cursor reaches the end and the user still has text to enter. The input line is prefixed by a configurable prompt indicator.
Constructor.
| in | The terminal-attached input stream. | |
| out | The terminal-attached output stream. | |
| _size | The maximum buffer size. | |
| _wsize | The window width (0 for automatic). |
References buffer, crsr, curview, engaged, file::filno, historycrsr, idlearg, idlecb, len, ocrsr, owcrsr, setprompt(), size, utf8expect, wcrsr, and wsize.

| void termbuffer::advance | ( | void | ) | [protected] |
Automatically advance viewport cursor to updated situation.
References buffer, wcrsr, and wsize.
Referenced by clearleft(), crend(), crright(), insert(), setprompt(), wordleft(), and wordright().
| void termbuffer::clearleft | ( | void | ) |
Clear the terminal buffer to the left of the cursor.
References advance(), buffer, len, prompt, string::strlen(), and wcrsr.
Referenced by terminal< cli< ctlclass > >::readline(), and terminal< cli< ctlclass > >::readpass().

| void termbuffer::clearright | ( | void | ) |
Clear the terminal buffer to the right of the cursor.
Referenced by terminal< cli< ctlclass > >::readline(), and terminal< cli< ctlclass > >::readpass().
| void termbuffer::draw | ( | void | ) |
Update the terminal display.
Will selectively update the visible characters on the screen that have changed since the last time.
References buffer, curview, len, ocrsr, owcrsr, setpos(), tputc(), wcrsr, and wsize.
Referenced by getkey(), terminal< cli< ctlclass > >::readline(), and terminal< cli< ctlclass > >::readpass().

| int termbuffer::getkey | ( | void | ) |
Read a key from the terminal.
This process may be interrupted by console output sent by other threads through the termbuffer::sendconsole method if the user has not pressed a key for longer than 2 seconds.
References value::count(), curview, draw(), eventlock, events, idlearg, idlecb, len, lockbase::lockw(), file::puts(), file::read(), value::rmindex(), string::strlen(), and lockbase::unlock().
Referenced by terminal< cli< ctlclass > >::readline(), and terminal< cli< ctlclass > >::readpass().

| void termbuffer::insert | ( | const string & | str | ) | [inline] |
Insert a string into the buffer.
| str | The text to insert. |
References insert(), and string::strlen().

| void termbuffer::insert | ( | char | c | ) |
Insert a character into the buffer.
| c | The character to insert. |
References advance(), buffer, len, size, tputc(), and utf8expect.
Referenced by insert(), terminal< cli< ctlclass > >::readline(), terminal< cli< ctlclass > >::readpass(), and cli< ctlclass >::tabhandler().

| void termbuffer::off | ( | void | ) |
Turns terminal handling back off.
Should not be called for a terminal that has not first been called with termbuffer:on().
References engaged, file::filno, and oldterm.
Referenced by terminal< cli< ctlclass > >::off(), terminal< cli< ctlclass > >::readpass(), and cli< ctlclass >::run().
| void termbuffer::on | ( | void | ) |
Turns terminal handling on.
Should not be called twice in a row, or previous state will be nuked.
References engaged, file::filno, newterm, and oldterm.
Referenced by terminal< cli< ctlclass > >::readline(), and terminal< cli< ctlclass > >::readpass().
| void termbuffer::redraw | ( | void | ) | [inline] |
Force the buffer to be completely redrawn on the next draw() cycle.
References curview, and wsize.
Referenced by cli< ctlclass >::printf(), terminal< cli< ctlclass > >::readline(), and cli< ctlclass >::tabhandler().
| void termbuffer::sendconsole | ( | const string & | s | ) | [inline] |
Send a console message (should be called from another thread).
References eventlock, events, lockbase::lockw(), and lockbase::unlock().
Referenced by terminal< cli< ctlclass > >::sendconsole().

| void termbuffer::set | ( | const string & | to | ) |
Explicitly set the contents of the buffer.
Cursor will be moved to the end position.
References buffer, crend(), curview, len, prompt, size, string::str(), and string::strlen().
Referenced by terminal< cli< ctlclass > >::set(), and cli< ctlclass >::singlecmd().

| void termbuffer::setidlecb | ( | tbidlecb | mycb, | |
| void * | arg | |||
| ) | [inline] |
| void termbuffer::setpos | ( | int | cpos, | |
| int | npos | |||
| ) | [protected] |
| void termbuffer::setprompt | ( | const string & | prmpt | ) |
Set the prompt string.
The new prompt will be active at the next draw().
References advance(), buffer, value::count(), history, historycrsr, len, prompt, size, string::str(), and string::strlen().
Referenced by terminal< cli< ctlclass > >::readline(), terminal< cli< ctlclass > >::readpass(), and termbuffer().

| void termbuffer::writeconsole | ( | const string & | s | ) | [inline] |
Send a line directly to the console, with no regard to the state of the terminal.
Safe from command callbacks, unsafe from other threads.
References file::writeln().

1.6.1