rlmm::basic_readline< Lock > Struct Template Reference
[The Readline classes.]

#include <rlmm/readline.hh>

Inheritance diagram for rlmm::basic_readline< Lock >:

Inheritance graph
[legend]
Collaboration diagram for rlmm::basic_readline< Lock >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename Lock>
struct rlmm::basic_readline< Lock >

Readline.

Interface the C readline library

A very basic example is

//
// $Id: basic.cc,v 1.2 2005/08/10 10:30:25 cholm Exp $ 
//  
//  simple.cc
//  Copyright (C) 2002 Christian Holm Christensen <cholm@nbi.dk> 
//
//  This library is free software; you can redistribute it and/or 
//  modify it under the terms of the GNU Lesser General Public License 
//  as published by the Free Software Foundation; either version 2.1 
//  of the License, or (at your option) any later version. 
//
//  This library is distributed in the hope that it will be useful, 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
//  Lesser General Public License for more details. 
// 
//  You should have received a copy of the GNU Lesser General Public 
//  License along with this library; if not, write to the Free 
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
//  02111-1307 USA 
//
#ifdef HAVE_CONFIG_H
# include <config.hh>
#endif
#ifndef rlmm_readline_hh
# include <rlmm/readline.hh>
#endif
#ifndef __IOSTREAM__
# include <iostream>
#endif

/** @file   rlmmtest.cc
    @author Christian Holm
    @date   Mon Oct  7 13:57:07 2002
    @brief  Very basic example. */

using namespace std;
using namespace rlmm;

//____________________________________________________________________
/** @namespace examples. 
    @brief Namespace for all the examples in rlmm. 

    All examples belong to this namespace (just to make it easier to
    see what is code and what is examples. */ 
namespace examples
{
  /// The (almost) most basic example of using rlmm. 
  class basic : public rlmm::readline 
  {
  private:
    /// The prompt. 
    string _prompt;
  public:
    /** CTOR
        @param prompt The prompt to use. */
    basic(const string& prompt) : _prompt(prompt) { _prompt += "> "; }
    /// Run this example. 
    int run() {
      string line;
      while(read(_prompt, line)) cout << line << endl;
      return 0;
    }
  };
}

//____________________________________________________________________
int main(int argc, char** argv) 
{
  examples::basic b(argv[0]);
  return b.run();
}

//____________________________________________________________________
//
// EOF
//


Examples:

rlmmtest.cc.


Variables and functions

int variable (const std::string &var, const std::string &val)
void list_variables (bool inputrc=false)
static command_t last_command ()

Public Types

enum  edit_mode { vi, emacs }
enum  state_bit {
  none, initializing, initialized, terminal_preped,
  command, meta, dispatching, more,
  incremental, non_incremental, search, numeric_arg,
  macro_input, macro_define, overwrite, completing,
  signal, undo, pending, finish
}

Public Member Functions

virtual ~basic_readline ()
const std::string & name () const
void name (const std::string &name)
Initialise
int read_init_file (const std::string &file=std::string())
bool parse (const std::string &line)
Reading lines
bool read (const std::string &prompt, std::string &line)
bool read (const std::string &prompt, char *&line)
Status information
int state () const
void state (int status)
int state (state_bit bit, bool on=true)
bool test_state (state_bit bit) const
Prompting
const std::string & prompt () const
void prompt (const std::string &prompt)
void save_prompt ()
void restore_prompt ()
void expand_prompt (const std::string &prompt)
void already_prompted (bool already=true)
bool already_prompted () const
Editing mode
edit_mode editing_mode () const
void editing_mode (edit_mode mode=emacs)
Miscellaneous parameters
bool clear_empty_lines () const
void clear_empty_lines (bool clear=true)
int max_read () const
void max_read (int n)
void parenthesis_timeout (int us)
Miscellaneous operations
void done ()
int parenthesis_blink_timeout () const
void parenthesis_blink_timeout (int us)
std::string version ()
bool gnu_readline ()
Hooks
virtual int input_hook ()
virtual int event_hook ()
virtual int startup_hook ()

Protected Member Functions

 basic_readline ()
 basic_readline (const basic_readline &o)
basic_readlineoperator= (const basic_readline &o)

Protected Attributes

std::string _name
int _parenthesis_blink_timeout

Friends

class singleton


Member Enumeration Documentation

template<typename Lock>
enum rlmm::basic_readline::edit_mode
 

EditingMode.

Enum of possible editing modes

Enumerator:
vi 
emacs 

template<typename Lock>
enum rlmm::basic_readline::state_bit
 

