FACT++  1.0
Readline::Readline ( const char *  prgname)

Construct a Readline object. The constructor reads the history from a history file. The filename is compiled by adding ".his" to the supplied argument. The name oif the history file is stored in fName.

Since readline has a global namespace, the creation of only one Readline instance is allowed.

The provided program name is supplied to readline by means of rl_readline_name.

Readlines default callback frunction for completions is redirected to CompletionImp which in turn will call Completion, which can be overwritten by the user.

Bind some default key sequences like Page-up/-down for searching forward and backward in history.

Parameters
prgnameThe prefix of the history filename. Usually the program name, which can be initialized by argv[0].

Definition at line 105 of file Readline.cc.

References fCommandLog, fName, rl_ncurses_completion_display(), rl_ncurses_completion_function(), rl_ncurses_event_hook(), rl_ncurses_getc(), rl_ncurses_redisplay(), rl_ncurses_startup(), and This.

Referenced by SetSection().

105  :
106  fMaxLines(500), fLine(0), fSection(-4), fLabel(-1), fCompletion(0)
107 {
108  if (This)
109  {
110  cout << "ERROR - Readline can only be instatiated once!" << endl;
111  exit(-1);
112  }
113 
114  This = this;
115 
116  // Alternative completion function
117  rl_attempted_completion_function = rl_ncurses_completion_function;
118 
119  // Program name
120 #if BOOST_VERSION < 104600
121  static const string fname = boost::filesystem::path(prgname).filename();
122 #else
123  static const string fname = boost::filesystem::path(prgname).filename().string();
124 #endif
125  rl_readline_name = fname.c_str();
126 
127  // Compile filename for history file
128  fName = string(prgname)+".his";
129 
130  // Read history file
131  read_history(fName.c_str());
132  //if (read_history(fName.c_str()))
133  // cout << "WARNING - Reading " << fName << ": " << strerror(errno) << endl;
134 
135  fCommandLog.open(string(prgname)+".evt");
136 
137  // Setup the readline callback which are needed to redirect
138  // the otuput properly to our ncurses panel
139  rl_getc_function = rl_ncurses_getc;
140  rl_startup_hook = rl_ncurses_startup;
141  rl_redisplay_function = rl_ncurses_redisplay;
142  rl_event_hook = rl_ncurses_event_hook;
143  rl_completion_display_matches_hook = rl_ncurses_completion_display;
144 
145  // Bind delete, page up, page down
146  rl_bind_keyseq("\e[1~", rl_named_function("beginning-of-line"));
147  rl_bind_keyseq("\e[3~", rl_named_function("delete-char"));
148  rl_bind_keyseq("\e[4~", rl_named_function("end-of-line"));
149  rl_bind_keyseq("\e[5~", rl_named_function("history-search-backward"));
150  rl_bind_keyseq("\e[6~", rl_named_function("history-search-forward"));
151  rl_bind_keyseq("\033[1;3F", rl_named_function("kill-line"));
152  rl_bind_keyseq("\033[1;5D", rl_named_function("backward-word"));
153  rl_bind_keyseq("\033[1;5C", rl_named_function("forward-word"));
154  rl_bind_key(25, rl_named_function("kill-whole-line"));
155 
156  //for (int i=0; i<10; i++) cout << (int)getchar() << endl;
157 }
static Readline * This
Definition: Readline.h:19
const std::vector< std::string > * fCompletion
Pointer to a list of possible matched for auto-completion.
Definition: Readline.h:63
static int rl_ncurses_event_hook()
Definition: Readline.cc:260
std::ofstream fCommandLog
Maximum number of lines in the history file.
Definition: Readline.h:25
int fMaxLines
Filename for the history file compiled in the constructor.
Definition: Readline.h:23
static int rl_ncurses_startup()
Definition: Readline.cc:237
std::string fName
Definition: Readline.h:22
static char ** rl_ncurses_completion_function(const char *text, int start, int end)
Definition: Readline.cc:286
int fSection
Definition: Readline.h:30
static void rl_ncurses_completion_display(char **matches, int num, int max)
Definition: Readline.cc:281
static int rl_ncurses_getc(FILE *)
Static member function which are used to adapt readline to ncurses.
Definition: Readline.cc:227
int fLine
Last line adde to history.
Definition: Readline.h:29
static void rl_ncurses_redisplay()
Definition: Readline.cc:249
int fLabel
Definition: Readline.h:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function: