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

TermHandler Class Reference

Inherits IOHandler.

List of all members.


Detailed Description

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

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

To use a TermHandler, you will typically

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


Public Methods

 TermHandler (IOEventLoop &loop, string prompt=">")
 Constructor.

 ~TermHandler ()
 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

TermHandler::TermHandler IOEventLoop   loop,
string    prompt = "> "
 

Constructor.

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

TermHandler::~TermHandler  
 

Destructor.


Member Function Documentation

template<class CallbackType>
void TermHandler::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 TermHandler::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 TermHandler::text_arg = 0x10000 [static]
 

const unsigned int TermHandler::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:11 2002 for NMSTL