本文整理汇总了C++中rl_callback_handler_install函数的典型用法代码示例。如果您正苦于以下问题:C++ rl_callback_handler_install函数的具体用法?C++ rl_callback_handler_install怎么用?C++ rl_callback_handler_install使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rl_callback_handler_install函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: edit_init
int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos),
void *ctx, const char *history_file, const char *ps)
{
edit_cb_ctx = ctx;
edit_cmd_cb = cmd_cb;
edit_eof_cb = eof_cb;
edit_completion_cb = completion_cb;
rl_attempted_completion_function = readline_completion;
if (history_file) {
read_history(history_file);
stifle_history(100);
}
eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);
if (ps) {
size_t blen = os_strlen(ps) + 3;
char *ps2 = os_malloc(blen);
if (ps2) {
os_snprintf(ps2, blen, "%s> ", ps);
rl_callback_handler_install(ps2, readline_cmd_handler);
os_free(ps2);
return 0;
}
}
rl_callback_handler_install("> ", readline_cmd_handler);
return 0;
}
示例2: rl_callback_handler_install
void *
ConsoleUI::threadMain(void *arg) {
rl_callback_handler_install("", ConsoleUICallbacks::lineRead);
while (!quit) {
while (canRead()) {
lineProcessed = false;
rl_callback_read_char();
if (lineProcessed && rl_prompt != NULL && rl_prompt[0] != '\0') {
// If a line has been processed, reset the prompt
// so we don't see it again after an Enter.
rl_set_prompt("");
rl_display_prompt = NULL;
rl_redisplay();
}
}
pthread_mutex_lock(&outputLock);
if (!output.empty()) {
processOutput();
pthread_cond_broadcast(&outputCond);
}
pthread_mutex_unlock(&outputLock);
usleep(10000);
}
rl_callback_handler_remove();
return NULL;
}
示例3: console_init
int
console_init(int infd, int outfd, cons_info_t *ci, int cnt,
cons_exit_handler exitcb, const char *prompt)
{
if (cmds != NULL) {
return (-1);
}
cmds = ci;
cmd_cnt = cnt;
exit_handler = exitcb;
cons_prompt = prompt;
infile = infd == 0 ? stdin : fdopen(infd, "r");
outfile = outfd == 1 ? stdout : fdopen(outfd, "w");
#ifdef USE_READLINE
rl_instream = infile;
rl_outstream = outfile;
rl_completion_entry_function = possible_cmds;
#ifdef THREADS
if (pthread_create(&cons_tid, NULL, console_thr, NULL) != 0) {
return (-1);
}
#else
rl_callback_handler_install(prompt, handle_rlinput);
#endif /* THREADS */
#else
fprintf(outfile, "%s", prompt);
fflush(outfile);
#endif /* USE_READLINE */
return (0);
}
示例4: rl_callback_handler_remove
char *ssc_input_read_string(char *str, int size)
{
#if USE_READLINE
char *input;
/* disable readline callbacks */
if (ssc_input_handler_f)
rl_callback_handler_remove();
rl_reset_line_state();
/* read a string a feed to 'str' */
input = readline(ssc_input_prompt);
strncpy(str, input, size - 1);
str[size - 1] = 0;
/* free the copy malloc()'ed by readline */
free(input);
/* reinstall the func */
if (ssc_input_handler_f)
rl_callback_handler_install(ssc_input_prompt, ssc_input_handler_f);
rl_redisplay();
return str;
#else
return fgets(str, size, stdin);
#endif
}
示例5: cli_command_loop
/* Initialize all the necessary variables, start the event loop,
register readline, and stdin, start the loop. */
void
cli_command_loop (void *data /* unused */)
{
int length;
char *a_prompt;
char *gdb_prompt = get_prompt ();
/* If we are using readline, set things up and display the first
prompt, otherwise just print the prompt. */
if (async_command_editing_p)
{
/* Tell readline what the prompt to display is and what function it
will need to call after a whole line is read. This also displays
the first prompt. */
length = strlen (PREFIX (0)) + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1;
a_prompt = (char *) xmalloc (length);
strcpy (a_prompt, PREFIX (0));
strcat (a_prompt, gdb_prompt);
strcat (a_prompt, SUFFIX (0));
rl_callback_handler_install (a_prompt, input_handler);
}
else
display_gdb_prompt (0);
/* Now it's time to start the event loop. */
start_event_loop ();
}
示例6: main
int main(int argc, char *argv[]) {
if (argc != 2) {
char usage[] = "%s block_directory\n\t"
"Starts the bitcoin client with block chain storage "
"in the specified directory\n";
printf(usage, argv[0]);
exit(2);
}
srand(time(NULL));
/* initialize block chain and selector */
char *dir = make_dir(argv[1]);
block_chain = BRNewBlockChain(dir);
selector = BRNewSelector();
/* allow readline to work with select */
rl_callback_handler_install("$ ", handle_line);
BRAddSelectable(selector, STDIN_FILENO, readline_callback, NULL, 0, FOR_READING);
BRLoop(selector);
free(dir);
return 0;
}
示例7: cli_init
int cli_init(struct parser_state *_state)
{
const char *home;
rl_readline_name = "nft";
rl_instream = stdin;
rl_outstream = stdout;
rl_callback_handler_install("nft> ", cli_complete);
rl_attempted_completion_function = cli_completion;
home = getenv("HOME");
if (home == NULL)
home = "";
snprintf(histfile, sizeof(histfile), "%s/%s", home, CMDLINE_HISTFILE);
read_history(histfile);
history_set_pos(history_length);
state = _state;
scanner = scanner_init(state);
while (!eof)
rl_callback_read_char();
return 0;
}
示例8: tty_init
void tty_init( const char *name, const char *prompt )
{
if( isatty(STDOUT_FILENO)){
char *term;
char *area = tent;
if( NULL == (term = getenv("TERM") )){
term="dumb";
}
if( 0 <= tgetent( tent, term ) ){
tcap.clreol = tgetstr("ce", &area );
tcap.abold = tgetstr("md", &area );
tcap.anorm = tgetstr("me", &area );
}
}
dmsg_msg_cb = tty_vmsg;
dfmt_bf = tcap.abold;
dfmt_nf = tcap.anorm;
rl_readline_name = name;
rl_attempted_completion_function = tty_completer;
rl_callback_handler_install( prompt, tty_executor );
}
示例9: readline_status_mode
void
readline_status_mode (cli_context_t *ctx, const keymap_entry_t map[])
{
int i;
Keymap stkmap;
readline_cli_ctx = ctx;
rl_callback_handler_install (NULL, &readline_status_callback);
/* Backup current keymap-name */
readline_keymap = g_strdup (rl_get_keymap_name (rl_get_keymap ()));
/* New keymap for status mode */
stkmap = rl_make_bare_keymap ();
/* Fill out the keymap and display it. */
g_printf ("\n");
for (i = 0; map[i].keyseq; i++) {
rl_set_key (map[i].keyseq,
rl_named_function (map[i].named_function),
stkmap);
if (map[i].readable_keyseq) {
g_printf (" (%s) %s\n", map[i].readable_keyseq,
map[i].readable_function ? map[i].readable_function
: map[i].named_function);
}
}
g_printf ("\n");
rl_set_keymap (stkmap);
}
示例10: readline_resume
void
readline_resume (cli_context_t *ctx)
{
configuration_t *config = cli_context_config (ctx);
rl_callback_handler_install (configuration_get_string (config, "PROMPT"),
&readline_callback);
}
示例11: main
int
main (int c, char **v)
{
fd_set fds;
int r;
/* Install the line handler. */
rl_callback_handler_install (prompt, cb_linehandler);
/* Enter a simple event loop. This waits until something is available
to read on readline's input stream (defaults to standard input) and
calls the builtin character read callback to read it. It does not
have to modify the user's terminal settings. */
running = 1;
while (running)
{
FD_ZERO (&fds);
FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
if (r < 0 && errno != EINTR)
{
perror ("rltest: select");
rl_callback_handler_remove ();
break;
}
if (FD_ISSET (fileno (rl_instream), &fds))
rl_callback_read_char ();
}
printf ("rltest: Event loop has exited\n");
return 0;
}
示例12: install_line_handler
static void install_line_handler() {
if (rl_bind_key(RETURN, io_handle_enter)) {
io_printfln("failed to bind RETURN");
abort();
}
rl_callback_handler_install(prompt, handle_line_fake);
}
示例13: cli_rl_enable
int
cli_rl_enable (struct cli_state *state)
{
int ret = 0;
rl_pre_input_hook = NULL;
rl_attempted_completion_function = cli_rl_autocomplete;
rl_completion_entry_function = complete_none;
if (!state->rl_async) {
ret = pthread_create (&state->input, NULL,
cli_rl_input, state);
if (ret == 0)
state->rl_enabled = 1;
goto out;
}
ret = event_register (state->ctx->event_pool, 0, cli_rl_stdin, state,
1, 0);
if (ret == -1)
goto out;
state->rl_enabled = 1;
rl_callback_handler_install (state->prompt, cli_rl_process_line);
out:
return state->rl_enabled;
}
示例14: displayCmdLine
char* displayCmdLine(WINDOW *win){
curs_set(2);
winCommandMode = win;
wmove (win, 1, 1);
//wprintw(winCommandMode, prompt);
wrefresh(win);
//rl_bind_key(RETURN, io_handle_enter);
rl_redisplay_function = (rl_voidfunc_t*)rl_redisplay_mod;
wprintw(winCommandMode, prompt);
char* line = readline(prompt);
add_history(line);
// for testing history
//line = readline(prompt);
wmove (win, 1, 11);
wprintw(winCommandMode, line);
wrefresh(win);
return line;
rl_callback_handler_install(prompt, handle_line);
while (prog_running) {
usleep(10);
rl_callback_read_char();
}
rl_callback_handler_remove();
//handle_command(rl_line_buffer);
return rl_line_buffer;
}
示例15: readline_until_enter_or_signal
static char *
readline_until_enter_or_signal(const char *prompt, int *signal)
{
char * not_done_reading = "";
fd_set selectset;
*signal = 0;
#ifdef HAVE_RL_CATCH_SIGNAL
rl_catch_signals = 0;
#endif
rl_callback_handler_install (prompt, rlhandler);
FD_ZERO(&selectset);
completed_input_string = not_done_reading;
while (completed_input_string == not_done_reading) {
int has_input = 0, err = 0;
while (!has_input)
{ struct timeval timeout = {0, 100000}; /* 0.1 seconds */
/* [Bug #1552726] Only limit the pause if an input hook has been
defined. */
struct timeval *timeoutp = NULL;
if (PyOS_InputHook)
timeoutp = &timeout;
FD_SET(fileno(rl_instream), &selectset);
/* select resets selectset if no input was available */
has_input = select(fileno(rl_instream) + 1, &selectset,
NULL, NULL, timeoutp);
err = errno;
if(PyOS_InputHook) PyOS_InputHook();
}
if (has_input > 0) {
rl_callback_read_char();
}
else if (err == EINTR) {
int s;
#ifdef WITH_THREAD
PyEval_RestoreThread(_PyOS_ReadlineTState);
#endif
s = PyErr_CheckSignals();
#ifdef WITH_THREAD
PyEval_SaveThread();
#endif
if (s < 0) {
rl_free_line_state();
rl_cleanup_after_signal();
rl_callback_handler_remove();
*signal = 1;
completed_input_string = NULL;
}
}
}
return completed_input_string;
}