static int newline_callback(int count, int key) { if (!rl_point) return 0; spaces_suppressed = 0; rl_insert_text("\n"); int i; for (i = 0; i < prompt_length; i++) rl_insert_text(" "); return 0; }
/* Turn the current line into a comment in shell history. A K*rn shell style function. */ int rl_vi_comment (int count, int key) { rl_beg_of_line (0, 0); if (rl_vi_comment_begin != (char *)NULL) rl_insert_text (rl_vi_comment_begin); else rl_insert_text (VI_COMMENT_BEGIN_DEFAULT); /* Default. */ rl_redisplay (); rl_newline (1, '\n'); return (0); }
//------------------------------------------------------------------------------ static void suffix_translation() { // readline's path completion may have appended a '/'. If so; flip it. char from; char* to; if (!rl_filename_completion_desired) { return; } if (g_slash_translation < 0) { return; } // Decide what direction we're going in. switch (g_slash_translation) { case 1: from = '\\'; to = "/"; break; default: from = '/'; to = "\\"; break; } // Swap the trailing slash, using Readline's API to maintain undo state. if ((rl_point > 0) && (rl_line_buffer[rl_point - 1] == from)) { rl_delete_text(rl_point - 1, rl_point); --rl_point; rl_insert_text(to); } }
static int space_callback(int count, int key) { if (!rl_point) strip_initial_spaces++; else if (suppress_space()) spaces_suppressed++; else rl_insert_text(" "); return 0; }
static int tab_callback(int count, int key) { if (!rl_point) { strip_initial_spaces += tab_width; return 0; } int i; for (i = line_start(rl_point); i < rl_point; i++) { if (rl_line_buffer[i] != ' ') { // do tab completion i = rl_point; rl_complete_internal('!'); if (i < rl_point && rl_line_buffer[rl_point-1] == ' ') { rl_delete_text(rl_point-1, rl_point); rl_point = rl_point-1; } return 0; } } // indent to next tab stop if (suppress_space()) { spaces_suppressed += tab_width; } else { i = line_start(rl_point) + prompt_length; do { rl_insert_text(" "); } while ((rl_point - i) % tab_width); } return 0; }
//------------------------------------------------------------------------------ static int paste_from_clipboard(int count, int invoking_key) { if (OpenClipboard(NULL) != FALSE) { HANDLE clip_data = GetClipboardData(CF_UNICODETEXT); if (clip_data != NULL) { wchar_t* from_clipboard = (wchar_t*)clip_data; char utf8[1024]; WideCharToMultiByte( CP_UTF8, 0, from_clipboard, -1, utf8, sizeof(utf8), NULL, NULL ); utf8[sizeof(utf8) - 1] = '\0'; rl_insert_text(utf8); } CloseClipboard(); } return 0; }
static int _cmd_complete(int all) { char **argv = NULL; int argc = 0; int rc = 1; char *line = malloc(strlen(rl_line_buffer) + 2); if (!line) return -1; strcpy(line, rl_line_buffer); line[rl_point] = 2; /* empty character, will force a word */ line[rl_point+1] = 0; if (tokenize_line(line, &argc, &argv) != 0) goto end; char *compl = commands_complete(root, argc, (const char **)argv, all); if (compl && strlen(argv[argc-1]) < strlen(compl)) { if (rl_insert_text(compl + strlen(argv[argc-1])) < 0) { free(compl); goto end; } free(compl); rc = 0; goto end; } /* No completion or several completion available. */ fprintf(stderr, "\n"); rl_forced_update_display(); rc = 0; end: free(line); tokenize_free(argc, argv); return rc; }
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 */ }
static void cli_handler_fn(char *input) { _shl_free_ char *original = input; _shl_strv_free_ char **args = NULL; int r; if (!input) { rl_insert_text("quit"); rl_redisplay(); rl_crlf(); sd_event_exit(cli_event, 0); return; } r = shl_qstr_tokenize(input, &args); if (r < 0) return cli_vENOMEM(); else if (!r) return; add_history(original); r = cli_do(cli_cmds, args, r); if (r != -EAGAIN) return; cli_printf("Command not found\n"); }
static void _rl_vi_stuff_insert(int count) { rl_begin_undo_group(); while (count--) rl_insert_text(vi_insert_buffer); rl_end_undo_group(); }
static PyObject * insert_text(PyObject *self, PyObject *args) { char *s; if (!PyArg_ParseTuple(args, "s:insert_text", &s)) return NULL; rl_insert_text(s); Py_RETURN_NONE; }
static int set_deftext () { if (deftext) { rl_insert_text (deftext); deftext = (char *)NULL; rl_startup_hook = (Function *)NULL; } }
static PyObject * insert_text(PyObject *self, PyObject *args) { char *s; if (!PyArg_ParseTuple(args, "s:insert_text", &s)) return NULL; rl_insert_text(s); Py_INCREF(Py_None); return Py_None; }
static int set_deftext (void) { if (pre_input_deftext && rl_startup_hook) { rl_insert_text (pre_input_deftext); g_free (pre_input_deftext); pre_input_deftext = NULL; rl_startup_hook = NULL; } return 0; }
int nmc_rl_set_deftext (void) { if (nmc_rl_pre_input_deftext && rl_startup_hook) { rl_insert_text (nmc_rl_pre_input_deftext); g_free (nmc_rl_pre_input_deftext); nmc_rl_pre_input_deftext = NULL; rl_startup_hook = NULL; } return 0; }
static int set_deftext () { if (deftext) { rl_insert_text (deftext); deftext = (char *)NULL; rl_startup_hook = (rl_hook_func_t *)NULL; } return 0; }
static PyObject * insert_text(PyObject *self, PyObject *string) { PyObject *encoded = encode(string); if (encoded == NULL) { return NULL; } rl_insert_text(PyBytes_AS_STRING(encoded)); Py_DECREF(encoded); Py_RETURN_NONE; }
int rl_vi_change_to(int count, int key) { int c, start_pos; if (_rl_uppercase_p (key)) rl_stuff_char ('$'); else if (vi_redoing) rl_stuff_char (_rl_vi_last_motion); start_pos = rl_point; if (rl_vi_domove (key, &c)) { rl_ding (); return -1; } /* These are the motion commands that do not require adjusting the mark. c[wW] are handled by special-case code in rl_vi_domove(), and already leave the mark at the correct location. */ if ((strchr (" l|hwW^0bB", c) == 0) && (rl_mark < rl_end)) rl_mark++; /* The cursor never moves with c[wW]. */ if ((_rl_to_upper (c) == 'W') && rl_point < start_pos) rl_point = start_pos; if (vi_redoing) { if (vi_insert_buffer && *vi_insert_buffer) rl_begin_undo_group (); rl_delete_text (rl_point, rl_mark); if (vi_insert_buffer && *vi_insert_buffer) { rl_insert_text (vi_insert_buffer); rl_end_undo_group (); } } else { rl_begin_undo_group (); /* to make the `u' command work */ rl_kill_text (rl_point, rl_mark); /* `C' does not save the text inserted for undoing or redoing. */ if (_rl_uppercase_p (key) == 0) _rl_vi_doing_insert = 1; _rl_vi_set_last (key, count, rl_arg_sign); rl_vi_insertion_mode (1, key); } return (0); }
//------------------------------------------------------------------------------ static int getc_impl(FILE* stream) { int i; while (1) { wchar_t wc[2]; char utf8[4]; i = _getwch(); if (i == 0) { i = 0xe0; } // treat esc like cmd.exe does - clear the line. if (i == 0x1b) { rl_delete_text(0, rl_end); rl_point = 0; display(); continue; } if (i < 0x7f || i == 0xe0) { break; } // Convert to utf-8 and insert directly into rl's line buffer. wc[0] = (wchar_t)i; wc[1] = L'\0'; WideCharToMultiByte( CP_UTF8, 0, wc, -1, utf8, sizeof(utf8), NULL, NULL ); rl_insert_text(utf8); display(); } // Set the "meta" key bit if the ALT key is pressed. if (GetAsyncKeyState(VK_MENU) & 0x8000) { i |= 0x80; } return i; }
//------------------------------------------------------------------------------ int getc_impl(FILE* stream) { int printable; int alt; int i; while (1) { wchar_t wc[2]; char utf8[4]; alt = 0; i = GETWCH_IMPL(&alt); // MSB is set if value represents a printable character. printable = (i & 0x80000000); i &= ~printable; // Treat esc like cmd.exe does - clear the line. if (i == 0x1b) { if (rl_editing_mode == emacs_mode && get_clink_setting_int("esc_clears_line")) { using_history(); rl_delete_text(0, rl_end); rl_point = 0; rl_redisplay(); continue; } } // Mask off top bits, they're used to track ALT key state. if (i < 0x80 || (i == 0xe0 && !printable)) { break; } // Convert to utf-8 and insert directly into rl's line buffer. wc[0] = (wchar_t)i; wc[1] = L'\0'; WideCharToMultiByte(CP_UTF8, 0, wc, -1, utf8, sizeof(utf8), NULL, NULL); rl_insert_text(utf8); rl_redisplay(); } alt = RL_ISSTATE(RL_STATE_MOREINPUT) ? 0 : alt; alt = alt ? 0x80 : 0; return i|alt; }
int my_bind_cr(int count, int key) { struct slre_cap caps[4]; if (my_eoq == 1 || slre_match("(\\\\G|;)\\s*$", rl_line_buffer, strlen(rl_line_buffer), caps, 4, SLRE_IGNORE_CASE) > 0){ rl_done = 1; return 1; } else if( slre_match("^(\\\\q|exit)$", rl_line_buffer, strlen(rl_line_buffer), caps, 4, 0) > 0) { rl_done = 1;exit_flag=1; return 1; } if (strcmp( rl_line_buffer , "") == 0 || slre_match("^\\s+$", rl_line_buffer, strlen(rl_line_buffer), caps, 4, 0) > 0) { printf("\n"); rl_on_new_line(); }else{ rl_insert_text(" \n"); } return 1; }
static VALUE readline_buffer_ext(VALUE self, VALUE str){ rb_secure(4); StringValue(str); if(rl_line_buffer == NULL) return Qnil; #ifdef HAVE_RL_DELETE_TEXT rl_delete_text(0, rl_end); #else rl_line_buffer[rl_end = 0] = '\0'; #endif rl_insert_text(RSTRING_PTR(str)); rl_redisplay(); return rb_str_new(rl_line_buffer, strlen(rl_line_buffer)); }
static int _rl_vi_change_mbchar_case(int count) { wchar_t wc; char mb[MB_LEN_MAX + 1]; int mb_len; mbstate_t ps; memset(&ps, 0, sizeof(mbstate_t)); if (_rl_adjust_point(rl_line_buffer, rl_point, &ps) > 0) count--; while (count-- && (rl_point < rl_end)) { mbrtowc(&wc, (rl_line_buffer + rl_point), (size_t)(rl_end - rl_point), &ps); if (iswupper(wc)) wc = towlower(wc); else if (iswlower(wc)) wc = towupper(wc); else { /* Just skip over chars neither upper nor lower case */ rl_forward_char(1, 0); continue; } /* Vi is kind of strange here. */ if (wc) { mb_len = wctomb(mb, wc); if (mb_len >= 0) mb[mb_len] = '\0'; rl_begin_undo_group(); rl_delete(1, 0); rl_insert_text(mb); rl_end_undo_group(); rl_vi_check(); } else rl_forward_char(1, 0); } return 0; }
static SeedValue seed_rl_insert(SeedContext ctx, SeedObject function, SeedObject this_object, size_t argument_count, const SeedValue arguments[], SeedValue * exception) { gchar *ins; gint ret; CHECK_ARG_COUNT("readline.insert", 1); ins = seed_value_to_string (ctx, arguments[0], exception); ret = rl_insert_text (ins); g_free (ins); return seed_value_from_int (ctx, ret, exception); }
int change_prompt(void) { /* toggle the prompt variable */ prompt = !prompt; /* save away the current contents of the line */ strcpy(line_buf, rl_line_buffer); /* install a new handler which will change the prompt and erase the current line */ rl_callback_handler_install(get_prompt(), process_line); /* insert the old text on the new line */ rl_insert_text(line_buf); /* redraw the current line - this is an undocumented function. It invokes the * redraw-current-line command. */ rl_refresh_line(0, 0); }
static int complete(lua_State *L) { const char* line; char* out = NULL; line = lua_tostring(L, 1); rl_insert_text(line); lua_pop(L, 1); rl_complete(0, 0); if(rl_outstream == NULL) return 0; if (!lua_istable(L, -1)) { out = rl_copy_text(0, rl_end); /* Nothing found */ if (out[0] == '\0') lua_pushfstring(L, line); else lua_pushfstring(L, out); free(out); } rl_delete_text(0, rl_end); rl_point = 0; return 1; }
static int input_help(int arg, int key UNUSED) { int i, in_string, in_bracket; if (arg != 1) return rl_insert(arg, '?'); in_string = in_bracket = 0; for (i = 0; i < rl_point; i++) { if (rl_line_buffer[i] == '"') in_string = ! in_string; else if (! in_string) { if (rl_line_buffer[i] == '[') in_bracket++; else if (rl_line_buffer[i] == ']') in_bracket--; } } /* `?' inside string or path -> insert */ if (in_string || in_bracket) return rl_insert(1, '?'); rl_begin_undo_group(); /* HACK: We want to display `?' at point position */ rl_insert_text("?"); rl_redisplay(); rl_end_undo_group(); input_start_list(); cmd_help(rl_line_buffer, rl_point); rl_undo_command(1, 0); input_stop_list(); return 0; }
//------------------------------------------------------------------------------ static int completion_shim(int count, int invoking_key) { int ret; // rl_complete checks if it was called previously. if (rl_last_func == completion_shim) { rl_last_func = rl_complete; } rl_begin_undo_group(); ret = rl_complete(count, invoking_key); // readline's path completion may have appended a '/'. If so; flip it. if ((rl_point > 0) && (rl_line_buffer[rl_point - 1] == '/')) { rl_delete_text(rl_point - 1, rl_point); --rl_point; rl_insert_text("\\"); } rl_end_undo_group(); return ret; }
static int input_complete(int arg UNUSED, int key UNUSED) { static int complete_flag; char buf[256]; if (rl_last_func != input_complete) complete_flag = 0; switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag)) { case 0: complete_flag = 1; break; case 1: rl_insert_text(buf); break; default: complete_flag = 1; #ifdef HAVE_RL_DING rl_ding(); #endif } return 0; }
void octave_rl_insert_text (const char *s) { rl_insert_text (s); }