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; }
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; }
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); }
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 }
/* 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 (); }
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; }
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; }
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 ); }
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); }
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); }
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; }
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); }
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; }
void restore_rl_state() { char *newprompt; move_cursor_to_start_of_prompt(impatient_prompt ? ERASE : DONT_ERASE); cook_prompt_if_necessary(); newprompt = mark_invisible(saved_rl_state.cooked_prompt); /* bracket (colour) control sequences with \001 and \002 */ rl_expand_prompt(newprompt); mirror_slaves_echo_mode(); /* don't show passwords etc */ DPRINTF1(DEBUG_READLINE,"newprompt now %s", mangle_string_for_debug_log(newprompt,MANGLE_LENGTH)); rl_callback_handler_install(newprompt, &line_handler); DPRINTF0(DEBUG_AD_HOC, "freeing newprompt"); free(newprompt); /* readline docs don't say it, but we can free newprompt now (readline apparently uses its own copy) */ rl_insert_text(saved_rl_state.input_buffer); rl_point = saved_rl_state.point; saved_rl_state.already_saved = 0; DPRINTF0(DEBUG_AD_HOC, "Starting redisplay"); rl_redisplay(); rl_prep_terminal(1); prompt_is_still_uncooked = FALSE; /* has been done right now */ }
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; }
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; }
int net_getline (char **s, size_t *l) { got_it_ok = 0; _s = s; _l = l; rl_callback_handler_install (0, got_it); net_loop (1, is_got_it); return 0; }
int tty_cmd(int argc, char **argv) { g_context.ttymode = 1; rl_callback_handler_remove(); rl_callback_handler_install("", cli_handler); return 0; }
void repl_callback_enable(char *prompt) { callback_en = 1; if (prompt_string == NULL || strcmp(prompt, prompt_string)) { if (prompt_string) free(prompt_string); prompt_string = strdup(prompt); } rl_callback_handler_install(prompt_string, jl_input_line_callback); }
void ssc_input_install_handler(const char* prompt, ssc_input_handler_cb func) { #if USE_READLINE rl_callback_handler_install(prompt, func); #else /* nop */ #endif ssc_input_handler_f = func; }
/* Unregister the current readline handler and pop it from R's readline stack, followed by re-registering the previous one. */ static void popReadline(void) { if(ReadlineStack.current > -1) { rl_callback_handler_remove(); ReadlineStack.fun[ReadlineStack.current--] = NULL; if(ReadlineStack.current > -1 && ReadlineStack.fun[ReadlineStack.current]) rl_callback_handler_install("", ReadlineStack.fun[ReadlineStack.current]); } }
int close_cmd(int argc, char **argv) { if(g_context.args.script == 0) { rl_callback_handler_remove(); rl_callback_handler_install("", cli_handler); } g_context.exit = 1; return 0; }
int main( int argc, char *argv[] ) { args( argc, argv ); open_tty(); if( isatty( packet_fd )) setup_tty(); nipp_attach( packet_fd ); rl_callback_handler_install( prompt, line_handler ); poll(); return EXIT_SUCCESS; }
static gboolean ncl_prv_kbinput_cb(GIOChannel *source, GIOCondition condition, gpointer data) { rl_callback_read_char(); #ifdef HAVE_LIBEDIT /* Editline bug workaround: handler install with the original prompt corrects EL_UNBUFFERED state without side-effects. */ rl_callback_handler_install(NCL_PROMPT, ncl_parse_line); #endif return TRUE; }
static void send_line(char *l) { if (l) { cli_write(_line_sock, l); cli_write(_line_sock, "\n"); add_history(l); rl_callback_handler_install("varnish> ", send_line); } else { RL_EXIT(0); } }
void gdb_rl_callback_handler_install (const char *prompt) { /* Calling rl_callback_handler_install resets readline's input buffer. Calling this when we were already processing input therefore loses input. */ gdb_assert (!callback_handler_installed); rl_callback_handler_install (prompt, input_handler); callback_handler_installed = 1; }
static void input_init(void) { rl_readline_name = "birdc"; rl_add_defun("bird-complete", input_complete, '\t'); rl_add_defun("bird-help", input_help, '?'); rl_callback_handler_install("bird> ", got_line); input_initialized = 1; // readline library does strange things when stdin is nonblocking. // if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) // die("fcntl: %m"); }
int main() { printf("Start.\n"); rl_bind_key(RETURN, io_handle_enter); rl_callback_handler_install(prompt, handle_line); while (running) { usleep(10); rl_callback_read_char(); } rl_callback_handler_remove(); }
/* Registers the specified routine and prompt with readline and keeps a record of it on the top of the R readline stack. */ static void pushReadline(const char *prompt, rl_vcpfunc_t f) { if(ReadlineStack.current >= ReadlineStack.max) { warning(_("An unusual circumstance has arisen in the nesting of readline input. Please report using bug.report()")); } else ReadlineStack.fun[++ReadlineStack.current] = f; rl_callback_handler_install(prompt, f); /* flush stdout in case readline wrote the prompt, but didn't flush stdout to make it visible. (needed for Apple's rl in OS X 10.4-pre) */ fflush(stdout); }
static void console_line_ready(char *line) { if (line) { add_history(line); inject_to_server(packet_new(PACKET_CHAT_MESSAGE, line)); } else /* ^D */ exit(0); free(line); rl_callback_handler_install("> ", console_line_ready); }