Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

term_handler Class Reference

Inherits io_handler.

List of all members.


Detailed Description

GNU Readline-based terminal input/output handler, providing command completion and history.

When using term_handler, you must link against libreadline.so and libncurses.so, i.e., add -lreadline -lncurses to your linker command line.

To use a term_handler, you will typically

Only one term_handler can be instantiated at a time, due to limitations in Readline.


Public Methods

 term_handler (io_event_loop &loop, string prompt=">")
 Constructor.

 ~term_handler ()
 Destructor.

void on_eof (callback< void > quit_cb)
 Registers a callback to be invoked when the input stream ends (e.g., the user types Control-D).

template<class CallbackType> void add_command (string name, unsigned int min_args, unsigned int max_args, CallbackType cb)
 Adds a binding for a command.


Static Public Attributes

const unsigned int text_arg = 0x10000
const unsigned int var_args = UINT_MAX
 A flag which may be passed to add_command (as the max_args argument) specifying that any number of arguments greater than or equal to min_args is valid.


Constructor & Destructor Documentation

term_handler::term_handler io_event_loop   loop,
string    prompt = "> "
 

Constructor.

Parameters:
loop  the event loop to bind to.
prompt  the string to be displayed when prompting for input.

term_handler::~term_handler  
 

Destructor.


Member Function Documentation

template<class CallbackType>
void term_handler::add_command string    name,
unsigned int    min_args,
unsigned int    max_args,
CallbackType    cb
 

Adds a binding for a command.

Parameters:
name  the name of the command (usually an all-lowercase string), optionally followed by a space and a human-readable description of the arguments.
min_args  the minimum acceptable number of arguments to the command (not including the command name)
max_args  the maximum acceptable number of arguments to the command. Use var_args if any number of arguments is acceptable, or num | text_arg if any more than num arguments should be concatenated and added to the previous argument (e.g., for a command like echo).
cb  the callback to be invoked when the command is run. The callback should have one of the following signatures:
void handler(void);
void handler(string arg1);
void handler(string arg1, string arg2);
void handler(string arg1, string arg2, string arg3);
void handler(vector<string> args);
status handler(void);
status handler(string arg1);
status handler(string arg1, string arg2);
status handler(string arg1, string arg2, string arg3);
status handler(vector<string> args);

The first three arguments are passed as arg1, arg2, and arg3; or all arguments are passed as args[0].

If the callback returns a "bad" status, it is displayed as an error message on the terminal.

void term_handler::on_eof callback< void >    quit_cb
 

Registers a callback to be invoked when the input stream ends (e.g., the user types Control-D).


Member Data Documentation

const unsigned int term_handler::text_arg = 0x10000 [static]
 

const unsigned int term_handler::var_args = UINT_MAX [static]
 

A flag which may be passed to add_command (as the max_args argument) specifying that any number of arguments greater than or equal to min_args is valid.


The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:10 2002 for NMSTL