State.

The state of the readline library.

Enumerator:
none  nothing yet
initializing  What you expect.
initialized  What you expect.
terminal_preped  The terminal is prepared.
command  Reading a command.
meta  Read a meta-prefix.
dispatching  Dispatching to a cimmand.
more  Reading more input after an editing command.
incremental  Performing incremental search.
non_incremental  Performing a non-incremental search.
search  Performing a search.
numeric_arg  Reading a numeric argument.
macro_input  Input from a macro expansion.
macro_define  Reading charaters for a macro replacement text.
overwrite  In overwrite mode.
completing  In completion mode.
signal  In the signal handler.
undo  Undoing previous stuff.
pending  More to read.
finish  About to return line to caller.


Constructor & Destructor Documentation

template<typename Lock>
rlmm::basic_readline< Lock >::basic_readline  )  [inline, protected]
 

Create an readline.

template<typename Lock>
rlmm::basic_readline< Lock >::basic_readline const basic_readline< Lock > &  o  )  [inline, protected]
 

Constructor.

template<typename Lock>
virtual rlmm::basic_readline< Lock >::~basic_readline  )  [inline, virtual]
 

DTOR.


Member Function Documentation

template<typename Lock>
bool rlmm::basic_readline< Lock >::already_prompted  )  const [inline]
 

Does application control the prompt?

Returns:
true if application deals with the prompt itself.

template<typename Lock>
void rlmm::basic_readline< Lock >::already_prompted bool  already = true  )  [inline]
 

Set if application does the prompting.

If the application is in charge of doing the prompting itself, it should tell readline so by calling this member function.

Parameters:
already Should be true if applcation sets the prompt.

template<typename Lock>
void rlmm::basic_readline< Lock >::clear_empty_lines bool  clear = true  )  [inline]
 

Set wether or not to clear empty lines.

Parameters:
clear true if empty lines should be ignored.

template<typename Lock>
bool rlmm::basic_readline< Lock >::clear_empty_lines  )  const [inline]
 

See if empty lines are dicarded.

Returns:
true if clearing empty lines

template<typename Lock>
void rlmm::basic_readline< Lock >::done  )  [inline]
 

Force readline to return immediately.

template<typename Lock>
void rlmm::basic_readline< Lock >::editing_mode edit_mode  mode = emacs  )  [inline]
 

Set the editing mode.

Parameters:
mode Mode to use.

template<typename Lock>
basic_readline< Lock >::edit_mode rlmm::basic_readline< Lock >::editing_mode  )  const [inline]
 

Get the editing mode.

Returns:
emacs for Emacs-like, and vi for vi-like

template<typename Lock>
int rlmm::basic_readline< Lock >::event_hook  )  [inline, virtual]
 

Event Hook.

member function to be run after event timeout. Users can overload this function to do some period checking.

Returns:
has no special meaning and is ignored by C API.

template<typename Lock>
void rlmm::basic_readline< Lock >::expand_prompt const std::string &  prompt  )  [inline]
 

Expand the prompt to new prompt.

Parameters:
prompt The new prompt.

template<typename Lock>
bool rlmm::basic_readline< Lock >::gnu_readline  )  [inline]
 

Test if this GNU readline (it is, trust me).

template<typename Lock>
int rlmm::basic_readline< Lock >::input_hook  )  [inline, virtual]
 

Input hook.

member function to be run after input timeout. Users can overload this function to do some period checking.

Returns:
has no special meaning and is ignored by C API.

template<typename Lock>
rlmm::command_t rlmm::basic_readline< Lock >::last_command  )  [inline, static]
 

Return pointer to last command executed.

template<typename Lock>
void rlmm::basic_readline< Lock >::list_variables bool  inputrc = false  )  [inline]
 

Show a list of currently defined variables.

template<typename Lock>
void rlmm::basic_readline< Lock >::max_read int  n  )  [inline]
 

Set the limit on reads before returning.

Parameters:
n Maximum number of characters to read before returning. 0 or less means upto a newline.

template<typename Lock>
int rlmm::basic_readline< Lock >::max_read  )  const [inline]
 

Get the limit on reads before returning .

Returns:
Maximum number of characters to read before returning. 0 or less means upto a newline.

template<typename Lock>
void rlmm::basic_readline< Lock >::name const std::string &  name  )  [inline]
 

Set the unique appliation name.

Parameters:
name the application name.

template<typename Lock>
const std::string & rlmm::basic_readline< Lock >::name  )  const [inline]
 

Get the unique application name.

