$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/ui/cmdline/SReadline.hpp File Reference

C++ wrapper around libreadline. More...

#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <readline/keymaps.h>
#include <string>
#include <fstream>
#include <vector>
#include <stdexcept>
#include <map>
#include <boost/algorithm/string/trim.hpp>
#include <boost/tokenizer.hpp>
#include <boost/function.hpp>

Go to the source code of this file.


Namespaces

namespace  swift

Classes

class  swift::SKeymap
 The readline keymap wrapper. More...
class  swift::SReadline
 The readline library wrapper. More...

Typedefs

typedef std::vector< std::string > TokensStorage
 Tokens in a single variation of a user command.
typedef std::vector< TokensStorageCompletionsStorage
 Set of variations of user commands.
typedef boost::function< int(int, int)> KeyCallback
 Pressed key callback. Must return 0 if OK, != 0 otherwise.
typedef std::map< int, KeyCallbackKeysBind
 A set of keys binding.

Functions

const size_t DefaultHistoryLimit (64)
bool KeymapWasSetup (false)
Keymap Earlykeymap (0)
char * Generator (const char *text, int State)
 Custom completion generator.
char ** UserCompletion (const char *text, int start, int end)
 The function is called before trying to complete a token.
int KeyDispatcher (int Count, int Key)
 The function selects the set of bindings and makes the corresponding call.
int StartupHook (void)
 The readline startup hook. It is required to setup the proper keymap.
template<typename Container>
bool AreTokensEqual (const Container &Pattern, const Container &Input)
 Compares all the Input tokens with starts tokens in the Pattern.
template<typename ContainerType>
void SplitTokens (const std::string &Source, ContainerType &Container)
char ** UserCompletion (const char *text, int start, int end)
char * Generator (const char *text, int State)
int KeyDispatcher (int Count, int Key)
int StartupHook (void)

Variables

CompletionsStorage Completions
TokensStorage Tokens
std::map< Keymap, KeysBindKeymaps

Detailed Description

C++ wrapper around libreadline.

Supported: editing, history, custom completers, keymaps. Attention: implementation is not thread safe! It is mainly because the readline library provides pure C interface and has many calls for an "atomic" completion operation

Definition in file SReadline.hpp.


Typedef Documentation

typedef std::vector<std::string> TokensStorage [static]

Tokens in a single variation of a user command.

Definition at line 54 of file SReadline.hpp.

typedef std::vector<TokensStorage> CompletionsStorage [static]

Set of variations of user commands.

Definition at line 59 of file SReadline.hpp.

typedef boost::function<int (int, int)> KeyCallback [static]

Pressed key callback. Must return 0 if OK, != 0 otherwise.

Definition at line 64 of file SReadline.hpp.

typedef std::map<int, KeyCallback> KeysBind [static]

A set of keys binding.

Definition at line 69 of file SReadline.hpp.


Function Documentation

const size_t @0::DefaultHistoryLimit ( 64   )  [static]

Default value for the history length.

bool @0::KeymapWasSetup ( false   )  [static]

Has sense if a keymap was setup before the first readline call.

Referenced by swift::SReadline::SetKeymap(), and StartupHook().

Keymap @0::Earlykeymap (  )  [static]

The keymap which was setup before the first readline call.

Referenced by swift::SReadline::SetKeymap(), and StartupHook().

char* @0::Generator ( const char *  text,
int  State 
) [static]

Custom completion generator.

Parameters:
text Pointer to a token to be completed
State 0 for a first call, non 0 for all consequent calls

Referenced by UserCompletion().

char** @0::UserCompletion ( const char *  text,
int  start,
int  end 
) [static]

The function is called before trying to complete a token.

Parameters:
text A token to be completed
start Index of the beginning of the token in the readline buffer
end Index of the end of the token in the readline buffer

Referenced by swift::SReadline::SReadline().

int @0::KeyDispatcher ( int  Count,
int  Key 
) [static]

The function selects the set of bindings and makes the corresponding call.

Parameters:
Count The parameter is passed by readline
Key The pressed key

Referenced by swift::SKeymap::Bind().

int @0::StartupHook ( void   )  [static]

The readline startup hook. It is required to setup the proper keymap.

Referenced by swift::SReadline::SReadline().

template<typename Container>
bool @0::AreTokensEqual ( const Container &  Pattern,
const Container &  Input 
) [static]

Compares all the Input tokens with starts tokens in the Pattern.

Parameters:
Pattern pattern tokens
Input user input tokens
Returns:
true if first Input.size() tokens are equal to the pattern tokens

Definition at line 146 of file SReadline.hpp.

Referenced by Generator(), and UserCompletion().

template<typename ContainerType>
void @0::SplitTokens ( const std::string &  Source,
ContainerType &  Container 
) [static]

char** @0::UserCompletion ( const char *  text,
int  start,
int  end 
) [static]

Definition at line 189 of file SReadline.hpp.

References AreTokensEqual(), Completions, Generator(), SplitTokens(), and Tokens.

char* @0::Generator ( const char *  text,
int  State 
) [static]

Definition at line 228 of file SReadline.hpp.

References AreTokensEqual(), Completions, and Tokens.

int @0::KeyDispatcher ( int  Count,
int  Key 
) [static]

Definition at line 267 of file SReadline.hpp.

References Keymaps.

int @0::StartupHook ( void   )  [static]

Definition at line 284 of file SReadline.hpp.

References Earlykeymap(), and KeymapWasSetup().


Variable Documentation

Global storage of custom completions.

Definition at line 79 of file SReadline.hpp.

Referenced by Generator(), swift::SReadline::RegisterCompletions(), and UserCompletion().

Tokens storage for a single completion session.

Definition at line 84 of file SReadline.hpp.

Referenced by Generator(), and UserCompletion().

std::map<Keymap, KeysBind> Keymaps [static]

Global storage for keymaps.

Definition at line 89 of file SReadline.hpp.

Referenced by swift::SKeymap::Bind(), KeyDispatcher(), swift::SKeymap::SKeymap(), swift::SKeymap::Unbind(), and swift::SKeymap::~SKeymap().