Returns:
the unique application name

template<typename Lock>
basic_readline< Lock > & rlmm::basic_readline< Lock >::operator= const basic_readline< Lock > &  o  )  [inline, protected]
 

Constructor.

template<typename Lock>
void rlmm::basic_readline< Lock >::parenthesis_blink_timeout int  us  )  [inline]
 

Set the parenthis blink timeout in $ \mu{}s$.

Parameters:
us Timeout.

template<typename Lock>
int rlmm::basic_readline< Lock >::parenthesis_blink_timeout  )  const [inline]
 

template<typename Lock>
void rlmm::basic_readline< Lock >::parenthesis_timeout int  us  )  [inline]
 

Set the timeout (micro seconds) before showing matching parenthesis.

Parameters:
us timeout in microseconds.

template<typename Lock>
bool rlmm::basic_readline< Lock >::parse const std::string &  line  )  [inline]
 

Parse a line and do bindings accordingly.

Parameters:
line Line to parse.
Returns:
true on success, false otherwise.

template<typename Lock>
void rlmm::basic_readline< Lock >::prompt const std::string &  prompt  )  [inline]
 

Set the prompt.

Parameters:
prompt Prompt to use.

template<typename Lock>
const std::string & rlmm::basic_readline< Lock >::prompt  )  const [inline]
 

Get the current prompt.

Returns:
the current prompt

template<typename Lock>
bool rlmm::basic_readline< Lock >::read const std::string &  prompt,
char *&  line
[inline]
 

Read one line of input User must free() the returned line read.

Parameters:
prompt Prompt to be displayed.
line Line read (NULL terminated).
Returns:
true on success, false otherwise.

template<typename Lock>
bool rlmm::basic_readline< Lock >::read const std::string &  prompt,
std::string &  line
[inline]
 

Read one line of input.

Parameters:
prompt Prompt to be displayed.
line Line read.
Returns:
true on success, false otherwise.

template<typename Lock>
int rlmm::basic_readline< Lock >::read_init_file const std::string &  file = std::string()  )  [inline]
 

Read settings from a file.

Parameters:
file file to read from. If empty, then the default file is read, which is (in order or priority): Last file read with this member function; value of INPUTRC; or ~/.inputrc.
Returns:
0 on success, otherwise errno

template<typename Lock>
void rlmm::basic_readline< Lock >::restore_prompt  )  [inline]
 

Restore the prompt previously saved.

template<typename Lock>
void rlmm::basic_readline< Lock >::save_prompt  )  [inline]
 

Save away the prompt.

template<typename Lock>
int rlmm::basic_readline< Lock >::startup_hook  )  [inline, virtual]
 

Startup hook.

member function to be run after event timeout. Users can overload this function to do some period checking.

Returns:
has no special meaning and is ignored by C API.

template<typename Lock>
int rlmm::basic_readline< Lock >::state state_bit  bit,
bool  on = true
[inline]
 

Set a bit in the status of readline.

Parameters:
bit A state bit.
on if true, bit is turned on, otherwise off.

template<typename Lock>
void rlmm::basic_readline< Lock >::state int  status  )  [inline]
 

Set the status of readline.

Parameters:
status A bit-wise or of state bits.

template<typename Lock>
int rlmm::basic_readline< Lock >::state  )  const [inline]
 

Get the status of readline.

This is an bitwise or of the bits in the state enum

Returns:
the status of readline.

template<typename Lock>
bool rlmm::basic_readline< Lock >::test_state state_bit  bit  )  const [inline]
 

Test a bit in the status.

Parameters:
bit State bit to test.
Returns:
true if bit is on.

template<typename Lock>
int rlmm::basic_readline< Lock >::variable const std::string &  var,
const std::string &  val
[inline]
 

Set a variable.

Parameters:
var variable name.
val The value.

template<typename Lock>
std::string rlmm::basic_readline< Lock >::version  )  [inline]
 

Get the version of readline (C) library.


Friends And Related Function Documentation

template<typename Lock>
friend class singleton [friend]
 

Base class is a friend.


Member Data Documentation

template<typename Lock>
std::string rlmm::basic_readline< Lock >::_name [mutable, protected]
 

Name of the readline application.

template<typename Lock>
int rlmm::basic_readline< Lock >::_parenthesis_blink_timeout [protected]
 

parenthesis blink timeout in $ \mu{}s$


The documentation for this struct was generated from the following file:
Top of page
Last update Fri Aug 26 15:19:53 2005
Christian Holm
Created by DoxyGen 1.4.4