Module: RbReadline
- Included in:
- Readline
- Defined in:
- lib/rbreadline.rb
Constant Summary collapse
- RL_LIBRARY_VERSION =
"5.2"
- RL_READLINE_VERSION =
0x0502
- RB_READLINE_VERSION =
"0.2.0.1"
- EOF =
"\xFF"
- ESC =
"\C-["
- PAGE =
"\C-L"
- SPACE =
"\x20"
- RETURN =
"\C-M"
- ABORT_CHAR =
"\C-G"
- TAB =
"\t"
- RUBOUT =
"x7f"
- NEWLINE =
"\n"
- DEFAULT_BUFFER_SIZE =
256
- DEFAULT_MAX_KILLS =
10
- MB_FIND_NONZERO =
1
- MB_FIND_ANY =
0
- MB_LEN_MAX =
4
- DEFAULT_INPUTRC =
"~/.inputrc"
- SYS_INPUTRC =
"/etc/inputrc"
- UpCase =
1
- DownCase =
2
- CapCase =
3
- EVENT_NOT_FOUND =
Possible history errors passed to hist_error.
0
- BAD_WORD_SPEC =
1
- SUBST_FAILED =
2
- BAD_MODIFIER =
3
- NO_PREV_SUBST =
4
- ANCHORED_SEARCH =
Possible definitions for history starting point specification.
1
- NON_ANCHORED_SEARCH =
0
- HISTORY_APPEND =
Possible definitions for what style of writing the history file we want.
0
- HISTORY_OVERWRITE =
1
- READERR =
Input error; can be returned by (*rl_getc_function) if readline is reading
a top-level command (RL_ISSTATE (RL_STATE_READCMD)).
0xFE.chr
- RL_PROMPT_START_IGNORE =
Definitions available for use by readline clients.
1.chr
- RL_PROMPT_END_IGNORE =
2.chr
- NO_MATCH =
Possible values for do_replace argument to rl_filename_quoting_function,
called by rl_complete_internal.
0
- SINGLE_MATCH =
1
- MULT_MATCH =
2
- NUM_SAWMINUS =
Callback data for reading numeric arguments
0x01
- NUM_SAWDIGITS =
0x02
- NUM_READONE =
0x04
- KSEQ_DISPATCHED =
A context for reading key sequences longer than a single character when
using the callback interface.
0x01
- KSEQ_SUBSEQ =
0x02
- KSEQ_RECURSIVE =
0x04
- RL_STATE_NONE =
Possible state values for rl_readline_state
0x000000
- RL_STATE_INITIALIZING =
no state before first call
0x000001
- RL_STATE_INITIALIZED =
initializing
0x000002
- RL_STATE_TERMPREPPED =
initialization done
0x000004
- RL_STATE_READCMD =
terminal is prepped
0x000008
- RL_STATE_METANEXT =
reading a command key
0x000010
- RL_STATE_DISPATCHING =
reading input after ESC
0x000020
- RL_STATE_MOREINPUT =
dispatching to a command
0x000040
- RL_STATE_ISEARCH =
reading more input in a command function
0x000080
- RL_STATE_NSEARCH =
doing incremental search
0x000100
- RL_STATE_SEARCH =
doing non-inc search
0x000200
- RL_STATE_NUMERICARG =
doing a history search
0x000400
- RL_STATE_MACROINPUT =
reading numeric argument
0x000800
- RL_STATE_MACRODEF =
getting input from a macro
0x001000
- RL_STATE_OVERWRITE =
defining keyboard macro
0x002000
- RL_STATE_COMPLETING =
overwrite mode
0x004000
- RL_STATE_SIGHANDLER =
doing completion
0x008000
- RL_STATE_UNDOING =
in readline sighandler
0x010000
- RL_STATE_INPUTPENDING =
doing an undo
0x020000
- RL_STATE_TTYCSAVED =
rl_execute_next called
0x040000
- RL_STATE_CALLBACK =
tty special chars saved
0x080000
- RL_STATE_VIMOTION =
using the callback interface
0x100000
- RL_STATE_MULTIKEY =
reading vi motion arg
0x200000
- RL_STATE_VICMDONCE =
reading multiple-key command
0x400000
- RL_STATE_DONE =
entered vi command mode at least once
0x800000
- NO_BELL =
done accepted line
0
- AUDIBLE_BELL =
1
- VISIBLE_BELL =
2
- FTO =
Definitions used when searching the line for characters. NOTE: it is necessary that opposite directions are inverses
1
- BTO =
forward to
-1 # backward to
- FFIND =
backward to
2
- BFIND =
forward find
-2 # backward find
- RL_QF_SINGLE_QUOTE =
Possible values for the found_quote flags word used by the completion
functions. It says what kind of (shell-like) quoting we found anywhere in the line.
0x01
- RL_QF_DOUBLE_QUOTE =
0x02
- RL_QF_BACKSLASH =
0x04
- RL_QF_OTHER_QUOTE =
0x08
- KEYMAP_SIZE =
257
- ANYOTHERKEY =
KEYMAP_SIZE-1
- RL_IM_INSERT =
1
- RL_IM_OVERWRITE =
0
- RL_IM_DEFAULT =
RL_IM_INSERT
- ISFUNC =
0
- ISKMAP =
1
- ISMACR =
2
- HISTORY_WORD_DELIMITERS =
" \t\n;&()|<>"
- HISTORY_QUOTE_CHARACTERS =
"\"'`"
- RL_SEARCH_ISEARCH =
incremental search
0x01
- RL_SEARCH_NSEARCH =
non-incremental search
0x02
- RL_SEARCH_CSEARCH =
intra-line char search
0x04
- SF_REVERSE =
search flags
0x01
- SF_FOUND =
0x02
- SF_FAILED =
0x04
- XOK =
1
Instance Attribute Summary collapse
-
#history_base ⇒ Object
writeonly
Sets the attribute history_base.
-
#history_length ⇒ Object
writeonly
Sets the attribute history_length.
Class Method Summary collapse
-
.__rl_fix_point(x) ⇒ Object
Fix up point so that it is within the line boundaries after killing text.
-
._rl_abort_internal ⇒ Object
How to abort things.
-
._rl_adjust_point(string, point) ⇒ Object
adjust pointed byte and find mbstate of the point of string.
- ._rl_any_typein ⇒ Object
-
._rl_arg_dispatch(cxt, c) ⇒ Object
Process C as part of the current numeric argument.
- ._rl_arg_getchar ⇒ Object
- ._rl_arg_init ⇒ Object
- ._rl_arg_overflow ⇒ Object
-
._rl_backspace(count) ⇒ Object
Move the cursor back.
- ._rl_bind_tty_special_chars(kmap) ⇒ Object
- ._rl_char_search(count, fdir, bdir) ⇒ Object
- ._rl_char_search_internal(count, dir, smbchar, len) ⇒ Object
- ._rl_char_value(buf, ind) ⇒ Object
- ._rl_clean_up_for_exit ⇒ Object
- ._rl_clear_screen ⇒ Object
-
._rl_clear_to_eol(count) ⇒ Object
Clear to the end of the line.
- ._rl_col_width(string, start, _end) ⇒ Object
-
._rl_compare_chars(buf1, pos1, buf2, pos2) ⇒ Object
compare the specified two characters.
- ._rl_control_keypad(on) ⇒ Object
-
._rl_copy_to_kill_ring(text, append) ⇒ Object
Add TEXT to the kill ring, allocating a new kill ring slot as necessary.
-
._rl_current_display_line ⇒ Object
return the ‘current display line’ of the cursor – the number of lines to move up to get to the first screen line of the current readline line.
-
._rl_dispatch(key, map) ⇒ Object
Do the command associated with KEY in MAP.
- ._rl_dispatch_subseq(key, map, got_subseq) ⇒ Object
- ._rl_enable_meta_key ⇒ Object
-
._rl_erase_at_end_of_line(l) ⇒ Object
Quick redisplay hack when erasing characters at the end of the line.
- ._rl_erase_entire_line ⇒ Object
- ._rl_find_completion_word ⇒ Object
-
._rl_find_next_mbchar(string, seed, count, flags) ⇒ Object
Find next ‘count’ characters started byte point of the specified seed.
-
._rl_find_prev_mbchar(string, seed, flags) ⇒ Object
Find previous character started byte point of the specified seed.
- ._rl_fix_point(fix_mark_too) ⇒ Object
-
._rl_get_char_len(src) ⇒ Object
return the number of bytes parsed from the multibyte sequence starting at src, if a non-L’0‘ wide character was recognized.
-
._rl_get_screen_size(tty, ignore_env) ⇒ Object
Get readline’s idea of the screen size.
- ._rl_history_set_point ⇒ Object
- ._rl_init_eightbit ⇒ Object
- ._rl_init_line_state ⇒ Object
- ._rl_init_terminal_io(terminal_name) ⇒ Object
-
._rl_insert_char(count, c) ⇒ Object
Insert the character C at the current location, moving point forward.
-
._rl_insert_next(count) ⇒ Object
Insert the next typed character verbatim.
- ._rl_insert_typein(c) ⇒ Object
- ._rl_internal_char_cleanup ⇒ Object
- ._rl_internal_pager(lines) ⇒ Object
- ._rl_is_mbchar_matched(string, seed, _end, mbchar, length) ⇒ Object
- ._rl_isearch_cleanup(cxt, r) ⇒ Object
-
._rl_isearch_dispatch(cxt, c) ⇒ Object
Process just-read character C according to isearch context CXT.
- ._rl_isearch_fini(cxt) ⇒ Object
- ._rl_isearch_init(direction) ⇒ Object
- ._rl_make_prompt_for_search(pchar) ⇒ Object
-
._rl_move_cursor_relative(new, data, start = 0) ⇒ Object
Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
-
._rl_move_vert(to) ⇒ Object
PWP: move the cursor up or down.
- ._rl_nsearch_abort(cxt) ⇒ Object
- ._rl_nsearch_cleanup(cxt, r) ⇒ Object
-
._rl_nsearch_dispatch(cxt, c) ⇒ Object
Process just-read character C according to search context CXT.
-
._rl_nsearch_dosearch(cxt) ⇒ Object
Perform one search according to CXT, using NONINC_SEARCH_STRING.
- ._rl_nsearch_init(dir, pchar) ⇒ Object
-
._rl_output_some_chars(string, start, count) ⇒ Object
Write COUNT characters from STRING to the output stream.
-
._rl_overwrite_char(count, c) ⇒ Object
Overwrite the character at point (or next COUNT characters) with C.
-
._rl_overwrite_rubout(count, key) ⇒ Object
This is different from what vi does, so the code’s not shared.
- ._rl_read_init_file(filename, include_level) ⇒ Object
-
._rl_read_mbchar(mbchar, size) ⇒ Object
read multibyte char.
-
._rl_read_mbstring(first, mb, mlen) ⇒ Object
Read a multibyte-character string whose first character is FIRST into the buffer MB of length MLEN.
-
._rl_redisplay_after_sigwinch ⇒ Object
Redisplay the current line after a SIGWINCH is received.
-
._rl_replace_text(text, start, _end) ⇒ Object
Replace the contents of the line buffer between START and END with TEXT.
-
._rl_reset_argument ⇒ Object
Create a default argument.
- ._rl_rubout_char(count, key) ⇒ Object
- ._rl_scxt_alloc(type, flags) ⇒ Object
- ._rl_search_getchar(cxt) ⇒ Object
-
._rl_set_insert_mode(im, force) ⇒ Object
Function for the rest of the library to use to set insert/overwrite mode.
-
._rl_set_mark_at_pos(position) ⇒ Object
Set the mark at POSITION.
-
._rl_start_using_history ⇒ Object
Set the history pointer back to the last entry in the history.
- ._rl_strip_prompt(pmt) ⇒ Object
- ._rl_subseq_getchar(key) ⇒ Object
- ._rl_to_lower(char) ⇒ Object
-
._rl_unget_char(key) ⇒ Object
Stuff KEY into the front of the input buffer.
- ._rl_update_final ⇒ Object
- ._rl_vi_done_inserting ⇒ Object
- ._rl_vi_initialize_line ⇒ Object
- ._rl_vi_reset_last ⇒ Object
- ._rl_vi_save_insert(up) ⇒ Object
-
._rl_vi_textmod_command(c) ⇒ Object
Is the command C a VI mode text modification command?.
- ._rl_walphabetic(c) ⇒ Object
-
.add_history(string) ⇒ Object
Place STRING at the end of the history list.
- .alloc_history_entry(string, ts) ⇒ Object
- .alloc_undo_entry(what, start, _end, text) ⇒ Object
-
.append_to_match(text, delimiter, quote_char, nontrivial_match) ⇒ Object
Append any necessary closing quote and a separator character to the just-inserted match.
-
.bind_arrow_keys ⇒ Object
Try and bind the common arrow key prefixes after giving termcap and the inputrc file a chance to bind them and create ‘real’ keymaps for the arrow key prefix.
-
.bind_arrow_keys_internal(map) ⇒ Object
Bind some common arrow key sequences in MAP.
-
.bind_termcap_arrow_keys(map) ⇒ Object
Bind the arrow key sequences from the termcap description in MAP.
- .block_sigint ⇒ Object
- .clear_history ⇒ Object
-
.compute_lcd_of_matches(match_list, matches, text) ⇒ Object
Find the common prefix of the list of matches, and put it into matches.
-
.cr ⇒ Object
Move to the start of the current line.
- .cr_faster(new, cur) ⇒ Object
- .ctrl_char(c) ⇒ Object
-
.current_history ⇒ Object
Return the history entry at the current position, as determined by history_offset.
-
.delete_chars(count) ⇒ Object
Delete COUNT characters from the display line.
-
.display_matches(matches) ⇒ Object
Display MATCHES, a list of matching filenames in argv format.
- .endsrch_char(c) ⇒ Object
-
.expand_prompt(pmt) ⇒ Object
Current implementation: 001 (^A) start non-visible characters 002 (^B) end non-visible characters all characters except 001 and 002 (following a 001) are copied to the returned string all characters except those between 001 and 002 are assumed to be ‘visible’.
- .fnprint(to_print) ⇒ Object
-
.fnwidth(string) ⇒ Object
Compute width of STRING when displayed on screen by print_filename.
- .gen_completion_matches(text, start, _end, our_func, found_quote, quote_char) ⇒ Object
- .get_term_capabilities(buffer) ⇒ Object
-
.get_y_or_n(for_pager) ⇒ Object
The user must press “y” or “n”.
-
.handle_parser_directive(statement) ⇒ Object
Handle a parser directive.
- .hist_inittime ⇒ Object
-
.history_base ⇒ Object
Returns the value of attribute history_base.
-
.history_get(offset) ⇒ Object
Return the history entry which is logically at OFFSET in the history array.
- .history_is_stifled ⇒ Object
-
.history_length ⇒ Object
Returns the value of attribute history_length.
- .history_list ⇒ Object
-
.history_search_pos(string, dir, pos) ⇒ Object
Search for STRING in the history list.
-
.history_search_prefix(string, direction) ⇒ Object
Do an anchored search for string through the history in DIRECTION.
-
.history_set_pos(pos) ⇒ Object
Make the current history item be the one at POS, an absolute index.
-
.ibuffer_space ⇒ Object
Return the amount of space available in the buffer for stuffing characters.
-
.init_line_structures(minsize) ⇒ Object
Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated arrays of line break markers.
- .insert_all_matches(matches, point, qc) ⇒ Object
- .insert_match(match, start, mtype, qc) ⇒ Object
-
.insert_some_chars(string, count, col) ⇒ Object
Insert COUNT characters from STRING to the output stream at column COL.
- .inv_line(line) ⇒ Object
- .inv_llen(l) ⇒ Object
- .isascii(c) ⇒ Object
- .isprint(c) ⇒ Object
- .m_offset(margin, offset) ⇒ Object
-
.make_history_line_current(entry) ⇒ Object
Make the data from the history entry ENTRY be the contents of the current line.
- .make_quoted_replacement(match, mtype, qc) ⇒ Object
- .meta_char(c) ⇒ Object
-
.next_history ⇒ Object
Move history_offset forward to the next history entry, and return a pointer to that entry.
- .no_terminal? ⇒ Boolean
-
.noninc_dosearch(string, dir) ⇒ Object
Search for a line in the history containing STRING.
-
.noninc_search(dir, pchar) ⇒ Object
Search non-interactively through the history list.
-
.noninc_search_from_pos(string, pos, dir) ⇒ Object
Search the history list for STRING starting at absolute history position POS.
-
.parser_else(args) ⇒ Object
Invert the current parser state if there is anything on the stack.
-
.parser_endif(args) ⇒ Object
Terminate a conditional, popping the value of _rl_parsing_conditionalized_out from the stack.
-
.parser_if(args) ⇒ Object
Push _rl_parsing_conditionalized_out, and set parser state based on ARGS.
- .parser_include(args) ⇒ Object
- .path_isdir(filename) ⇒ Object
- .postprocess_matches(matchesp, matching_filenames) ⇒ Object
- .prepare_terminal_settings(meta_flag) ⇒ Object
-
.previous_history ⇒ Object
Back up history_offset to the previous history entry, and return a pointer to that entry.
-
.print_filename(to_print, full_pathname) ⇒ Object
Output TO_PRINT to rl_outstream.
-
.printable_part(pathname) ⇒ Object
Return the portion of PATHNAME that should be output when listing possible completions.
-
.prompt_ending_index ⇒ Object
-
_rl_last_c_pos is an absolute cursor position in multibyte locales and a buffer index in others.
-
-
.readline(prompt) ⇒ Object
Read a line of input.
-
.readline_default_bindings ⇒ Object
If this system allows us to look at the values of the regular input editing characters, then bind them to their readline equivalents, iff the characters are not bound to keymaps.
-
.readline_initialize_everything ⇒ Object
Initialize the entire state of the world.
-
.readline_internal ⇒ Object
Read a line of input from the global rl_instream, doing output on the global rl_outstream.
- .readline_internal_charloop ⇒ Object
- .readline_internal_setup ⇒ Object
- .readline_internal_teardown(eof) ⇒ Object
-
.redraw_prompt(t) ⇒ Object
Redraw the last line of a multi-line prompt that may possibly contain terminal escape sequences.
- .release_sigint ⇒ Object
-
.remove_duplicate_matches(matches) ⇒ Object
Filter out duplicates in MATCHES.
-
.remove_history(which) ⇒ Object
Remove history element WHICH from the history.
-
.replace_history_data(which, old, new) ⇒ Object
Replace the DATA in the specified history entries, replacing OLD with NEW.
-
.replace_history_entry(which, line, data) ⇒ Object
Make the history entry at WHICH have LINE and DATA.
- .rl_abort(count, key) ⇒ Object
-
.rl_add_undo(what, start, _end, text) ⇒ Object
-
Remember how to undo something.
-
- .rl_alphabetic(c) ⇒ Object
- .rl_arrow_keys(count, c) ⇒ Object
-
.rl_attempted_completion_function ⇒ Object
Returns the value of attribute rl_attempted_completion_function.
-
.rl_attempted_completion_function=(value) ⇒ Object
Sets the attribute rl_attempted_completion_function.
-
.rl_attempted_completion_over ⇒ Object
Returns the value of attribute rl_attempted_completion_over.
-
.rl_attempted_completion_over=(value) ⇒ Object
Sets the attribute rl_attempted_completion_over.
-
.rl_backward(count, key) ⇒ Object
Backwards compatibility.
-
.rl_backward_byte(count, key) ⇒ Object
Move backward COUNT bytes.
-
.rl_backward_char(count, key) ⇒ Object
Move backward COUNT characters.
- .rl_backward_char_search(count, key) ⇒ Object
-
.rl_backward_kill_line(direction, ignore) ⇒ Object
Kill backwards to the start of the line.
-
.rl_backward_kill_word(count, ignore) ⇒ Object
Rubout the word before point, placing it on the kill ring.
-
.rl_backward_word(count, key) ⇒ Object
Move backward a word.
-
.rl_basic_quote_characters ⇒ Object
Returns the value of attribute rl_basic_quote_characters.
-
.rl_basic_quote_characters=(value) ⇒ Object
Sets the attribute rl_basic_quote_characters.
-
.rl_basic_word_break_characters ⇒ Object
Returns the value of attribute rl_basic_word_break_characters.
-
.rl_basic_word_break_characters=(value) ⇒ Object
Sets the attribute rl_basic_word_break_characters.
-
.rl_beg_of_line(count, key) ⇒ Object
Move to the beginning of the line.
-
.rl_begin_undo_group ⇒ Object
Begin a group.
-
.rl_beginning_of_history(count, key) ⇒ Object
Meta-< goes to the start of the history.
-
.rl_bind_key(key, function) ⇒ Object
Bind KEY to FUNCTION.
- .rl_bind_keyseq_if_unbound(keyseq, default_func) ⇒ Object
-
.rl_bind_keyseq_if_unbound_in_map(keyseq, default_func, kmap) ⇒ Object
Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound.
-
.rl_bind_keyseq_in_map(keyseq, function, map) ⇒ Object
Bind the key sequence represented by the string KEYSEQ to FUNCTION.
-
.rl_capitalize_word(count, key) ⇒ Object
Upcase the first letter, downcase the rest.
-
.rl_change_case(count, op) ⇒ Object
The meaty function.
- .rl_char_search(count, key) ⇒ Object
- .rl_character_len(c, pos) ⇒ Object
-
.rl_cleanup_after_signal ⇒ Object
Clean up the terminal and readline state after catching a signal, before resending it to the calling application.
-
.rl_clear_message ⇒ Object
How to clear things from the “echo-area”.
-
.rl_clear_pending_input ⇒ Object
Clear any pending input pushed with rl_execute_next().
-
.rl_clear_screen(count, key) ⇒ Object
C-l typed to a line without quoting clears the screen, and then reprints the prompt and the current input line.
- .rl_clear_signals ⇒ Object
-
.rl_complete(ignore, invoking_key) ⇒ Object
Complete the word at or before point.
-
.rl_complete_internal(what_to_do) ⇒ Object
Complete the word at or before point.
-
.rl_completer_quote_characters ⇒ Object
Returns the value of attribute rl_completer_quote_characters.
-
.rl_completer_quote_characters=(value) ⇒ Object
Sets the attribute rl_completer_quote_characters.
-
.rl_completer_word_break_characters ⇒ Object
Returns the value of attribute rl_completer_word_break_characters.
-
.rl_completer_word_break_characters=(value) ⇒ Object
Sets the attribute rl_completer_word_break_characters.
-
.rl_completion_append_character ⇒ Object
Returns the value of attribute rl_completion_append_character.
-
.rl_completion_append_character=(value) ⇒ Object
Sets the attribute rl_completion_append_character.
-
.rl_completion_matches(text, entry_function) ⇒ Object
Return an array of (char *) which is a list of completions for TEXT.
- .rl_copy_text(from, to) ⇒ Object
-
.rl_crlf ⇒ Object
Move to the start of the next line.
-
.rl_delete(count, key) ⇒ Object
Delete the character under the cursor.
-
.rl_delete_horizontal_space(count, ignore) ⇒ Object
Delete all spaces and tabs around point.
-
.rl_delete_or_show_completions(count, key) ⇒ Object
Like the tcsh editing function delete-char-or-list.
-
.rl_delete_text(from, to) ⇒ Object
Delete the string between FROM and TO.
-
.rl_deprep_term_function ⇒ Object
Returns the value of attribute rl_deprep_term_function.
-
.rl_deprep_term_function=(value) ⇒ Object
Sets the attribute rl_deprep_term_function.
-
.rl_deprep_terminal ⇒ Object
Restore the terminal’s normal settings and modes.
-
.rl_digit_argument(ignore, key) ⇒ Object
Start a numeric argument with initial value KEY.
-
.rl_digit_loop ⇒ Object
Handle C-u style numeric args, as well as M–, and M-digits.
-
.rl_ding ⇒ Object
Ring the terminal bell.
-
.rl_display_match_list(matches, len, max) ⇒ Object
A convenience function for displaying a list of strings in columnar format on readline’s output stream.
-
.rl_display_search(search_string, reverse_p, where) ⇒ Object
Display the current state of the search in the echo-area.
-
.rl_do_lowercase_version(ignore1, ignore2) ⇒ Object
What to do for some uppercase characters, like meta characters, and some characters appearing in emacs_ctlx_keymap.
- .rl_do_undo ⇒ Object
-
.rl_downcase_word(count, key) ⇒ Object
Lowercase the word at point.
- .rl_emacs_editing_mode(count, key) ⇒ Object
-
.rl_end_of_history(count, key) ⇒ Object
Meta-> goes to the end of the history.
-
.rl_end_of_line(count, key) ⇒ Object
Move to the end of the line.
-
.rl_end_undo_group ⇒ Object
End an undo group started with rl_begin_undo_group ().
-
.rl_event_hook ⇒ Object
Returns the value of attribute rl_event_hook.
-
.rl_event_hook=(value) ⇒ Object
Sets the attribute rl_event_hook.
-
.rl_exchange_point_and_mark(count, key) ⇒ Object
Exchange the position of mark and point.
-
.rl_execute_next(c) ⇒ Object
Make C be the next command to be executed.
-
.rl_expand_prompt(prompt) ⇒ Object
-
Expand the prompt string into the various display components, if * necessary.
-
-
.rl_extend_line_buffer(len) ⇒ Object
Increase the size of RL_LINE_BUFFER until it has enough space to hold LEN characters.
-
.rl_filename_completion_function(text, state) ⇒ Object
Okay, now we write the entry_function for filename completion.
-
.rl_filename_quote_characters ⇒ Object
Returns the value of attribute rl_filename_quote_characters.
-
.rl_filename_quote_characters=(value) ⇒ Object
Sets the attribute rl_filename_quote_characters.
-
.rl_forced_update_display ⇒ Object
Actually update the display, period.
-
.rl_forward(count, key) ⇒ Object
Backwards compatibility.
-
.rl_forward_byte(count, key) ⇒ Object
Move forward COUNT bytes.
-
.rl_forward_char(count, key) ⇒ Object
Move forward COUNT characters.
-
.rl_forward_search_history(sign, key) ⇒ Object
Search forwards through the history looking for a string which is typed interactively.
-
.rl_forward_word(count, key) ⇒ Object
Move forward a word.
- .rl_free_undo_list ⇒ Object
-
.rl_function_of_keyseq(keyseq, map, type) ⇒ Object
Return the function (or macro) definition which would be invoked via KEYSEQ if executed in MAP.
-
.rl_generic_bind(type, keyseq, data, map) ⇒ Object
Bind the key sequence represented by the string KEYSEQ to the arbitrary pointer DATA.
-
.rl_get_char ⇒ Object
Get a key from the buffer of characters to be read.
- .rl_get_keymap_name_from_edit_mode ⇒ Object
-
.rl_get_next_history(count, key) ⇒ Object
Move down to the next history line.
-
.rl_get_previous_history(count, key) ⇒ Object
Get the previous item out of our interactive history, making it the current line.
-
.rl_initialize ⇒ Object
Initialize readline (and terminal if not already).
- .rl_insert(count, c) ⇒ Object
-
.rl_insert_comment(count, key) ⇒ Object
Turn the current line into a comment in shell history.
- .rl_insert_completions(ignore, invoking_key) ⇒ Object
-
.rl_insert_text(string) ⇒ Object
Insert a string of text into the line at point.
-
.rl_instream ⇒ Object
Returns the value of attribute rl_instream.
-
.rl_instream=(value) ⇒ Object
Sets the attribute rl_instream.
- .rl_isstate(x) ⇒ Object
-
.rl_kill_full_line(count, ignore) ⇒ Object
Kill the whole line, no matter where point is.
-
.rl_kill_line(direction, ignore) ⇒ Object
Kill from here to the end of the line.
-
.rl_kill_text(from, to) ⇒ Object
The way to kill something.
-
.rl_kill_word(count, key) ⇒ Object
Delete the word at point, saving the text in the kill ring.
-
.rl_library_version ⇒ Object
Returns the value of attribute rl_library_version.
-
.rl_library_version=(value) ⇒ Object
Sets the attribute rl_library_version.
-
.rl_maybe_replace_line ⇒ Object
Perhaps put back the current line if it has changed.
-
.rl_maybe_save_line ⇒ Object
Save the current line in _rl_saved_line_for_history.
-
.rl_maybe_unsave_line ⇒ Object
Restore the _rl_saved_line_for_history if there is one.
- .rl_message(msg_buf) ⇒ Object
-
.rl_modifying(start, _end) ⇒ Object
Save an undo entry for the text from START to END.
- .rl_named_function(name) ⇒ Object
-
.rl_newline(count, key) ⇒ Object
What to do when a NEWLINE is pressed.
-
.rl_noninc_forward_search(count, key) ⇒ Object
Search forward through the history list for a string.
-
.rl_noninc_reverse_search(count, key) ⇒ Object
Reverse search the history list for a string.
-
.rl_on_new_line ⇒ Object
Tell the update routines that we have moved onto a new (empty) line.
-
.rl_on_new_line_with_prompt ⇒ Object
Tell the update routines that we have moved onto a new line with the prompt already displayed.
-
.rl_outstream ⇒ Object
Returns the value of attribute rl_outstream.
-
.rl_outstream=(value) ⇒ Object
Sets the attribute rl_outstream.
-
.rl_overwrite_mode(count, key) ⇒ Object
Toggle overwrite mode.
-
.rl_parse_and_bind(string) ⇒ Object
Read the binding command from STRING and perform it.
-
.rl_possible_completions(ignore, invoking_key) ⇒ Object
List the possible completions.
- .rl_prep_terminal(meta_flag) ⇒ Object
- .rl_quoted_insert(count, key) ⇒ Object
-
.rl_re_read_init_file(count, ignore) ⇒ Object
Re-read the current keybindings file.
-
.rl_read_init_file(filename) ⇒ Object
Do key bindings from a file.
-
.rl_read_key ⇒ Object
Read a key, including pending input.
-
.rl_readline_name ⇒ Object
Returns the value of attribute rl_readline_name.
-
.rl_readline_name=(value) ⇒ Object
Sets the attribute rl_readline_name.
-
.rl_redisplay ⇒ Object
Basic redisplay algorithm.
-
.rl_refresh_line(ignore1, ignore2) ⇒ Object
Clear the current line.
- .rl_replace_from_history(entry, flags) ⇒ Object
-
.rl_replace_line(text, clear_undo) ⇒ Object
Replace the current line buffer contents with TEXT.
- .rl_reset_line_state ⇒ Object
- .rl_resize_terminal ⇒ Object
- .rl_restart_output(count, key) ⇒ Object
- .rl_restore_prompt ⇒ Object
-
.rl_reverse_search_history(sign, key) ⇒ Object
Search backwards through the history looking for a string which is typed interactively.
-
.rl_revert_line(count, key) ⇒ Object
Revert the current line to its previous state.
-
.rl_rubout(count, key) ⇒ Object
Rubout the character behind point.
-
.rl_rubout_or_delete(count, key) ⇒ Object
Delete the character under the cursor, unless the insertion point is at the end of the line, in which case the character behind the cursor is deleted.
- .rl_save_prompt ⇒ Object
-
.rl_search_history(direction, invoking_key) ⇒ Object
Search through the history looking for an interactively typed string.
- .rl_set_keymap_from_edit_mode ⇒ Object
-
.rl_set_mark(count, key) ⇒ Object
A bindable command to set the mark.
-
.rl_set_prompt(prompt) ⇒ Object
Set up the prompt and expand it.
- .rl_set_signals ⇒ Object
- .rl_setstate(x) ⇒ Object
- .rl_sigwinch_handler(sig) ⇒ Object
-
.rl_stuff_char(key) ⇒ Object
Add KEY to the buffer of characters to be read.
-
.rl_tab_insert(count, key) ⇒ Object
Insert a tab character.
-
.rl_tilde_expand(ignore, key) ⇒ Object
A function for simple tilde expansion.
-
.rl_transpose_chars(count, key) ⇒ Object
Transpose the characters at point.
-
.rl_transpose_words(count, key) ⇒ Object
Transpose the words at point.
-
.rl_tty_set_default_bindings(kmap) ⇒ Object
New public way to set the system default editing chars to their readline equivalents.
-
.rl_tty_unset_default_bindings(kmap) ⇒ Object
Rebind all of the tty special chars that readline worries about back to self-insert.
-
.rl_undo_command(count, key) ⇒ Object
Do some undoing of things that were done.
-
.rl_unix_filename_rubout(count, key) ⇒ Object
This deletes one filename component in a Unix pathname.
-
.rl_unix_line_discard(count, key) ⇒ Object
Here is C-u doing what Unix does.
-
.rl_unix_word_rubout(count, key) ⇒ Object
This does what C-w does in Unix.
- .rl_unsetstate(x) ⇒ Object
-
.rl_upcase_word(count, key) ⇒ Object
Uppercase the word at point.
-
.rl_username_completion_function(text, state) ⇒ Object
A completion function for usernames.
- .rl_variable_bind(name, value) ⇒ Object
- .rl_vi_check ⇒ Object
- .rl_vi_editing_mode(count, key) ⇒ Object
-
.rl_vi_insertion_mode(count, key) ⇒ Object
Switching from one mode to the other really just involves switching keymaps.
-
.rl_yank(count, ignore) ⇒ Object
Yank back the last killed text.
- .rl_yank_last_arg(count, key) ⇒ Object
-
.rl_yank_nth_arg(count, ignore) ⇒ Object
Yank the COUNTth argument from the previous history line.
-
.rl_yank_nth_arg_internal(count, ignore, history_skip) ⇒ Object
Yank the COUNTh argument from the previous history line, skipping HISTORY_SKIP lines before looking for the ‘previous line’.
-
.rl_yank_pop(count, key) ⇒ Object
If the last command was yank, or yank_pop, and the text just before point is identical to the current kill item, then delete that text from the line, rotate the index down, and yank back some other text.
- .save_tty_chars ⇒ Object
-
.set_completion_defaults(what_to_do) ⇒ Object
Set default values for readline word completion.
-
.sh_set_lines_and_columns(lines, cols) ⇒ Object
Set the environment variables LINES and COLUMNS to lines and cols, respectively.
-
.space_to_eol(count) ⇒ Object
Clear to the end of the line using spaces.
-
.stat_char(filename) ⇒ Object
Return the character which best describes FILENAME.
-
.stifle_history(max) ⇒ Object
Stifle the history list, remembering only MAX number of lines.
- .tgetflag(name) ⇒ Object
-
.trans(i) ⇒ Object
Undo the next thing in the list.
-
.unstifle_history ⇒ Object
Stop stifling the history.
-
.update_line(old, ostart, new, current_line, omax, nmax, inv_botlin) ⇒ Object
PWP: update_line() is based on finding the middle difference of each line on the screen; vis:.
- .using_history ⇒ Object
- .vis_chars(line) ⇒ Object
- .vis_line(line) ⇒ Object
- .vis_llen(l) ⇒ Object
- .vis_pos(line) ⇒ Object
- .w_offset(line, offset) ⇒ Object
-
.where_history ⇒ Object
Returns the magic number which says what history element we are looking at now.
- .whitespace(c) ⇒ Object
Instance Attribute Details
#history_base=(value) ⇒ Object
Sets the attribute history_base
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def history_base=(value) @history_base = value end |
#history_length=(value) ⇒ Object
Sets the attribute history_length
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def history_length=(value) @history_length = value end |
Class Method Details
.__rl_fix_point(x) ⇒ Object
Fix up point so that it is within the line boundaries after killing
text. If FIX_MARK_TOO is non-zero, the mark is forced within line
boundaries also.
4844 4845 4846 4847 4848 4849 4850 4851 4852 |
# File 'lib/rbreadline.rb', line 4844 def __rl_fix_point(x) if (x > @rl_end) @rl_end elsif (x < 0) 0 else x end end |
._rl_abort_internal ⇒ Object
How to abort things.
4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 |
# File 'lib/rbreadline.rb', line 4649 def _rl_abort_internal() rl_ding() () _rl_reset_argument() rl_clear_pending_input() rl_unsetstate(RL_STATE_MACRODEF) @rl_last_func = nil #throw :readline_top_level send(@rl_redisplay_function) @_rl_want_redisplay = false 0 end |
._rl_adjust_point(string, point) ⇒ Object
adjust pointed byte and find mbstate of the point of string.
adjusted point will be point <= adjusted_point, and returns
differences of the byte(adjusted_point - point).
if point is invalied (point < 0 || more than string length),
it returns -1
8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 |
# File 'lib/rbreadline.rb', line 8401 def _rl_adjust_point(string, point) length = string.length return -1 if (point < 0) return -1 if (length < point) pos = 0 case @encoding when 'E' pos = string.scan(/./me).inject(0){|r,x| r<point ? r += x.length : r } when 'S' pos = string.scan(/./ms).inject(0){|r,x| r<point ? r += x.length : r } when 'U' pos = string.scan(/./mu).inject(0){|r,x| r<point ? r += x.length : r } when 'X' pos = string.dup.force_encoding(@encoding_name).chars.inject(0){|r,x| r<point ? r += x.bytesize : r } else pos = point end pos - point end |
._rl_any_typein ⇒ Object
5414 5415 5416 |
# File 'lib/rbreadline.rb', line 5414 def _rl_any_typein() return (@push_index != @pop_index) end |
._rl_arg_dispatch(cxt, c) ⇒ Object
Process C as part of the current numeric argument. Return -1 if the
argument should be aborted, 0 if we should not read any more chars, and
1 if we should continue to read chars.
7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 |
# File 'lib/rbreadline.rb', line 7596 def _rl_arg_dispatch(cxt, c) key = c # If we see a key bound to `universal-argument' after seeing digits, # it ends the argument but is otherwise ignored. if (@_rl_keymap[c] == :rl_universal_argument) if ((cxt & NUM_SAWDIGITS) == 0) @rl_numeric_arg *= 4 return 1 elsif (rl_isstate(RL_STATE_CALLBACK)) @_rl_argcxt |= NUM_READONE return 0 # XXX else rl_setstate(RL_STATE_MOREINPUT) key = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) rl_restore_prompt() () rl_unsetstate(RL_STATE_NUMERICARG) return (_rl_dispatch(key, @_rl_keymap)) end end #c = (c[0].ord & ~0x80).chr r = c[1,1] if (r>='0' && r<='9') r = r.to_i @rl_numeric_arg = @rl_explicit_arg ? (@rl_numeric_arg * 10) + r : r @rl_explicit_arg = 1 @_rl_argcxt |= NUM_SAWDIGITS elsif (c == '-' && !@rl_explicit_arg) @rl_numeric_arg = 1 @_rl_argcxt |= NUM_SAWMINUS @rl_arg_sign = -1 else # Make M-- command equivalent to M--1 command. if ((@_rl_argcxt & NUM_SAWMINUS)!=0 && @rl_numeric_arg == 1 && !@rl_explicit_arg) @rl_explicit_arg = 1 end rl_restore_prompt() () rl_unsetstate(RL_STATE_NUMERICARG) r = _rl_dispatch(key, @_rl_keymap) if (rl_isstate(RL_STATE_CALLBACK)) # At worst, this will cause an extra redisplay. Otherwise, # we have to wait until the next character comes in. if (!@rl_done) send(@rl_redisplay_function) end r = 0 end return r end 1 end |
._rl_arg_getchar ⇒ Object
7585 7586 7587 7588 7589 7590 7591 |
# File 'lib/rbreadline.rb', line 7585 def _rl_arg_getchar() ("(arg: #{@rl_arg_sign * @rl_numeric_arg}) ") rl_setstate(RL_STATE_MOREINPUT) c = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) c end |
._rl_arg_init ⇒ Object
7579 7580 7581 7582 7583 |
# File 'lib/rbreadline.rb', line 7579 def _rl_arg_init() rl_save_prompt() @_rl_argcxt = 0 rl_setstate(RL_STATE_NUMERICARG) end |
._rl_arg_overflow ⇒ Object
7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 |
# File 'lib/rbreadline.rb', line 7653 def _rl_arg_overflow() if (@rl_numeric_arg > 1000000) @_rl_argcxt = 0 @rl_explicit_arg = @rl_numeric_arg = 0 rl_ding() rl_restore_prompt() () rl_unsetstate(RL_STATE_NUMERICARG) return 1 end 0 end |
._rl_backspace(count) ⇒ Object
Move the cursor back.
4534 4535 4536 4537 4538 4539 4540 4541 |
# File 'lib/rbreadline.rb', line 4534 def _rl_backspace(count) if (@_rl_term_backspace) @_rl_out_stream.write(@_rl_term_backspace * count) else @_rl_out_stream.write("\b"*count) end 0 end |
._rl_bind_tty_special_chars(kmap) ⇒ Object
6827 6828 6829 6830 6831 6832 |
# File 'lib/rbreadline.rb', line 6827 def _rl_bind_tty_special_chars(kmap) kmap[@_rl_tty_chars.t_erase] = :rl_rubout kmap[@_rl_tty_chars.t_kill] = :rl_unix_line_discard kmap[@_rl_tty_chars.t_werase] = :rl_unix_word_rubout kmap[@_rl_tty_chars.t_lnext] = :rl_quoted_insert end |
._rl_char_search(count, fdir, bdir) ⇒ Object
7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 |
# File 'lib/rbreadline.rb', line 7430 def _rl_char_search(count, fdir, bdir) mbchar = '' mb_len = _rl_read_mbchar(mbchar, MB_LEN_MAX) if (count < 0) return (_rl_char_search_internal(-count, bdir, mbchar, mb_len)) else return (_rl_char_search_internal(count, fdir, mbchar, mb_len)) end end |
._rl_char_search_internal(count, dir, smbchar, len) ⇒ Object
7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 |
# File 'lib/rbreadline.rb', line 7403 def _rl_char_search_internal(count, dir, smbchar, len) pos = @rl_point inc = (dir < 0) ? -1 : 1 while (count!=0) if ((dir < 0 && pos <= 0) || (dir > 0 && pos >= @rl_end)) rl_ding() return -1 end pos = (inc > 0) ? _rl_find_next_mbchar(@rl_line_buffer, pos, 1, MB_FIND_ANY) : _rl_find_prev_mbchar(@rl_line_buffer, pos, MB_FIND_ANY) begin if (_rl_is_mbchar_matched(@rl_line_buffer, pos, @rl_end, smbchar, len)!=0) count-=1 if (dir < 0) @rl_point = (dir == BTO) ? pos+1 : pos else @rl_point = (dir == FTO) ? pos-1 : pos end break end prepos = pos end while ((dir < 0) ? (pos = _rl_find_prev_mbchar(@rl_line_buffer, pos, MB_FIND_ANY)) != prepos : (pos = _rl_find_next_mbchar(@rl_line_buffer, pos, 1, MB_FIND_ANY)) != prepos) end 0 end |
._rl_char_value(buf, ind) ⇒ Object
5056 5057 5058 |
# File 'lib/rbreadline.rb', line 5056 def _rl_char_value(buf,ind) buf[ind,1] end |
._rl_clean_up_for_exit ⇒ Object
1500 1501 1502 1503 1504 1505 1506 1507 |
# File 'lib/rbreadline.rb', line 1500 def _rl_clean_up_for_exit() if @readline_echoing_p _rl_move_vert(@_rl_vis_botlin) @_rl_vis_botlin = 0 @rl_outstream.flush rl_restart_output(1, 0) end end |
._rl_clear_screen ⇒ Object
4525 4526 4527 4528 4529 4530 4531 |
# File 'lib/rbreadline.rb', line 4525 def _rl_clear_screen() if (@_rl_term_clrpag) @rl_outstream.write(@_rl_tirberm_clrpag) else rl_crlf() end end |
._rl_clear_to_eol(count) ⇒ Object
Clear to the end of the line. COUNT is the minimum
number of character spaces to clear,
4502 4503 4504 4505 4506 4507 4508 |
# File 'lib/rbreadline.rb', line 4502 def _rl_clear_to_eol(count) if (@_rl_term_clreol) @rl_outstream.write(@_rl_term_clreol) elsif (count!=0) space_to_eol(count) end end |
._rl_col_width(string, start, _end) ⇒ Object
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 |
# File 'lib/rbreadline.rb', line 3764 def _rl_col_width(string,start,_end) return 0 if _end <= start index = string.index(0.chr) str = index ? string[0,index] : string width = 0 case @encoding when 'N' return (_end - start) when 'U' str[start ... _end].scan(/./mu).each {|s| width += s.unpack('U').first >= 0x1000 ? 2 : 1 } when 'S' str[start ... _end].scan(/./ms).each {|s| width += s.length } when 'E' str[start ... _end].scan(/./me).each {|s| width += s.length } when 'X' str[start ... _end].force_encoding(@encoding_name).codepoints.each {|s| width += s > 0x1000 ? 2 : 1 } end width end |
._rl_compare_chars(buf1, pos1, buf2, pos2) ⇒ Object
compare the specified two characters. If the characters matched,
return true. Otherwise return false.
8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 |
# File 'lib/rbreadline.rb', line 8486 def _rl_compare_chars(buf1, pos1, buf2, pos2) return false if buf1[pos1].nil? || buf2[pos2].nil? case @encoding when 'E' buf1[pos1..-1].scan(/./me)[0] == buf2[pos2..-1].scan(/./me)[0] when 'S' buf1[pos1..-1].scan(/./ms)[0] == buf2[pos2..-1].scan(/./ms)[0] when 'U' buf1[pos1..-1].scan(/./mu)[0] == buf2[pos2..-1].scan(/./mu)[0] when 'X' buf1[pos1..-1].force_encoding(@encoding_name)[0] == buf2[pos2..-1].force_encoding(@encoding_name)[0] else buf1[pos1] == buf2[pos2] end end |
._rl_control_keypad(on) ⇒ Object
6858 6859 6860 6861 6862 6863 6864 |
# File 'lib/rbreadline.rb', line 6858 def _rl_control_keypad(on) if on && @_rl_term_ks @_rl_out_stream.write(@_rl_term_ks) elsif !on && @_rl_term_ke @_rl_out_stream.write(@_rl_term_ke) end end |
._rl_copy_to_kill_ring(text, append) ⇒ Object
Add TEXT to the kill ring, allocating a new kill ring slot as necessary.
This uses TEXT directly, so the caller must not free it. If APPEND is
non-zero, and the last command was a kill, the text is appended to the
current kill ring slot, otherwise prepended.
5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 |
# File 'lib/rbreadline.rb', line 5784 def _rl_copy_to_kill_ring(text, append) # First, find the slot to work with. if (!@_rl_last_command_was_kill) # Get a new slot. if @rl_kill_ring.nil? # If we don't have any defined, then make one. @rl_kill_ring_length = 1 @rl_kill_ring = Array.new(@rl_kill_ring_length+1) @rl_kill_ring[slot = 0] = nil else # We have to add a new slot on the end, unless we have # exceeded the max limit for remembering kills. slot = @rl_kill_ring_length if (slot == @rl_max_kills) @rl_kill_ring[0,slot] = @rl_kill_ring[1,slot] else slot = @rl_kill_ring_length += 1 end @rl_kill_ring[slot-=1] = nil end else slot = @rl_kill_ring_length - 1 end # If the last command was a kill, prepend or append. if (@_rl_last_command_was_kill && @rl_editing_mode != @vi_mode) old = @rl_kill_ring[slot] if (append) new = old + text else new = text + old end old = nil text = nil @rl_kill_ring[slot] = new else @rl_kill_ring[slot] = text end @rl_kill_index = slot 0 end |
._rl_current_display_line ⇒ Object
return the ‘current display line’ of the cursor – the number of lines to
move up to get to the first screen line of the current readline line.
5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 |
# File 'lib/rbreadline.rb', line 5170 def _rl_current_display_line() # Find out whether or not there might be invisible characters in the # editing buffer. if (@rl_display_prompt == @rl_prompt) nleft = @_rl_last_c_pos - @_rl_screenwidth - @rl_visible_prompt_length else nleft = @_rl_last_c_pos - @_rl_screenwidth end if (nleft > 0) ret = 1 + nleft / @_rl_screenwidth else ret = 0 end ret end |
._rl_dispatch(key, map) ⇒ Object
Do the command associated with KEY in MAP.
If the associated command is really a keymap, then read
another key, and dispatch into that map.
4219 4220 4221 4222 |
# File 'lib/rbreadline.rb', line 4219 def _rl_dispatch(key, map) @_rl_dispatching_keymap = map return _rl_dispatch_subseq(key, map, false) end |
._rl_dispatch_subseq(key, map, got_subseq) ⇒ Object
4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 |
# File 'lib/rbreadline.rb', line 4225 def _rl_dispatch_subseq(key, map, got_subseq) func = map[key] if (func) @rl_executing_keymap = map @rl_dispatching = true rl_setstate(RL_STATE_DISPATCHING) send(map[key],@rl_numeric_arg * @rl_arg_sign, key) rl_unsetstate(RL_STATE_DISPATCHING) @rl_dispatching = false if (@rl_pending_input == 0 && map[key] != :rl_digit_argument) @rl_last_func = map[key] end else if(map.keys.detect{|x| x =~ /^#{Regexp.escape(key)}/}) key += _rl_subseq_getchar(key) return _rl_dispatch_subseq(key,map,got_subseq) elsif(key.length>1 && key[1] < ?\x7F) _rl_abort_internal() return -1 else @rl_dispatching = true rl_setstate(RL_STATE_DISPATCHING) send(:rl_insert,@rl_numeric_arg * @rl_arg_sign, key) rl_unsetstate(RL_STATE_DISPATCHING) @rl_dispatching = false end end 0 end |
._rl_enable_meta_key ⇒ Object
2405 2406 2407 2408 2409 |
# File 'lib/rbreadline.rb', line 2405 def () if(@term_has_meta && @_rl_term_mm) @_rl_out_stream.write(@_rl_term_mm) end end |
._rl_erase_at_end_of_line(l) ⇒ Object
Quick redisplay hack when erasing characters at the end of the line.
5712 5713 5714 5715 5716 5717 5718 5719 |
# File 'lib/rbreadline.rb', line 5712 def _rl_erase_at_end_of_line(l) _rl_backspace(l) @rl_outstream.write(' '*l) _rl_backspace(l) @_rl_last_c_pos -= l @visible_line[@_rl_last_c_pos,l] = 0.chr * l @rl_display_fixed = true if !@rl_display_fixed end |
._rl_erase_entire_line ⇒ Object
4560 4561 4562 4563 4564 4565 |
# File 'lib/rbreadline.rb', line 4560 def _rl_erase_entire_line() cr() _rl_clear_to_eol(0) cr() @rl_outstream.flush end |
._rl_find_completion_word ⇒ Object
6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 |
# File 'lib/rbreadline.rb', line 6040 def _rl_find_completion_word() _end = @rl_point found_quote = 0 delimiter = 0.chr quote_char = 0.chr brkchars = nil if @rl_completion_word_break_hook brkchars = send(@rl_completion_word_break_hook) end if brkchars.nil? brkchars = @rl_completer_word_break_characters end if (@rl_completer_quote_characters) # We have a list of characters which can be used in pairs to # quote substrings for the completer. Try to find the start # of an unclosed quoted substring. # FOUND_QUOTE is set so we know what kind of quotes we found. scan = 0 pass_next = false while scan < _end if (pass_next) pass_next = false next end # Shell-like semantics for single quotes -- don't allow backslash # to quote anything in single quotes, especially not the closing # quote. If you don't like this, take out the check on the value # of quote_char. if (quote_char != "'" && @rl_line_buffer[scan] == ?\\) pass_next = true found_quote |= RL_QF_BACKSLASH next end if (quote_char != 0.chr) # Ignore everything until the matching close quote char. if (@rl_line_buffer[scan,1] == quote_char) # Found matching close. Abandon this substring. quote_char = 0.chr @rl_point = _end end elsif (@rl_completer_quote_characters.include?(@rl_line_buffer[scan,1])) # Found start of a quoted substring. quote_char = @rl_line_buffer[scan,1] @rl_point = scan + 1 # Shell-like quoting conventions. if (quote_char == "'") found_quote |= RL_QF_SINGLE_QUOTE elsif (quote_char == '"') found_quote |= RL_QF_DOUBLE_QUOTE else found_quote |= RL_QF_OTHER_QUOTE end end if !@rl_byte_oriented scan = _rl_find_next_mbchar(@rl_line_buffer, scan, 1, MB_FIND_ANY) else scan += 1 end end end if (@rl_point == _end && quote_char == 0.chr) # We didn't find an unclosed quoted substring upon which to do # completion, so use the word break characters to find the # substring on which to complete. while (@rl_point = !@rl_byte_oriented ? _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_ANY):(@rl_point-1))>0 scan = @rl_line_buffer[@rl_point,1] if !brkchars.include?(scan) next end # Call the application-specific function to tell us whether # this word break character is quoted and should be skipped. if (@rl_char_is_quoted_p && found_quote!=0 && send(@rl_char_is_quoted_p,@rl_line_buffer, @rl_point)) next end # Convoluted code, but it avoids an n^2 algorithm with calls # to char_is_quoted. break end end # If we are at an unquoted word break, then advance past it. scan = @rl_line_buffer[@rl_point,1] # If there is an application-specific function to say whether or not # a character is quoted and we found a quote character, let that # function decide whether or not a character is a word break, even # if it is found in rl_completer_word_break_characters. Don't bother # if we're at the end of the line, though. if (scan != 0.chr) if (@rl_char_is_quoted_p) isbrk = (found_quote == 0 || !send(@rl_char_is_quoted_p,@rl_line_buffer, @rl_point)) && brkchars.include?(scan) else isbrk = brkchars.include?(scan) end if (isbrk) # If the character that caused the word break was a quoting # character, then remember it as the delimiter. if (@rl_basic_quote_characters && @rl_basic_quote_characters.include?(scan) && (_end - @rl_point) > 1) delimiter = scan end # If the character isn't needed to determine something special # about what kind of completion to perform, then advance past it. if (@rl_special_prefixes.nil? || !@rl_special_prefixes.include?(scan) ) @rl_point+=1 end end end return [quote_char,found_quote!=0,delimiter] end |
._rl_find_next_mbchar(string, seed, count, flags) ⇒ Object
Find next ‘count’ characters started byte point of the specified seed.
If flags is MB_FIND_NONZERO, we look for non-zero-width multibyte
characters.
8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 |
# File 'lib/rbreadline.rb', line 8427 def _rl_find_next_mbchar(string, seed, count, flags) if @encoding == 'N' return (seed + count) end seed = 0 if seed < 0 return seed if count <= 0 point = seed + _rl_adjust_point(string,seed) if (seed < point) count -= 1 end case @encoding when 'E' point += string[point..-1].scan(/./me)[0,count].to_s.length when 'S' point += string[point..-1].scan(/./ms)[0,count].to_s.length when 'U' point += string[point..-1].scan(/./mu)[0,count].to_s.length when 'X' point += string[point..-1].force_encoding(@encoding_name)[0,count].bytesize else point += count end if flags == MB_FIND_NONZERO point = string.length if point>=string.length end point end |
._rl_find_prev_mbchar(string, seed, flags) ⇒ Object
Find previous character started byte point of the specified seed.
Returned point will be point <= seed. If flags is MB_FIND_NONZERO,
we look for non-zero-width multibyte characters.
8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 |
# File 'lib/rbreadline.rb', line 8460 def _rl_find_prev_mbchar(string, seed, flags) if @encoding == 'N' return ((seed == 0) ? seed : seed - 1) end length = string.length if seed < 0 return 0 elsif length < seed return length end case @encoding when 'E' string[0,seed].scan(/./me)[0..-2].to_s.length when 'S' string[0,seed].scan(/./ms)[0..-2].to_s.length when 'U' string[0,seed].scan(/./mu)[0..-2].to_s.length when 'X' string[0,seed].force_encoding(@encoding_name)[0..-2].bytesize end end |
._rl_fix_point(fix_mark_too) ⇒ Object
4854 4855 4856 4857 4858 4859 |
# File 'lib/rbreadline.rb', line 4854 def _rl_fix_point(fix_mark_too) @rl_point = __rl_fix_point(@rl_point) if (fix_mark_too) @rl_mark = __rl_fix_point(@rl_mark) end end |
._rl_get_char_len(src) ⇒ Object
return the number of bytes parsed from the multibyte sequence starting at src, if a non-L’0‘ wide character was recognized. It returns 0, if a L’0‘ wide character was recognized. It returns (size_t)(-1), if an invalid multibyte sequence was encountered. It returns (size_t)(-2) if it couldn’t parse a complete multibyte character.
8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 |
# File 'lib/rbreadline.rb', line 8507 def _rl_get_char_len(src) return 0 if src[0] == ?\0 || src.length==0 case @encoding when 'E' len = src.scan(/./me)[0].to_s.length when 'S' len = src.scan(/./ms)[0].to_s.length when 'U' len = src.scan(/./mu)[0].to_s.length when 'X' src = src.dup.force_encoding(@encoding_name) len = src.valid_encoding? ? src[0].bytesize : 0 else len = 1 end len==0 ? -2 : len end |
._rl_get_screen_size(tty, ignore_env) ⇒ Object
Get readline’s idea of the screen size. TTY is a file descriptor open
to the terminal. If IGNORE_ENV is true, we do not pay attention to the
values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being
non-null serve to check whether or not we have initialized termcap.
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 |
# File 'lib/rbreadline.rb', line 1840 def _rl_get_screen_size(tty, ignore_env) if @hConsoleHandle csbi = 0.chr * 24 @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi) wc,wr = csbi[0,4].unpack('SS') # wr,wc, = `mode con`.scan(/\d+\n/).map{|x| x.to_i} @_rl_screenwidth = wc @_rl_screenheight = wr else wr,wc = `stty size`.split(' ').map{|x| x.to_i} @_rl_screenwidth = wc @_rl_screenheight = wr if ignore_env==0 && ENV['LINES'] @_rl_screenheight = ENV['LINES'].to_i end if ignore_env==0 && ENV['COLUMNS'] @_rl_screenwidth = ENV['COLUMNS'].to_i end end # If all else fails, default to 80x24 terminal. if @_rl_screenwidth.nil? || @_rl_screenwidth <= 1 @_rl_screenwidth = 80 end if @_rl_screenheight.nil? || @_rl_screenheight <= 0 @_rl_screenheight = 24 end # If we're being compiled as part of bash, set the environment # variables $LINES and $COLUMNS to new values. Otherwise, just # do a pair of putenv () or setenv () calls. sh_set_lines_and_columns(@_rl_screenheight, @_rl_screenwidth) if !@_rl_term_autowrap @_rl_screenwidth-=1 end @_rl_screenchars = @_rl_screenwidth * @_rl_screenheight end |
._rl_history_set_point ⇒ Object
5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 |
# File 'lib/rbreadline.rb', line 5348 def _rl_history_set_point () @rl_point = (@_rl_history_preserve_point && @_rl_history_saved_point != -1) ? @_rl_history_saved_point : @rl_end if (@rl_point > @rl_end) @rl_point = @rl_end end if (@rl_editing_mode == @vi_mode && @_rl_keymap != @vi_insertion_keymap) @rl_point = 0 end if (@rl_editing_mode == @emacs_mode) @rl_mark = (@rl_point == @rl_end ? 0 : @rl_end) end end |
._rl_init_eightbit ⇒ Object
2060 2061 2062 |
# File 'lib/rbreadline.rb', line 2060 def _rl_init_eightbit() end |
._rl_init_line_state ⇒ Object
2525 2526 2527 2528 |
# File 'lib/rbreadline.rb', line 2525 def _rl_init_line_state() @rl_point = @rl_end = @rl_mark = 0 @rl_line_buffer = 0.chr * @rl_line_buffer.length end |
._rl_init_terminal_io(terminal_name) ⇒ Object
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 |
# File 'lib/rbreadline.rb', line 1949 def _rl_init_terminal_io(terminal_name) term = terminal_name ? terminal_name : ENV["TERM"] @_rl_term_clrpag = @_rl_term_cr = @_rl_term_clreol = nil tty = @rl_instream ? @rl_instream.fileno : 0 if no_terminal? term = "dumb" @_rl_bind_stty_chars = false end @term_string_buffer ||= 0.chr * 2032 @term_buffer ||= 0.chr * 4080 buffer = @term_string_buffer tgetent_ret = (term != "dumb") ? 1 : -1 if (tgetent_ret <= 0) buffer = @term_buffer = @term_string_buffer = nil @_rl_term_autowrap = false # used by _rl_get_screen_size # Allow calling application to set default height and width, using #rl_set_screen_size if (@_rl_screenwidth <= 0 || @_rl_screenheight <= 0) _rl_get_screen_size(tty, 0) end # Defaults. if (@_rl_screenwidth <= 0 || @_rl_screenheight <= 0) @_rl_screenwidth = 79 @_rl_screenheight = 24 end # Everything below here is used by the redisplay code (tputs). @_rl_screenchars = @_rl_screenwidth * @_rl_screenheight @_rl_term_cr = "\r" @_rl_term_im = @_rl_term_ei = @_rl_term_ic = @_rl_term_IC = nil @_rl_term_up = @_rl_term_dc = @_rl_term_DC = @_rl_visible_bell = nil @_rl_term_ku = @_rl_term_kd = @_rl_term_kl = @_rl_term_kr = nil @_rl_term_kh = @_rl_term_kH = @_rl_term_kI = @_rl_term_kD = nil @_rl_term_ks = @_rl_term_ke = @_rl_term_at7 = nil @_rl_term_mm = @_rl_term_mo = nil @_rl_term_ve = @_rl_term_vs = nil @_rl_term_forward_char = nil @_rl_terminal_can_insert = @term_has_meta = false # Reasonable defaults for tgoto(). Readline currently only uses # tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we # change that later... @_rl_term_backspace = "\b" return 0 end get_term_capabilities(buffer) @_rl_term_cr ||= "\r" @_rl_term_autowrap = !!(tgetflag("am") && tgetflag("xn")) # Allow calling application to set default height and width, using # rl_set_screen_size if (@_rl_screenwidth <= 0 || @_rl_screenheight <= 0) _rl_get_screen_size(tty, 0) end # "An application program can assume that the terminal can do # character insertion if *any one of* the capabilities `IC', # `im', `ic' or `ip' is provided." But we can't do anything if # only `ip' is provided, so... @_rl_terminal_can_insert = !!(@_rl_term_IC || @_rl_term_im || @_rl_term_ic) # Check to see if this terminal has a meta key and clear the capability # variables if there is none. @term_has_meta = !!(tgetflag("km") || tgetflag("MT")) if !@term_has_meta @_rl_term_mm = @_rl_term_mo = nil end # Attempt to find and bind the arrow keys. Do not override already # bound keys in an overzealous attempt, however. bind_termcap_arrow_keys(@emacs_standard_keymap) bind_termcap_arrow_keys(@vi_movement_keymap) bind_termcap_arrow_keys(@vi_insertion_keymap) return 0 end |
._rl_insert_char(count, c) ⇒ Object
Insert the character C at the current location, moving point forward.
If C introduces a multibyte sequence, we read the whole sequence and
then insert the multibyte char into the line buffer.
5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 |
# File 'lib/rbreadline.rb', line 5434 def _rl_insert_char(count, c) return 0 if (count <= 0) incoming = '' if @rl_byte_oriented incoming << c incoming_length = 1 else @pending_bytes << c if _rl_get_char_len(@pending_bytes) == -2 return 1 else incoming = @pending_bytes @pending_bytes = '' incoming_length = incoming.length end end if(count>1) string = incoming * count rl_insert_text(string) string = nil return 0 end if @rl_byte_oriented # We are inserting a single character. #If there is pending input, then make a string of all of the #pending characters that are bound to rl_insert, and insert #them all. if (_rl_any_typein()) _rl_insert_typein(c) else rl_insert_text(c) end else rl_insert_text(incoming) end return 0 end |
._rl_insert_next(count) ⇒ Object
Insert the next typed character verbatim.
5512 5513 5514 5515 5516 5517 5518 |
# File 'lib/rbreadline.rb', line 5512 def _rl_insert_next(count) rl_setstate(RL_STATE_MOREINPUT) c = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) _rl_insert_char(count, c) end |
._rl_insert_typein(c) ⇒ Object
5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 |
# File 'lib/rbreadline.rb', line 5418 def _rl_insert_typein(c) string = c while ((key = rl_get_char()) && @_rl_keymap[key] == :rl_insert) string << key end if (key) _rl_unget_char(key) end rl_insert_text(string) end |
._rl_internal_char_cleanup ⇒ Object
4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 |
# File 'lib/rbreadline.rb', line 4567 def _rl_internal_char_cleanup() # In vi mode, when you exit insert mode, the cursor moves back # over the previous character. We explicitly check for that here. if (@rl_editing_mode == @vi_mode && @_rl_keymap == @vi_movement_keymap) rl_vi_check() end if (@rl_num_chars_to_read!=0 && @rl_end >= @rl_num_chars_to_read) send(@rl_redisplay_function) @_rl_want_redisplay = false rl_newline(1, "\n") end if (!@rl_done) send(@rl_redisplay_function) @_rl_want_redisplay = false end # If the application writer has told us to erase the entire line if # the only character typed was something bound to rl_newline, do so. if (@rl_erase_empty_line && @rl_done && @rl_last_func == :rl_newline && @rl_point == 0 && @rl_end == 0) _rl_erase_entire_line() end end |
._rl_internal_pager(lines) ⇒ Object
6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 |
# File 'lib/rbreadline.rb', line 6389 def _rl_internal_pager(lines) @rl_outstream.puts "--More--" @rl_outstream.flush i = get_y_or_n(1) _rl_erase_entire_line() if (i == 0) return -1 elsif (i == 2) return (lines - 1) else return 0 end end |
._rl_is_mbchar_matched(string, seed, _end, mbchar, length) ⇒ Object
8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 |
# File 'lib/rbreadline.rb', line 8567 def _rl_is_mbchar_matched(string, seed, _end, mbchar, length) return 0 if ((_end - seed) < length) for i in 0 ... length if (string[seed + i] != mbchar[i]) return 0 end end 1 end |
._rl_isearch_cleanup(cxt, r) ⇒ Object
4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 |
# File 'lib/rbreadline.rb', line 4204 def _rl_isearch_cleanup(cxt, r) if (r >= 0) _rl_isearch_fini(cxt) end ctx = nil @_rl_iscxt = nil rl_unsetstate(RL_STATE_ISEARCH) r != 0 end |
._rl_isearch_dispatch(cxt, c) ⇒ Object
Process just-read character C according to isearch context CXT. Return
-1 if the caller should just free the context and return, 0 if we should
break out of the loop, and 1 if we should continue to read characters.
3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 |
# File 'lib/rbreadline.rb', line 3931 def _rl_isearch_dispatch(cxt, c) f = nil # Translate the keys we do something with to opcodes. if (c && @_rl_keymap[c]) f = @_rl_keymap[c] if (f == :rl_reverse_search_history) cxt.lastc = (cxt.sflags & SF_REVERSE)!=0 ? -1 : -2 elsif (f == :rl_forward_search_history) cxt.lastc = (cxt.sflags & SF_REVERSE)!=0 ? -2 : -1 elsif (f == :rl_rubout) cxt.lastc = -3 elsif (c == "\C-G") cxt.lastc = -4 elsif (c == "\C-W") # XXX cxt.lastc = -5 elsif (c == "\C-Y") # XXX cxt.lastc = -6 end end # The characters in isearch_terminators (set from the user-settable # variable isearch-terminators) are used to terminate the search but # not subsequently execute the character as a command. The default # value is "\033\012" (ESC and C-J). if (cxt.search_terminators.include?(cxt.lastc)) # ESC still terminates the search, but if there is pending #input or if input arrives within 0.1 seconds (on systems #with select(2)) it is used as a prefix character #with rl_execute_next. WATCH OUT FOR THIS! This is intended #to allow the arrow keys to be used like ^F and ^B are used #to terminate the search and execute the movement command. #XXX - since _rl_input_available depends on the application- #settable keyboard timeout value, this could alternatively #use _rl_input_queued(100000) if (cxt.lastc == ESC && _rl_input_available()) rl_execute_next(ESC) end return (0) end if !@rl_byte_oriented if (cxt.lastc.class == String && (cxt.mb.length == 1) && endsrch_char(cxt.lastc)) # This sets rl_pending_input to c; it will be picked up the next # time rl_read_key is called. rl_execute_next(cxt.lastc) return (0) end elsif (cxt.lastc.class == String && endsrch_char(cxt.lastc)) # This sets rl_pending_input to LASTC; it will be picked up the next # time rl_read_key is called. rl_execute_next(cxt.lastc) return (0) end # Now dispatch on the character. `Opcodes' affect the search string or # state. Other characters are added to the string. case (cxt.lastc) # search again when -1 if (cxt.search_string_index == 0) if (last_isearch_string) cxt.search_string_size = 64 + last_isearch_string_len cxt.search_string = last_isearch_string.dup cxt.search_string_index = last_isearch_string_len rl_display_search(cxt.search_string, (cxt.sflags & SF_REVERSE)!=0, -1) else return (1) end elsif (cxt.sflags & SF_REVERSE)!=0 cxt.sline_index-=1 elsif (cxt.sline_index != cxt.sline_len) cxt.sline_index+=1 else rl_ding() end # switch directions when -2 cxt.direction = -cxt.direction if (cxt.direction < 0) cxt.sflags |= SF_REVERSE else cxt.sflags &= ~SF_REVERSE end # delete character from search string. when -3 # C-H, DEL # This is tricky. To do this right, we need to keep a # stack of search positions for the current search, with # sentinels marking the beginning and end. But this will # do until we have a real isearch-undo. if (cxt.search_string_index == 0) rl_ding() else cxt.search_string[cxt.search_string_index-=1] = 0.chr end when -4 # C-G, abort rl_replace_line(cxt.lines[cxt.save_line], false) @rl_point = cxt.save_point @rl_mark = cxt.save_mark rl_restore_prompt() () return -1 when -5 # C-W # skip over portion of line we already matched and yank word wstart = @rl_point + cxt.search_string_index if (wstart >= @rl_end) rl_ding() else # if not in a word, move to one. cval = _rl_char_value(@rl_line_buffer, wstart) if (!_rl_walphabetic(cval)) rl_ding() else if !@rl_byte_oriented n = _rl_find_next_mbchar(@rl_line_buffer, wstart, 1, MB_FIND_NONZERO) else n = wstart+1 end while (n < @rl_end) cval = _rl_char_value(@rl_line_buffer, n) break if !_rl_walphabetic(cval) if !@rl_byte_oriented n = _rl_find_next_mbchar(@rl_line_buffer, n, 1, MB_FIND_NONZERO) else n = n+1 end end wlen = n - wstart + 1 if (cxt.search_string_index + wlen + 1 >= cxt.search_string_size) cxt.search_string_size += wlen + 1 end cxt.search_string[cxt.search_string_index..-1] = @rl_line_buffer[wstart,wlen] cxt.search_string_index += wlen end end when -6 # C-Y # skip over portion of line we already matched and yank rest wstart = @rl_point + cxt.search_string_index if (wstart >= @rl_end) rl_ding() else n = @rl_end - wstart + 1 if (cxt.search_string_index + n + 1 >= cxt.search_string_size) cxt.search_string_size += n + 1 end cxt.search_string[cxt.search_string_index..-1] = @rl_line_buffer[wstart,n] end # Add character to search string and continue search. else if (cxt.search_string_index + 2 >= cxt.search_string_size) cxt.search_string_size += 128 end if !@rl_byte_oriented for j in 0 ... cxt.mb.length cxt.search_string << cxt.mb[j,1] cxt.search_string_index += 1 end else cxt.search_string << c cxt.search_string_index += 1 end end while (cxt.sflags &= ~(SF_FOUND|SF_FAILED))!=0 limit = cxt.sline_len - cxt.search_string_index + 1 # Search the current line. while ((cxt.sflags & SF_REVERSE)!=0 ? (cxt.sline_index >= 0) : (cxt.sline_index < limit)) if (cxt.search_string[0,cxt.search_string_index] == cxt.sline[cxt.sline_index,cxt.search_string_index]) cxt.sflags |= SF_FOUND break else cxt.sline_index += cxt.direction end end break if (cxt.sflags & SF_FOUND)!=0 # Move to the next line, but skip new copies of the line # we just found and lines shorter than the string we're # searching for. begin # Move to the next line. cxt.history_pos += cxt.direction # At limit for direction? if ((cxt.sflags & SF_REVERSE)!=0 ? (cxt.history_pos < 0) : (cxt.history_pos == cxt.hlen)) cxt.sflags |= SF_FAILED break end # We will need these later. cxt.sline = cxt.lines[cxt.history_pos] cxt.sline_len = cxt.sline.length end while ((cxt.prev_line_found && cxt.prev_line_found == cxt.lines[cxt.history_pos]) || (cxt.search_string_index > cxt.sline_len)) break if (cxt.sflags & SF_FAILED)!=0 # Now set up the line for searching... cxt.sline_index = (cxt.sflags & SF_REVERSE)!=0 ? cxt.sline_len - cxt.search_string_index : 0 end if (cxt.sflags & SF_FAILED)!=0 # We cannot find the search string. Ding the bell. rl_ding() cxt.history_pos = cxt.last_found_line return 1 end # We have found the search string. Just display it. But don't # actually move there in the history list until the user accepts # the location. if (cxt.sflags & SF_FOUND)!=0 cxt.prev_line_found = cxt.lines[cxt.history_pos] rl_replace_line(cxt.lines[cxt.history_pos], false) @rl_point = cxt.sline_index cxt.last_found_line = cxt.history_pos rl_display_search(cxt.search_string, (cxt.sflags & SF_REVERSE)!=0, (cxt.history_pos == cxt.save_line) ? -1 : cxt.history_pos) end 1 end |
._rl_isearch_fini(cxt) ⇒ Object
4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 |
# File 'lib/rbreadline.rb', line 4168 def _rl_isearch_fini(cxt) # First put back the original state. @rl_line_buffer = cxt.lines[cxt.save_line].dup rl_restore_prompt() # Save the search string for possible later use. @last_isearch_string = cxt.search_string @last_isearch_string_len = cxt.search_string_index cxt.search_string = nil if (cxt.last_found_line < cxt.save_line) rl_get_previous_history(cxt.save_line - cxt.last_found_line, 0) else rl_get_next_history(cxt.last_found_line - cxt.save_line, 0) end # If the string was not found, put point at the end of the last matching # line. If last_found_line == orig_line, we didn't find any matching # history lines at all, so put point back in its original position. if (cxt.sline_index < 0) if (cxt.last_found_line == cxt.save_line) cxt.sline_index = cxt.save_point else cxt.sline_index = @rl_line_buffer.delete(0.chr).length end @rl_mark = cxt.save_mark end @rl_point = cxt.sline_index # Don't worry about where to put the mark here; rl_get_previous_history # and rl_get_next_history take care of it. () end |
._rl_isearch_init(direction) ⇒ Object
7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 |
# File 'lib/rbreadline.rb', line 7096 def _rl_isearch_init(direction) cxt = _rl_scxt_alloc(RL_SEARCH_ISEARCH, 0) if (direction < 0) cxt.sflags |= SF_REVERSE end cxt.search_terminators = @_rl_isearch_terminators ? @_rl_isearch_terminators : @default_isearch_terminators # Create an arrary of pointers to the lines that we want to search. hlist = history_list() rl_maybe_replace_line() i = 0 if (hlist) i += 1 while(hlist[i]) end # Allocate space for this many lines, +1 for the current input line, # and remember those lines. cxt.hlen = i cxt.lines = Array.new(cxt.hlen+1) for i in 0 ... cxt.hlen cxt.lines[i] = hlist[i].line end if (@_rl_saved_line_for_history) cxt.lines[i] = @_rl_saved_line_for_history.line.dup else # Keep track of this so we can free it. cxt.allocated_line = @rl_line_buffer.dup cxt.lines[i] = cxt.allocated_line end cxt.hlen+=1 # The line where we start the search. cxt.history_pos = cxt.save_line rl_save_prompt() # Initialize search parameters. cxt.search_string_size = 128 cxt.search_string_index = 0 cxt.search_string = 0.chr * cxt.search_string_size # Normalize DIRECTION into 1 or -1. cxt.direction = (direction >= 0) ? 1 : -1 cxt.sline = @rl_line_buffer cxt.sline_len = cxt.sline.delete(0.chr).length cxt.sline_index = @rl_point @_rl_iscxt = cxt # save globally cxt end |
._rl_make_prompt_for_search(pchar) ⇒ Object
7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 |
# File 'lib/rbreadline.rb', line 7956 def _rl_make_prompt_for_search(pchar) rl_save_prompt() # We've saved the prompt, and can do anything with the various prompt # strings we need before they're restored. We want the unexpanded # portion of the prompt string after any final newline. _p = @rl_prompt ? @rl_prompt.rindex("\n") : nil if _p.nil? len = (@rl_prompt && @rl_prompt.length>0 ) ? @rl_prompt.length : 0 if (len>0) pmt = @rl_prompt.dup else pmt = '' end pmt << pchar else _p+=1 pmt = @rl_prompt[_p..-1] pmt << pchar end # will be overwritten by expand_prompt, called from rl_message @prompt_physical_chars = @saved_physical_chars + 1 pmt end |
._rl_move_cursor_relative(new, data, start = 0) ⇒ Object
Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
(Well, when we don't have multibyte characters, _rl_last_c_pos is a
buffer index.)
DATA is the contents of the screen line of interest; i.e., where
the movement is being done.
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 |
# File 'lib/rbreadline.rb', line 1514 def _rl_move_cursor_relative(new, data, start=0) woff = w_offset(@_rl_last_v_pos, @wrap_offset) cpos = @_rl_last_c_pos if !@rl_byte_oriented dpos = _rl_col_width(data, start, start+new) if (dpos > @prompt_last_invisible) # XXX - don't use woff here dpos -= woff # Since this will be assigned to _rl_last_c_pos at the end (more # precisely, _rl_last_c_pos == dpos when this function returns), # let the caller know. @cpos_adjusted = true end else dpos = new end # If we don't have to do anything, then return. if (cpos == dpos) return end if @hConsoleHandle csbi = 0.chr * 24 @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi) x,y = csbi[4,4].unpack('SS') x = dpos @SetConsoleCursorPosition.Call(@hConsoleHandle,y*65536+x) @_rl_last_c_pos = dpos return end # It may be faster to output a CR, and then move forwards instead # of moving backwards. # i == current physical cursor position. if !@rl_byte_oriented i = @_rl_last_c_pos else i = @_rl_last_c_pos - woff end if (dpos == 0 || cr_faster(dpos, @_rl_last_c_pos) || (@_rl_term_autowrap && i == @_rl_screenwidth)) @rl_outstream.write(@_rl_term_cr) cpos = @_rl_last_c_pos = 0 end if (cpos < dpos) # Move the cursor forward. We do it by printing the command # to move the cursor forward if there is one, else print that # portion of the output buffer again. Which is cheaper? # The above comment is left here for posterity. It is faster # to print one character (non-control) than to print a control # sequence telling the terminal to move forward one character. # That kind of control is for people who don't know what the # data is underneath the cursor. # However, we need a handle on where the current display position is # in the buffer for the immediately preceding comment to be true. # In multibyte locales, we don't currently have that info available. # Without it, we don't know where the data we have to display begins # in the buffer and we have to go back to the beginning of the screen # line. In this case, we can use the terminal sequence to move forward # if it's available. if !@rl_byte_oriented if (@_rl_term_forward_char) @rl_outstream.write(@_rl_term_forward_char * (dpos-cpos)) else @rl_outstream.write(@_rl_term_cr) @rl_outstream.write(data[start,new]) end else @rl_outstream.write(data[start+cpos,new-cpos]) end elsif (cpos > dpos) _rl_backspace(cpos - dpos) end @_rl_last_c_pos = dpos end |
._rl_move_vert(to) ⇒ Object
PWP: move the cursor up or down.
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 |
# File 'lib/rbreadline.rb', line 1598 def _rl_move_vert(to) if (@_rl_last_v_pos == to || to > @_rl_screenheight) return end if ((delta = to - @_rl_last_v_pos) > 0) @rl_outstream.write("\n"*delta) @rl_outstream.write("\r") @_rl_last_c_pos = 0 else if(@_rl_term_up) @rl_outstream.write(@_rl_term_up*(-delta)) end end @_rl_last_v_pos = to # Now TO is here end |
._rl_nsearch_abort(cxt) ⇒ Object
8015 8016 8017 8018 8019 8020 8021 8022 |
# File 'lib/rbreadline.rb', line 8015 def _rl_nsearch_abort(cxt) rl_maybe_unsave_line() () @rl_point = cxt.save_point @rl_mark = cxt.save_mark rl_restore_prompt() rl_unsetstate(RL_STATE_NSEARCH) end |
._rl_nsearch_cleanup(cxt, r) ⇒ Object
8008 8009 8010 8011 8012 8013 |
# File 'lib/rbreadline.rb', line 8008 def _rl_nsearch_cleanup(cxt, r) cxt = nil @_rl_nscxt = nil rl_unsetstate(RL_STATE_NSEARCH) r != 1 end |
._rl_nsearch_dispatch(cxt, c) ⇒ Object
Process just-read character C according to search context CXT. Return -1
if the caller should abort the search, 0 if we should break out of the
loop, and 1 if we should continue to read characters.
8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 |
# File 'lib/rbreadline.rb', line 8027 def _rl_nsearch_dispatch(cxt, c) case (c) when "\C-W" rl_unix_word_rubout(1, c) when "\C-W" rl_unix_line_discard(1, c) when RETURN,NEWLINE return 0 when "\C-H",RUBOUT if (@rl_point == 0) _rl_nsearch_abort(cxt) return -1 end _rl_rubout_char(1, c) when "\C-C","\C-G" rl_ding() _rl_nsearch_abort(cxt) return -1 else if !@rl_byte_oriented rl_insert_text(cxt.mb) else _rl_insert_char(1, c) end end send(@rl_redisplay_function) 1 end |
._rl_nsearch_dosearch(cxt) ⇒ Object
Perform one search according to CXT, using NONINC_SEARCH_STRING. Return
-1 if the search should be aborted, any other value means to clean up
using _rl_nsearch_cleanup (). Returns 1 if the search was successful,
0 otherwise.
8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 |
# File 'lib/rbreadline.rb', line 8061 def _rl_nsearch_dosearch(cxt) @rl_mark = cxt.save_mark # If rl_point == 0, we want to re-use the previous search string and # start from the saved history position. If there's no previous search # string, punt. if (@rl_point == 0) if @noninc_search_string.nil? rl_ding() rl_restore_prompt() rl_unsetstate(RL_STATE_NSEARCH) return -1 end else # We want to start the search from the current history position. @noninc_history_pos = cxt.save_line @noninc_search_string = @rl_line_buffer.dup # If we don't want the subsequent undo list generated by the search #matching a history line to include the contents of the search string, #we need to clear rl_line_buffer here. For now, we just clear the #undo list generated by reading the search string. (If the search #fails, the old undo list will be restored by rl_maybe_unsave_line.) rl_free_undo_list() end rl_restore_prompt() noninc_dosearch(@noninc_search_string, cxt.direction) end |
._rl_nsearch_init(dir, pchar) ⇒ Object
7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 |
# File 'lib/rbreadline.rb', line 7982 def _rl_nsearch_init(dir, pchar) cxt = _rl_scxt_alloc(RL_SEARCH_NSEARCH, 0) if (dir < 0) cxt.sflags |= SF_REVERSE # not strictly needed end cxt.direction = dir cxt.history_pos = cxt.save_line rl_maybe_save_line() # Clear the undo list, since reading the search string should create its # own undo list, and the whole list will end up being freed when we # finish reading the search string. @rl_undo_list = nil # Use the line buffer to read the search string. @rl_line_buffer[0] = 0.chr @rl_end = @rl_point = 0 _p = _rl_make_prompt_for_search(pchar ? pchar : ':') (_p) _p = nil rl_setstate(RL_STATE_NSEARCH) @_rl_nscxt = cxt cxt end |
._rl_output_some_chars(string, start, count) ⇒ Object
Write COUNT characters from STRING to the output stream.
3787 3788 3789 |
# File 'lib/rbreadline.rb', line 3787 def _rl_output_some_chars(string,start,count) @_rl_out_stream.write(string[start,count]) end |
._rl_overwrite_char(count, c) ⇒ Object
Overwrite the character at point (or next COUNT characters) with C.
If C introduces a multibyte character sequence, read the entire sequence
before starting the overwrite loop.
5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 |
# File 'lib/rbreadline.rb', line 5480 def _rl_overwrite_char(count, c) # Read an entire multibyte character sequence to insert COUNT times. if (count > 0 && !@rl_byte_oriented) mbkey = '' k = _rl_read_mbstring(c, mbkey, MB_LEN_MAX) end rl_begin_undo_group() count.times do if !@rl_byte_oriented rl_insert_text(mbkey) else _rl_insert_char(1, c) end if (@rl_point < @rl_end) rl_delete(1, c) end end rl_end_undo_group() return 0 end |
._rl_overwrite_rubout(count, key) ⇒ Object
This is different from what vi does, so the code’s not shared. Emacs
rubout in overwrite mode has one oddity: it replaces a control
character that's displayed as two characters (^X) with two spaces.
5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 |
# File 'lib/rbreadline.rb', line 5660 def _rl_overwrite_rubout(count, key) if (@rl_point == 0) rl_ding() return 1 end opoint = @rl_point # L == number of spaces to insert l = 0 count.times do rl_backward_char(1, key) l += rl_character_len(@rl_line_buffer[@rl_point,1], @rl_point) # not exactly right end rl_begin_undo_group() if (count > 1 || @rl_explicit_arg) rl_kill_text(opoint, @rl_point) else rl_delete_text(opoint, @rl_point) end # Emacs puts point at the beginning of the sequence of spaces. if (@rl_point < @rl_end) opoint = @rl_point _rl_insert_char(l, ' ') @rl_point = opoint end rl_end_undo_group() 0 end |
._rl_read_init_file(filename, include_level) ⇒ Object
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 |
# File 'lib/rbreadline.rb', line 2093 def _rl_read_init_file(filename, include_level) @current_readline_init_file = filename @current_readline_init_include_level = include_level openname = File.(filename) begin buffer = File.open(openname).read rescue return -1 end if (include_level == 0 && filename != @last_readline_init_file) @last_readline_init_file = filename.dup end @currently_reading_init_file = true # Loop over the lines in the file. Lines that start with `#' are # comments; all other lines are commands for readline initialization. @current_readline_init_lineno = 1 buffer.each_line do |line| line.strip! next if line =~ /^#/ next if line == '' rl_parse_and_bind(line) end return 0 end |
._rl_read_mbchar(mbchar, size) ⇒ Object
read multibyte char
8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 |
# File 'lib/rbreadline.rb', line 8526 def _rl_read_mbchar(mbchar, size) mb_len = 0 while (mb_len < size) rl_setstate(RL_STATE_MOREINPUT) mbchar << rl_read_key() mb_len += 1 rl_unsetstate(RL_STATE_MOREINPUT) case @encoding when 'E' break unless mbchar.scan(/./me).empty? when 'S' break unless mbchar.scan(/./ms).empty? when 'U' break unless mbchar.scan(/./mu).empty? when 'X' break if mbchar.dup.force_encoding(@encoding_name).valid_encoding? end end mb_len end |
._rl_read_mbstring(first, mb, mlen) ⇒ Object
Read a multibyte-character string whose first character is FIRST into
the buffer MB of length MLEN. Returns the last character read, which
may be FIRST. Used by the search functions, among others. Very similar
to _rl_read_mbchar.
8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 |
# File 'lib/rbreadline.rb', line 8551 def _rl_read_mbstring(first, mb, mlen) c = first for i in 0 ... mlen mb << c if _rl_get_char_len(mb) == -2 # Read more for multibyte character rl_setstate(RL_STATE_MOREINPUT) c = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) else break end end c end |
._rl_redisplay_after_sigwinch ⇒ Object
Redisplay the current line after a SIGWINCH is received.
8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 |
# File 'lib/rbreadline.rb', line 8598 def _rl_redisplay_after_sigwinch() # Clear the current line and put the cursor at column 0. Make sure # the right thing happens if we have wrapped to a new screen line. if @_rl_term_cr @rl_outstream.write(@_rl_term_cr) @_rl_last_c_pos = 0 if @_rl_term_clreol @rl_outstream.write(@_rl_term_clreol) else space_to_eol(@_rl_screenwidth) @rl_outstream.write(@_rl_term_cr) end if @_rl_last_v_pos > 0 _rl_move_vert(0) end else rl_crlf() end # Redraw only the last line of a multi-line prompt. t = @rl_display_prompt.index("\n") if t redraw_prompt(@rl_display_prompt[(t+1)..-1]) else rl_forced_update_display() end end |
._rl_replace_text(text, start, _end) ⇒ Object
Replace the contents of the line buffer between START and END with
TEXT. The operation is undoable. To replace the entire line in an
undoable mode, use _rl_replace_text(text, 0, rl_end)
4883 4884 4885 4886 4887 4888 4889 4890 |
# File 'lib/rbreadline.rb', line 4883 def _rl_replace_text(text, start, _end) rl_begin_undo_group() rl_delete_text(start, _end + 1) @rl_point = start n = rl_insert_text(text) rl_end_undo_group() n end |
._rl_reset_argument ⇒ Object
Create a default argument.
3885 3886 3887 3888 3889 |
# File 'lib/rbreadline.rb', line 3885 def _rl_reset_argument() @rl_numeric_arg = @rl_arg_sign = 1 @rl_explicit_arg = false @_rl_argcxt = 0 end |
._rl_rubout_char(count, key) ⇒ Object
5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 |
# File 'lib/rbreadline.rb', line 5721 def _rl_rubout_char(count, key) # Duplicated code because this is called from other parts of the library. if (count < 0) return (rl_delete(-count, key)) end if (@rl_point == 0) rl_ding() return -1 end orig_point = @rl_point if (count > 1 || @rl_explicit_arg) rl_backward_char(count, key) rl_kill_text(orig_point, @rl_point) elsif (@rl_byte_oriented) c = @rl_line_buffer[@rl_point-=1,1] rl_delete_text(@rl_point, orig_point) # The erase-at-end-of-line hack is of questionable merit now. if (@rl_point == @rl_end && isprint(c) && @_rl_last_c_pos!=0) l = rl_character_len(c, @rl_point) _rl_erase_at_end_of_line(l) end else @rl_point = _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO) rl_delete_text(@rl_point, orig_point) end 0 end |
._rl_scxt_alloc(type, flags) ⇒ Object
7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 |
# File 'lib/rbreadline.rb', line 7056 def _rl_scxt_alloc(type, flags) cxt = Struct.new(:type,:sflags,:search_string,:search_string_index,:search_string_size,:lines,:allocated_line, :hlen,:hindex,:save_point,:save_mark,:save_line,:last_found_line,:prev_line_found,:save_undo_list,:history_pos, :direction,:lastc,:sline,:sline_len,:sline_index,:search_terminators).new cxt.type = type cxt.sflags = flags cxt.search_string = nil cxt.search_string_size = cxt.search_string_index = 0 cxt.lines = nil cxt.allocated_line = nil cxt.hlen = cxt.hindex = 0 cxt.save_point = @rl_point cxt.save_mark = @rl_mark cxt.save_line = where_history() cxt.last_found_line = cxt.save_line cxt.prev_line_found = nil cxt.save_undo_list = nil cxt.history_pos = 0 cxt.direction = 0 cxt.lastc = 0 cxt.sline = nil cxt.sline_len = cxt.sline_index = 0 cxt.search_terminators = nil cxt end |
._rl_search_getchar(cxt) ⇒ Object
3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 |
# File 'lib/rbreadline.rb', line 3912 def _rl_search_getchar(cxt) # Read a key and decide how to proceed. rl_setstate(RL_STATE_MOREINPUT) c = cxt.lastc = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) if !@rl_byte_oriented cxt.mb = "" c = cxt.lastc = _rl_read_mbstring(cxt.lastc, cxt.mb, MB_LEN_MAX) end c end |
._rl_set_insert_mode(im, force) ⇒ Object
Function for the rest of the library to use to set insert/overwrite mode.
1431 1432 1433 |
# File 'lib/rbreadline.rb', line 1431 def _rl_set_insert_mode(im, force) @rl_insert_mode = im end |
._rl_set_mark_at_pos(position) ⇒ Object
Set the mark at POSITION.
6951 6952 6953 6954 6955 |
# File 'lib/rbreadline.rb', line 6951 def _rl_set_mark_at_pos(position) return -1 if (position > @rl_end) @rl_mark = position 0 end |
._rl_start_using_history ⇒ Object
Set the history pointer back to the last entry in the history.
2531 2532 2533 2534 |
# File 'lib/rbreadline.rb', line 2531 def _rl_start_using_history() using_history() @_rl_saved_line_for_history = nil end |
._rl_strip_prompt(pmt) ⇒ Object
3760 3761 3762 |
# File 'lib/rbreadline.rb', line 3760 def _rl_strip_prompt(pmt) return (pmt).first end |
._rl_subseq_getchar(key) ⇒ Object
4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 |
# File 'lib/rbreadline.rb', line 4486 def _rl_subseq_getchar(key) if (key == ESC) rl_setstate(RL_STATE_METANEXT) end rl_setstate(RL_STATE_MOREINPUT) k = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) if (key == ESC) rl_unsetstate(RL_STATE_METANEXT) end return k end |
._rl_to_lower(char) ⇒ Object
1292 1293 1294 |
# File 'lib/rbreadline.rb', line 1292 def _rl_to_lower(char) char.nil? ? nil : char.chr.downcase end |
._rl_unget_char(key) ⇒ Object
Stuff KEY into the front of the input buffer.
Returns non-zero if successful, zero if there is
no space left in the buffer.
4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 |
# File 'lib/rbreadline.rb', line 4474 def _rl_unget_char(key) if (ibuffer_space()!=0) @pop_index-=1 if (@pop_index < 0) @pop_index = @ibuffer_len - 1 end @ibuffer[@pop_index] = key return (1) end return (0) end |
._rl_update_final ⇒ Object
5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 |
# File 'lib/rbreadline.rb', line 5582 def _rl_update_final() full_lines = false # If the cursor is the only thing on an otherwise-blank last line, # compensate so we don't print an extra CRLF. if (@_rl_vis_botlin && @_rl_last_c_pos == 0 && @visible_line[@vis_lbreaks[@_rl_vis_botlin]] == ?\0 ) @_rl_vis_botlin-=1 full_lines = true end _rl_move_vert(@_rl_vis_botlin) # If we've wrapped lines, remove the final xterm line-wrap flag. if (full_lines && @_rl_term_autowrap && (vis_llen(@_rl_vis_botlin) == @_rl_screenwidth)) last_line = @visible_line[@vis_lbreaks[@_rl_vis_botlin]..-1] @cpos_buffer_position = -1 # don't know where we are in buffer _rl_move_cursor_relative(@_rl_screenwidth - 1, last_line) # XXX _rl_clear_to_eol(0) @rl_outstream.write(last_line[@_rl_screenwidth - 1,1]) end @_rl_vis_botlin = 0 rl_crlf() @rl_outstream.flush @rl_display_fixed = true if !@rl_display_fixed end |
._rl_vi_done_inserting ⇒ Object
5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 |
# File 'lib/rbreadline.rb', line 5542 def _rl_vi_done_inserting() if (@_rl_vi_doing_insert) # The `C', `s', and `S' commands set this. rl_end_undo_group() # Now, the text between rl_undo_list->next->start and # rl_undo_list->next->end is what was inserted while in insert # mode. It gets copied to VI_INSERT_BUFFER because it depends # on absolute indices into the line which may change (though they # probably will not). @_rl_vi_doing_insert = 0 _rl_vi_save_insert(@rl_undo_list.next) @vi_continued_command = 1 else if ((@_rl_vi_last_key_before_insert == 'i' || @_rl_vi_last_key_before_insert == 'a') && @rl_undo_list) _rl_vi_save_insert(@rl_undo_list) # XXX - Other keys probably need to be checked. elsif (@_rl_vi_last_key_before_insert == 'C') rl_end_undo_group() end while (@_rl_undo_group_level > 0) rl_end_undo_group() end @vi_continued_command = 0 end end |
._rl_vi_initialize_line ⇒ Object
3716 3717 3718 |
# File 'lib/rbreadline.rb', line 3716 def _rl_vi_initialize_line rl_unsetstate(RL_STATE_VICMDONCE) end |
._rl_vi_reset_last ⇒ Object
5575 5576 5577 5578 5579 5580 |
# File 'lib/rbreadline.rb', line 5575 def _rl_vi_reset_last() @_rl_vi_last_command = 'i' @_rl_vi_last_repeat = 1 @_rl_vi_last_arg_sign = 1 @_rl_vi_last_motion = 0 end |
._rl_vi_save_insert(up) ⇒ Object
5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 |
# File 'lib/rbreadline.rb', line 5529 def _rl_vi_save_insert(up) if (up.nil? || up.what != UNDO_INSERT) if (@vi_insert_buffer_size >= 1) @vi_insert_buffer[0] = 0.chr end return end start = up.start _end = up.end len = _end - start + 1 @vi_insert_buffer = @rl_line_buffer[start,len-1] end |
._rl_vi_textmod_command(c) ⇒ Object
Is the command C a VI mode text modification command?
5571 5572 5573 |
# File 'lib/rbreadline.rb', line 5571 def _rl_vi_textmod_command(c) return @vi_textmod[c] end |
._rl_walphabetic(c) ⇒ Object
5072 5073 5074 |
# File 'lib/rbreadline.rb', line 5072 def _rl_walphabetic(c) rl_alphabetic(c) end |
.add_history(string) ⇒ Object
Place STRING at the end of the history list. The data field
is set to NULL.
6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 |
# File 'lib/rbreadline.rb', line 6003 def add_history(string) if (@history_stifled && (@history_length == @history_max_entries)) # If the history is stifled, and history_length is zero, # and it equals history_max_entries, we don't save items. return if (@history_length == 0) @the_history.shift else if @the_history.nil? @the_history = [] @history_length = 1 else @history_length+=1 end end temp = alloc_history_entry(string, hist_inittime()) @the_history[@history_length] = nil @the_history[@history_length - 1] = temp end |
.alloc_history_entry(string, ts) ⇒ Object
5983 5984 5985 5986 5987 5988 5989 5990 |
# File 'lib/rbreadline.rb', line 5983 def alloc_history_entry(string, ts) temp = Struct.new(:line,:data,:timestamp).new temp.line = string ? string.delete(0.chr) : string temp.data = nil temp. = ts return temp end |
.alloc_undo_entry(what, start, _end, text) ⇒ Object
4783 4784 4785 4786 4787 4788 4789 4790 4791 |
# File 'lib/rbreadline.rb', line 4783 def alloc_undo_entry(what, start, _end, text) temp = Struct.new(:what,:start,:end,:text,:next).new temp.what = what temp.start = start temp.end = _end temp.text = text temp.next = nil temp end |
.append_to_match(text, delimiter, quote_char, nontrivial_match) ⇒ Object
Append any necessary closing quote and a separator character to the just-inserted match. If the user has specified that directories should be marked by a trailing ‘/’, append one of those instead. The default trailing character is a space. Returns the number of characters appended. If NONTRIVIAL_MATCH is set, we test for a symlink (if the OS has them) and don’t add a suffix for a symlink to a directory. A nontrivial match is one that actually adds to the word being completed. The variable rl_completion_mark_symlink_dirs controls this behavior (it’s initially set to the what the user has chosen, indicated by the value of _rl_complete_mark_symlink_dirs, but may be modified by an application’s completion function).
8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 |
# File 'lib/rbreadline.rb', line 8256 def append_to_match(text, delimiter, quote_char, nontrivial_match) temp_string = 0.chr * 4 temp_string_index = 0 if (quote_char && @rl_point>0 && !@rl_completion_suppress_quote && @rl_line_buffer[@rl_point - 1,1] != quote_char) temp_string[temp_string_index] = quote_char temp_string_index += 1 end if (delimiter != 0.chr) temp_string[temp_string_index] = delimiter temp_string_index += 1 elsif (!@rl_completion_suppress_append && @rl_completion_append_character) temp_string[temp_string_index] = @rl_completion_append_character temp_string_index += 1 end temp_string[temp_string_index] = 0.chr temp_string_index += 1 if (@rl_filename_completion_desired) filename = File.(text) s = (nontrivial_match && !@rl_completion_mark_symlink_dirs) ? File.lstat(filename) : File.stat(filename) if s.directory? if @_rl_complete_mark_directories # This is clumsy. Avoid putting in a double slash if point # is at the end of the line and the previous character is a # slash. if (@rl_point>0 && @rl_line_buffer[@rl_point] == ?\0 && @rl_line_buffer[@rl_point - 1] == ?/ ) elsif (@rl_line_buffer[@rl_point] != ?/ ) rl_insert_text("/") end end # Don't add anything if the filename is a symlink and resolves to a # directory. elsif s.symlink? && File.stat(filename).directory? else if (@rl_point == @rl_end && temp_string_index>0) rl_insert_text(temp_string) end end filename = nil else if (@rl_point == @rl_end && temp_string_index>0) rl_insert_text(temp_string) end end temp_string_index end |
.bind_arrow_keys ⇒ Object
Try and bind the common arrow key prefixes after giving termcap and
the inputrc file a chance to bind them and create `real' keymaps
for the arrow key prefix.
2467 2468 2469 2470 2471 |
# File 'lib/rbreadline.rb', line 2467 def bind_arrow_keys() bind_arrow_keys_internal(@emacs_standard_keymap) bind_arrow_keys_internal(@vi_movement_keymap) bind_arrow_keys_internal(@vi_insertion_keymap) end |
.bind_arrow_keys_internal(map) ⇒ Object
Bind some common arrow key sequences in MAP.
2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 |
# File 'lib/rbreadline.rb', line 2430 def bind_arrow_keys_internal(map) xkeymap = @_rl_keymap @_rl_keymap = map if RUBY_PLATFORM =~ /mswin|mingw/ rl_bind_keyseq_if_unbound("\340H", :rl_get_previous_history) # Up rl_bind_keyseq_if_unbound("\340P", :rl_get_next_history) # Down rl_bind_keyseq_if_unbound("\340M", :rl_forward_char) # Right rl_bind_keyseq_if_unbound("\340K", :rl_backward_char) # Left rl_bind_keyseq_if_unbound("\340G", :rl_beg_of_line) # Home rl_bind_keyseq_if_unbound("\340O", :rl_end_of_line) # End rl_bind_keyseq_if_unbound("\340s", :rl_backward_word) # Ctrl-Left rl_bind_keyseq_if_unbound("\340t", :rl_forward_word) # Ctrl-Right rl_bind_keyseq_if_unbound("\340S", :rl_delete) # Delete rl_bind_keyseq_if_unbound("\340R", :rl_overwrite_mode) # Insert else rl_bind_keyseq_if_unbound("\033[A", :rl_get_previous_history) rl_bind_keyseq_if_unbound("\033[B", :rl_get_next_history) rl_bind_keyseq_if_unbound("\033[C", :rl_forward_char) rl_bind_keyseq_if_unbound("\033[D", :rl_backward_char) rl_bind_keyseq_if_unbound("\033[H", :rl_beg_of_line) rl_bind_keyseq_if_unbound("\033[F", :rl_end_of_line) rl_bind_keyseq_if_unbound("\033OA", :rl_get_previous_history) rl_bind_keyseq_if_unbound("\033OB", :rl_get_next_history) rl_bind_keyseq_if_unbound("\033OC", :rl_forward_char) rl_bind_keyseq_if_unbound("\033OD", :rl_backward_char) rl_bind_keyseq_if_unbound("\033OH", :rl_beg_of_line) rl_bind_keyseq_if_unbound("\033OF", :rl_end_of_line) end @_rl_keymap = xkeymap end |
.bind_termcap_arrow_keys(map) ⇒ Object
Bind the arrow key sequences from the termcap description in MAP.
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 |
# File 'lib/rbreadline.rb', line 1931 def bind_termcap_arrow_keys(map) xkeymap = @_rl_keymap @_rl_keymap = map rl_bind_keyseq_if_unbound(@_rl_term_ku, :rl_get_previous_history) rl_bind_keyseq_if_unbound(@_rl_term_kd, :rl_get_next_history) rl_bind_keyseq_if_unbound(@_rl_term_kr, :rl_forward_char) rl_bind_keyseq_if_unbound(@_rl_term_kl, :rl_backward_char) rl_bind_keyseq_if_unbound(@_rl_term_kh, :rl_beg_of_line) # Home rl_bind_keyseq_if_unbound(@_rl_term_at7, :rl_end_of_line) # End rl_bind_keyseq_if_unbound(@_rl_term_kD, :rl_delete) rl_bind_keyseq_if_unbound(@_rl_term_kI, :rl_overwrite_mode) @_rl_keymap = xkeymap end |
.block_sigint ⇒ Object
6792 6793 6794 6795 6796 |
# File 'lib/rbreadline.rb', line 6792 def block_sigint() return if @sigint_blocked #@sigint_proc = Signal.trap("INT","IGNORE") @sigint_blocked = true end |
.clear_history ⇒ Object
8336 8337 8338 8339 |
# File 'lib/rbreadline.rb', line 8336 def clear_history() @the_history = nil @history_offset = @history_length = 0 end |
.compute_lcd_of_matches(match_list, matches, text) ⇒ Object
Find the common prefix of the list of matches, and put it into
matches[0].
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 |
# File 'lib/rbreadline.rb', line 1298 def compute_lcd_of_matches(match_list, matches, text) # If only one match, just use that. Otherwise, compare each # member of the list with the next, finding out where they # stop matching. if (matches == 1) match_list[0] = match_list[1] match_list[1] = nil return 1 end i = 1 low = 100000 while(i<matches) if (@_rl_completion_case_fold) si = 0 while((c1 = _rl_to_lower(match_list[i][si])) && (c2 = _rl_to_lower(match_list[i + 1][si]))) if !@rl_byte_oriented if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si)) break elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1) si += v - 1 end else break if (c1 != c2) end si += 1 end else si = 0 while((c1 = match_list[i][si]) && (c2 = match_list[i + 1][si])) if !@rl_byte_oriented if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si)) break elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1) si += v - 1 end else break if (c1 != c2) end si += 1 end end if (low > si) low = si end i += 1 end # If there were multiple matches, but none matched up to even the # first character, and the user typed something, use that as the # value of matches[0]. if (low == 0 && text && text.length>0 ) match_list[0] = text.dup else # XXX - this might need changes in the presence of multibyte chars # If we are ignoring case, try to preserve the case of the string # the user typed in the face of multiple matches differing in case. if (@_rl_completion_case_fold) # We're making an assumption here: # IF we're completing filenames AND # the application has defined a filename dequoting function AND # we found a quote character AND # the application has requested filename quoting # THEN # we assume that TEXT was dequoted before checking against # the file system and needs to be dequoted here before we # check against the list of matches # FI if (@rl_filename_completion_desired && @rl_filename_dequoting_function && @rl_completion_found_quote && @rl_filename_quoting_desired) dtext = send(@rl_filename_dequoting_function,text, @rl_completion_quote_character) text = dtext end # sort the list to get consistent answers. match_list = [match_list[0]] + match_list[1..-1].sort si = text.length if (si <= low) for i in 1 .. matches if match_list[i][0,si] == text match_list[0] = match_list[i][0,low] break end # no casematch, use first entry if (i > matches) match_list[0] = match_list[1][0,low] end end else # otherwise, just use the text the user typed. match_list[0] = text[0,low] end else match_list[0] = match_list[1][0,low] end end return matches end |
.cr ⇒ Object
Move to the start of the current line.
4553 4554 4555 4556 4557 4558 |
# File 'lib/rbreadline.rb', line 4553 def cr() if (@_rl_term_cr) @_rl_out_stream.write(@_rl_term_cr) @_rl_last_c_pos = 0 end end |
.cr_faster(new, cur) ⇒ Object
2537 2538 2539 |
# File 'lib/rbreadline.rb', line 2537 def cr_faster(new, cur) (new + 1) < (cur - new) end |
.ctrl_char(c) ⇒ Object
2595 2596 2597 |
# File 'lib/rbreadline.rb', line 2595 def ctrl_char(c) c < "\x20" end |
.current_history ⇒ Object
Return the history entry at the current position, as determined by
history_offset. If there is no entry there, return a NULL pointer.
2586 2587 2588 2589 |
# File 'lib/rbreadline.rb', line 2586 def current_history() return ((@history_offset == @history_length) || @the_history.nil?) ? nil : @the_history[@history_offset] end |
.delete_chars(count) ⇒ Object
Delete COUNT characters from the display line.
8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 |
# File 'lib/rbreadline.rb', line 8381 def delete_chars(count) return if (count > @_rl_screenwidth) # XXX if @hConsoleHandle.nil? #if (@_rl_term_DC) # buffer = tgoto(_rl_term_DC, count, count); # @_rl_out_stream.write(buffer * count) #else if (@_rl_term_dc) @_rl_out_stream.write(@_rl_term_dc * count) end #end end end |
.display_matches(matches) ⇒ Object
Display MATCHES, a list of matching filenames in argv format. This handles the simple case – a single match – first. If there is more than one match, we compute the number of strings in the list and the length of the longest string, which will be needed by the display function. If the application wants to handle displaying the list of matches itself, it sets RL_COMPLETION_DISPLAY_MATCHES_HOOK to the address of a function, and we just call it. If we’re handling the display ourselves, we just call rl_display_match_list. We also check that the list of matches doesn’t exceed the user-settable threshold, and ask the user if he wants to see the list if there are more matches than RL_COMPLETION_QUERY_ITEMS.
6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 |
# File 'lib/rbreadline.rb', line 6572 def display_matches(matches) # Move to the last visible line of a possibly-multiple-line command. _rl_move_vert(@_rl_vis_botlin) # Handle simple case first. What if there is only one answer? if matches[1].nil? temp = printable_part(matches[0]) rl_crlf() print_filename(temp, matches[0]) rl_crlf() rl_forced_update_display() @rl_display_fixed = true return end # There is more than one answer. Find out how many there are, # and find the maximum printed length of a single entry. max = 0 i = 1 while(matches[i]) temp = printable_part(matches[i]) len = fnwidth(temp) if (len > max) max = len end i += 1 end len = i - 1 # If the caller has defined a display hook, then call that now. if (@rl_completion_display_matches_hook) send(@rl_completion_display_matches_hook,matches, len, max) return end # If there are many items, then ask the user if she really wants to # see them all. if (@rl_completion_query_items > 0 && len >= @rl_completion_query_items) rl_crlf() @rl_outstream.write("Display all #{len} possibilities? (y or n)") @rl_outstream.flush if (get_y_or_n(false)==0) rl_crlf() rl_forced_update_display() @rl_display_fixed = true return end end rl_display_match_list(matches, len, max) rl_forced_update_display() @rl_display_fixed = true end |
.endsrch_char(c) ⇒ Object
3924 3925 3926 |
# File 'lib/rbreadline.rb', line 3924 def endsrch_char(c) ((ctrl_char(c) || (c) || (c) == RUBOUT) && ((c) != "\C-G")) end |
.expand_prompt(pmt) ⇒ Object
Current implementation:
\001 (^A) start non-visible characters
\002 (^B) end non-visible characters
all characters except \001 and \002 (following a \001) are copied to
the returned string all characters except those between \001 and
\002 are assumed to be `visible'.
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 |
# File 'lib/rbreadline.rb', line 1656 def (pmt) # Short-circuit if we can. if (@rl_byte_oriented && pmt[RL_PROMPT_START_IGNORE].nil?) r = pmt.dup lp = r.length lip = 0 niflp = 0 vlp = lp return [r,lp,lip,niflp,vlp] end l = pmt.length ret = '' invfl = 0 # invisible chars in first line of prompt invflset = 0 # we only want to set invfl once igstart = 0 rl = 0 ignoring = false last = ninvis = physchars = 0 for pi in 0 ... pmt.length # This code strips the invisible character string markers #RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE if (!ignoring && pmt[pi,1] == RL_PROMPT_START_IGNORE) # XXX - check ignoring? ignoring = true igstart = pi next elsif (ignoring && pmt[pi,1] == RL_PROMPT_END_IGNORE) ignoring = false if (pi != (igstart + 1)) last = ret.length - 1 end next else if !@rl_byte_oriented pind = pi ind = _rl_find_next_mbchar(pmt, pind, 1, MB_FIND_NONZERO) l = ind - pind while (l>0) l-=1 ret << pmt[pi] pi += 1 end if (!ignoring) rl += ind - pind physchars += _rl_col_width(pmt, pind, ind) else ninvis += ind - pind end pi-=1 # compensate for later increment else ret << pmt[pi] if (!ignoring) rl+=1 # visible length byte counter physchars+=1 else ninvis+=1 # invisible chars byte counter end if (invflset == 0 && rl >= @_rl_screenwidth) invfl = ninvis invflset = 1 end end end end if (rl < @_rl_screenwidth) invfl = ninvis end lp = rl lip = last niflp = invfl vlp = physchars return [ret,lp,lip,niflp,vlp] end |
.fnprint(to_print) ⇒ Object
6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 |
# File 'lib/rbreadline.rb', line 6350 def fnprint(to_print) printed_len = 0 case @encoding when 'E' arr = to_print.scan(/./me) when 'S' arr = to_print.scan(/./ms) when 'U' arr = to_print.scan(/./mu) when 'X' arr = to_print.dup.force_encoding(@encoding_name).chars else arr = to_print.scan(/./m) end arr.each do |s| if(ctrl_char(s)) @rl_outstream.write('^'+(s[0].ord|0x40).chr.upcase) printed_len += 2 elsif s == RUBOUT @rl_outstream.write('^?') printed_len += 2 else @rl_outstream.write(s) if @encoding=='U' printed_len += s.unpack('U').first >= 0x1000 ? 2 : 1 elsif @encoding=='X' printed_len += s.ord >= 0x1000 ? 2 : 1 else printed_len += s.length end end end printed_len end |
.fnwidth(string) ⇒ Object
Compute width of STRING when displayed on screen by print_filename
6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 |
# File 'lib/rbreadline.rb', line 6522 def fnwidth(string) left = string.length + 1 width = pos = 0 while (string[pos] && string[pos] != ?\0) if (ctrl_char(string[0,1]) || string[0,1] == RUBOUT) width += 2 pos+=1 else case @encoding when 'E' wc = string[pos,left-pos].scan(/./me)[0] bytes = wc.length tempwidth = wc.length when 'S' wc = string[pos,left-pos].scan(/./ms)[0] bytes = wc.length tempwidth = wc.length when 'U' wc = string[pos,left-pos].scan(/./mu)[0] bytes = wc.length tempwidth = wc.unpack('U').first >= 0x1000 ? 2 : 1 when 'X' wc = string[pos,left-pos].force_encoding(@encoding_name)[0] bytes = wc.bytesize tempwidth = wc.ord >= 0x1000 ? 2 : 1 else wc = string[pos,left-pos].scan(/./m)[0] bytes = wc.length tempwidth = wc.length end clen = bytes pos += clen w = tempwidth width += (w >= 0) ? w : 1 end end width end |
.gen_completion_matches(text, start, _end, our_func, found_quote, quote_char) ⇒ Object
6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 |
# File 'lib/rbreadline.rb', line 6170 def gen_completion_matches(text, start, _end, our_func, found_quote, quote_char) @rl_completion_found_quote = found_quote @rl_completion_quote_character = quote_char # If the user wants to TRY to complete, but then wants to give # up and use the default completion function, they set the # variable rl_attempted_completion_function. if (@rl_attempted_completion_function) matches = Readline.send(@rl_attempted_completion_function,text, start, _end) if (matches || @rl_attempted_completion_over) @rl_attempted_completion_over = false return (matches) end end # XXX -- filename dequoting moved into rl_filename_completion_function matches = rl_completion_matches(text, our_func) matches end |
.get_term_capabilities(buffer) ⇒ Object
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 |
# File 'lib/rbreadline.rb', line 1794 def get_term_capabilities(buffer) hash = {} `infocmp -C`.split(':').select{|x| x =~ /(.*)=(.*)/ and hash[$1]=$2.gsub('\\E',"\e").gsub(/\^(.)/){($1[0].ord ^ ((?a..?z).include?($1[0]) ? 0x60 : 0x40)).chr}} @_rl_term_at7 = hash["@7"] @_rl_term_DC = hash["DC"] @_rl_term_IC = hash["IC"] @_rl_term_clreol = hash["ce"] @_rl_term_clrpag = hash["cl"] @_rl_term_cr = hash["cr"] @_rl_term_dc = hash["dc"] @_rl_term_ei = hash["ei"] @_rl_term_ic = hash["ic"] @_rl_term_im = hash["im"] @_rl_term_kD = hash["kD"] @_rl_term_kH = hash["kH"] @_rl_term_kI = hash["kI"] @_rl_term_kd = hash["kd"] @_rl_term_ke = hash["ke"] @_rl_term_kh = hash["kh"] @_rl_term_kl = hash["kl"] @_rl_term_kr = hash["kr"] @_rl_term_ks = hash["ks"] @_rl_term_ku = hash["ku"] @_rl_term_backspace = hash["le"] @_rl_term_mm = hash["mm"] @_rl_term_mo = hash["mo"] @_rl_term_forward_char = hash["nd"] @_rl_term_pc = hash["pc"] @_rl_term_up = hash["up"] @_rl_visible_bell = hash["vb"] @_rl_term_vs = hash["vs"] @_rl_term_ve = hash["ve"] @tcap_initialized = true end |
.get_y_or_n(for_pager) ⇒ Object
The user must press “y” or “n”. Non-zero return means “y” pressed.
6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 |
# File 'lib/rbreadline.rb', line 6495 def get_y_or_n(for_pager) while(true) rl_setstate(RL_STATE_MOREINPUT) c = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) if (c == 'y' || c == 'Y' || c == ' ') return (1) end if (c == 'n' || c == 'N' || c == RUBOUT) return (0) end if (c == ABORT_CHAR) _rl_abort_internal() end if (for_pager && (c == NEWLINE || c == RETURN)) return (2) end if (for_pager && (c == 'q' || c == 'Q')) return (0) end rl_ding() end end |
.handle_parser_directive(statement) ⇒ Object
Handle a parser directive. STATEMENT is the line of the directive
without any leading `$'.
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 |
# File 'lib/rbreadline.rb', line 2213 def handle_parser_directive(statement) directive,args = statement.split(' ') case directive.downcase when "if" parser_if(args) return 0 when "endif" parser_endif(args) return 0 when "else" parser_else(args) return 0 when "include" parser_include(args) return 0 end #_rl_init_file_error("unknown parser directive") return 1 end |
.hist_inittime ⇒ Object
5992 5993 5994 5995 5996 5997 5998 5999 |
# File 'lib/rbreadline.rb', line 5992 def hist_inittime() t = Time.now.to_i ts = "X%u" % t ret = ts.dup ret[0] = @history_comment_char ret end |
.history_base ⇒ Object
Returns the value of attribute history_base.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def history_base @history_base end |
.history_get(offset) ⇒ Object
Return the history entry which is logically at OFFSET in the history array.
OFFSET is relative to history_base.
6759 6760 6761 6762 6763 |
# File 'lib/rbreadline.rb', line 6759 def history_get(offset) local_index = offset - @history_base return (local_index >= @history_length || local_index < 0 || @the_history.nil?) ? nil : @the_history[local_index] end |
.history_is_stifled ⇒ Object
8332 8333 8334 |
# File 'lib/rbreadline.rb', line 8332 def history_is_stifled() return (@history_stifled) end |
.history_length ⇒ Object
Returns the value of attribute history_length.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def history_length @history_length end |
.history_list ⇒ Object
7092 7093 7094 |
# File 'lib/rbreadline.rb', line 7092 def history_list() @the_history end |
.history_search_pos(string, dir, pos) ⇒ Object
Search for STRING in the history list. DIR is < 0 for searching
backwards. POS is an absolute index into the history list at
which point to begin searching.
7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 |
# File 'lib/rbreadline.rb', line 7884 def history_search_pos(string, dir, pos) old = where_history() history_set_pos(pos) if (history_search(string, dir) == -1) history_set_pos(old) return (-1) end ret = where_history() history_set_pos(old) ret end |
.history_search_prefix(string, direction) ⇒ Object
Do an anchored search for string through the history in DIRECTION.
7877 7878 7879 |
# File 'lib/rbreadline.rb', line 7877 def history_search_prefix (string, direction) history_search_internal(string, direction, ANCHORED_SEARCH) end |
.history_set_pos(pos) ⇒ Object
Make the current history item be the one at POS, an absolute index.
Returns zero if POS is out of range, else non-zero.
7868 7869 7870 7871 7872 7873 7874 |
# File 'lib/rbreadline.rb', line 7868 def history_set_pos(pos) if (pos > @history_length || pos < 0 || @the_history.nil?) return (0) end @history_offset = pos 1 end |
.ibuffer_space ⇒ Object
Return the amount of space available in the buffer for stuffing
characters.
4446 4447 4448 4449 4450 4451 4452 |
# File 'lib/rbreadline.rb', line 4446 def ibuffer_space() if (@pop_index > @push_index) return (@pop_index - @push_index - 1) else return (@ibuffer_len - (@push_index - @pop_index)) end end |
.init_line_structures(minsize) ⇒ Object
Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated
arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE
and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is
increased. If the lines have already been allocated, this ensures that
they can hold at least MINSIZE characters.
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 |
# File 'lib/rbreadline.rb', line 2558 def init_line_structures(minsize) if @invisible_line.nil? # initialize it if (@line_size < minsize) @line_size = minsize end @visible_line = 0.chr * @line_size @invisible_line = 0.chr * @line_size # 1.chr elsif (@line_size < minsize) # ensure it can hold MINSIZE chars @line_size *= 2 if (@line_size < minsize) @line_size = minsize end @visible_line << 0.chr * (@line_size - @visible_line.length) @invisible_line << 1.chr * (@line_size - @invisible_line.length) end @visible_line[minsize,@line_size-minsize] = 0.chr * (@line_size-minsize) @invisible_line[minsize,@line_size-minsize] = 1.chr * (@line_size-minsize) if @vis_lbreaks.nil? @inv_lbreaks = [] @vis_lbreaks = [] @_rl_wrapped_line = [] @inv_lbreaks[0] = @vis_lbreaks[0] = 0 end end |
.insert_all_matches(matches, point, qc) ⇒ Object
6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 |
# File 'lib/rbreadline.rb', line 6238 def insert_all_matches(matches, point, qc) rl_begin_undo_group() # remove any opening quote character; make_quoted_replacement will add # it back. if (qc && qc.length>0 && point>0 && @rl_line_buffer[point - 1,1] == qc) point-=1 end rl_delete_text(point, @rl_point) @rl_point = point if (matches[1]) i = 1 while(matches[i]) rp = make_quoted_replacement(matches[i], SINGLE_MATCH, qc) rl_insert_text(rp) rl_insert_text(" ") if (rp != matches[i]) rp = nil end i += 1 end else rp = make_quoted_replacement(matches[0], SINGLE_MATCH, qc) rl_insert_text(rp) rl_insert_text(" ") if (rp != matches[0]) rp = nil end end rl_end_undo_group() end |
.insert_match(match, start, mtype, qc) ⇒ Object
6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 |
# File 'lib/rbreadline.rb', line 6309 def insert_match(match, start, mtype, qc) oqc = qc replacement = make_quoted_replacement(match, mtype, qc) # Now insert the match. if (replacement) # Don't double an opening quote character. if (qc && qc.length>0 && start!=0 && @rl_line_buffer[start - 1,1] == qc && replacement[0,1] == qc) start-=1 # If make_quoted_replacement changed the quoting character, remove # the opening quote and insert the (fully-quoted) replacement. elsif (qc && (qc != oqc) && start!=0 && @rl_line_buffer[start - 1,1] == oqc && replacement[0,1] != oqc) start-=1 end _rl_replace_text(replacement, start, @rl_point - 1) if (replacement != match) replacement = nil end end end |
.insert_some_chars(string, count, col) ⇒ Object
Insert COUNT characters from STRING to the output stream at column COL.
8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 |
# File 'lib/rbreadline.rb', line 8342 def insert_some_chars(string, count, col) if @hConsoleHandle _rl_output_some_chars(string,0,count) else # DEBUGGING if (@rl_byte_oriented) if (count != col) $stderr.write("readline: debug: insert_some_chars: count (#{count}) != col (#{col})\n"); end end # If IC is defined, then we do not have to "enter" insert mode. #if (@_rl_term_IC) # buffer = tgoto(@_rl_term_IC, 0, col) # @_rl_out_stream.write(buffer) # _rl_output_some_chars(string,0,count) #else # If we have to turn on insert-mode, then do so. if (@_rl_term_im) @_rl_out_stream.write(@_rl_term_im) end # If there is a special command for inserting characters, then # use that first to open up the space. if (@_rl_term_ic) @_rl_out_stream.write(@_rl_term_ic * count) end # Print the text. _rl_output_some_chars(string,0, count) # If there is a string to turn off insert mode, we had best use # it now. if (@_rl_term_ei) @_rl_out_stream.write(@_rl_term_ei) end #end end end |
.inv_line(line) ⇒ Object
2631 2632 2633 |
# File 'lib/rbreadline.rb', line 2631 def inv_line(line) @invisible_line[@inv_lbreaks[line] .. -1] end |
.inv_llen(l) ⇒ Object
2615 2616 2617 |
# File 'lib/rbreadline.rb', line 2615 def inv_llen(l) (@inv_lbreaks[l+1] - @inv_lbreaks[l]) end |
.isascii(c) ⇒ Object
7802 7803 7804 7805 |
# File 'lib/rbreadline.rb', line 7802 def isascii(c) int_val = c[0].to_i # 1.8 + 1.9 compat. return (int_val < 128 && int_val > 0) end |
.isprint(c) ⇒ Object
2599 2600 2601 |
# File 'lib/rbreadline.rb', line 2599 def isprint(c) c >= "\x20" && c < "\x7f" end |
.m_offset(margin, offset) ⇒ Object
2635 2636 2637 |
# File 'lib/rbreadline.rb', line 2635 def m_offset(margin, offset) ((margin) == 0 ? offset : 0) end |
.make_history_line_current(entry) ⇒ Object
Make the data from the history entry ENTRY be the contents of the
current line. This doesn't do anything with rl_point; the caller
must set it.
7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 |
# File 'lib/rbreadline.rb', line 7851 def make_history_line_current(entry) _rl_replace_text(entry.line, 0, @rl_end) _rl_fix_point(1) if (@rl_editing_mode == @vi_mode) # POSIX.2 says that the `U' command doesn't affect the copy of any # command lines to the edit line. We're going to implement that by # making the undo list start after the matching line is copied to the # current editing buffer. rl_free_undo_list() end if (@_rl_saved_line_for_history) @_rl_saved_line_for_history = nil end end |
.make_quoted_replacement(match, mtype, qc) ⇒ Object
6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 |
# File 'lib/rbreadline.rb', line 6269 def make_quoted_replacement(match, mtype, qc) # If we are doing completion on quoted substrings, and any matches # contain any of the completer_word_break_characters, then auto- # matically prepend the substring with a quote character (just pick # the first one from the list of such) if it does not already begin # with a quote string. FIXME: Need to remove any such automatically # inserted quote character when it no longer is necessary, such as # if we change the string we are completing on and the new set of # matches don't require a quoted substring. replacement = match should_quote = match && @rl_completer_quote_characters && @rl_filename_completion_desired && @rl_filename_quoting_desired if (should_quote) should_quote = should_quote && (qc.nil? || qc == 0.chr || (@rl_completer_quote_characters && @rl_completer_quote_characters.include?(qc))) end if (should_quote) # If there is a single match, see if we need to quote it. # This also checks whether the common prefix of several # matches needs to be quoted. should_quote = @rl_filename_quote_characters ? !!match[@rl_filename_quote_characters] : false do_replace = should_quote ? mtype : NO_MATCH # Quote the replacement, since we found an embedded # word break character in a potential match. if (do_replace != NO_MATCH && @rl_filename_quoting_function) replacement = send(@rl_filename_quoting_function,match, do_replace, qc) end end replacement end |
.meta_char(c) ⇒ Object
2591 2592 2593 |
# File 'lib/rbreadline.rb', line 2591 def (c) c > "\x7f" && c <= "\xff" end |
.next_history ⇒ Object
Move history_offset forward to the next history entry, and return
a pointer to that entry. If there is no next entry then return a
NULL pointer.
5298 5299 5300 |
# File 'lib/rbreadline.rb', line 5298 def next_history() (@history_offset == @history_length) ? nil : @the_history[@history_offset+=1] end |
.no_terminal? ⇒ Boolean
8659 8660 8661 8662 |
# File 'lib/rbreadline.rb', line 8659 def no_terminal? term = ENV["TERM"] term.nil? || (term == 'dumb') || (term == 'cygwin' && RUBY_PLATFORM =~ /mswin|mingw/) end |
.noninc_dosearch(string, dir) ⇒ Object
Search for a line in the history containing STRING. If DIR is < 0, the
search is backwards through previous entries, else through subsequent
entries. Returns 1 if the search was successful, 0 otherwise.
7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 |
# File 'lib/rbreadline.rb', line 7925 def noninc_dosearch(string, dir) if (string.nil? || string == '' || @noninc_history_pos < 0) rl_ding() return 0 end pos = noninc_search_from_pos(string, @noninc_history_pos + dir, dir) if (pos == -1) # Search failed, current history position unchanged. rl_maybe_unsave_line() () @rl_point = 0 rl_ding() return 0 end @noninc_history_pos = pos oldpos = where_history() history_set_pos(@noninc_history_pos) entry = current_history() if (@rl_editing_mode != @vi_mode) history_set_pos(oldpos) end make_history_line_current(entry) @rl_point = 0 @rl_mark = @rl_end () 1 end |
.noninc_search(dir, pchar) ⇒ Object
Search non-interactively through the history list. DIR < 0 means to
search backwards through the history of previous commands; otherwise
the search is for commands subsequent to the current position in the
history list. PCHAR is the character to use for prompting when reading
the search string; if not specified (0), it defaults to `:'.
7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 |
# File 'lib/rbreadline.rb', line 7812 def noninc_search(dir, pchar) cxt = _rl_nsearch_init(dir, pchar) if (rl_isstate(RL_STATE_CALLBACK)) return (0) end # Read the search string. r = 0 while (true) c = _rl_search_getchar(cxt) if (c == 0.chr) break end r = _rl_nsearch_dispatch(cxt, c) if (r < 0) return 1 elsif (r == 0) break end end r = _rl_nsearch_dosearch(cxt) (r >= 0) ? _rl_nsearch_cleanup(cxt, r) : (r != 1) end |
.noninc_search_from_pos(string, pos, dir) ⇒ Object
Search the history list for STRING starting at absolute history position
POS. If STRING begins with `^', the search must match STRING at the
beginning of a history line, otherwise a full substring match is performed
for STRING. DIR < 0 means to search backwards through the history list,
DIR >= 0 means to search forward.
7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 |
# File 'lib/rbreadline.rb', line 7901 def noninc_search_from_pos(string, pos, dir) return 1 if (pos < 0) old = where_history() return -1 if (history_set_pos(pos) == 0) rl_setstate(RL_STATE_SEARCH) if (string[0,1] == '^') ret = history_search_prefix(string + 1, dir) else ret = history_search(string, dir) end rl_unsetstate(RL_STATE_SEARCH) if (ret != -1) ret = where_history() end history_set_pos(old) ret end |
.parser_else(args) ⇒ Object
Invert the current parser state if there is anything on the stack.
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 |
# File 'lib/rbreadline.rb', line 2169 def parser_else(args) if @if_stack.empty? #_rl_init_file_error ("$else found without matching $if") return 0 end # Check the previous (n) levels of the stack to make sure that # we haven't previously turned off parsing. return 0 if @if_stack.detect {|x| x } # Invert the state of parsing if at top level. @_rl_parsing_conditionalized_out = !@_rl_parsing_conditionalized_out return 0 end |
.parser_endif(args) ⇒ Object
Terminate a conditional, popping the value of
_rl_parsing_conditionalized_out from the stack.
2186 2187 2188 2189 2190 2191 2192 2193 |
# File 'lib/rbreadline.rb', line 2186 def parser_endif(args) if (@if_stack.length>0) @_rl_parsing_conditionalized_out = @if_stack.pop else #_rl_init_file_error ("$endif without matching $if") end 0 end |
.parser_if(args) ⇒ Object
Push _rl_parsing_conditionalized_out, and set parser state based
on ARGS.
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 |
# File 'lib/rbreadline.rb', line 2126 def parser_if(args) # Push parser state. @if_stack << @_rl_parsing_conditionalized_out # If parsing is turned off, then nothing can turn it back on except # for finding the matching endif. In that case, return right now. if @_rl_parsing_conditionalized_out return 0 end args.downcase! # Handle "$if term=foo" and "$if mode=emacs" constructs. If this # isn't term=foo, or mode=emacs, then check to see if the first # word in ARGS is the same as the value stored in rl_readline_name. if (@rl_terminal_name && args =~ /^term=/) # Terminals like "aaa-60" are equivalent to "aaa". tname = @rl_terminal_name.downcase.gsub(/-.*$/,'') # Test the `long' and `short' forms of the terminal name so that #if someone has a `sun-cmd' and does not want to have bindings #that will be executed if the terminal is a `sun', they can put #`$if term=sun-cmd' into their .inputrc. @_rl_parsing_conditionalized_out = (args[5..-1] != tname && args[5..-1] != @rl_terminal_name.downcase) elsif args =~ /^mode=/ if args[5..-1] == "emacs" mode = @emacs_mode elsif args[5..-1] == "vi" mode = @vi_mode else mode = @no_mode end @_rl_parsing_conditionalized_out = (mode != @rl_editing_mode) # Check to see if the first word in ARGS is the same as the # value stored in rl_readline_name. elsif (args == @rl_readline_name) @_rl_parsing_conditionalized_out = false else @_rl_parsing_conditionalized_out = true end return 0 end |
.parser_include(args) ⇒ Object
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 |
# File 'lib/rbreadline.rb', line 2195 def parser_include(args) return 0 if (@_rl_parsing_conditionalized_out) old_init_file = @current_readline_init_file old_line_number = @current_readline_init_lineno old_include_level = @current_readline_init_include_level r = _rl_read_init_file(args, old_include_level + 1) @current_readline_init_file = old_init_file @current_readline_init_lineno = old_line_number @current_readline_init_include_level = old_include_level return r end |
.path_isdir(filename) ⇒ Object
6403 6404 6405 |
# File 'lib/rbreadline.rb', line 6403 def path_isdir(filename) return File.directory?(filename) end |
.postprocess_matches(matchesp, matching_filenames) ⇒ Object
6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 |
# File 'lib/rbreadline.rb', line 6202 def postprocess_matches(matchesp, matching_filenames) matches = matchesp return 0 if matches.nil? # It seems to me that in all the cases we handle we would like # to ignore duplicate possiblilities. Scan for the text to # insert being identical to the other completions. if (@rl_ignore_completion_duplicates) remove_duplicate_matches(matches) end # If we are matching filenames, then here is our chance to # do clever processing by re-examining the list. Call the # ignore function with the array as a parameter. It can # munge the array, deleting matches as it desires. if (@rl_ignore_some_completions_function && matching_filenames) nmatch = matches.length send(@rl_ignore_some_completions_function,matches) if (matches.nil? || matches[0].nil?) matches = nil return 0 else # If we removed some matches, recompute the common prefix. i = matches.length if (i > 1 && i < nmatch) t = matches[0] compute_lcd_of_matches(matches, i - 1, t) end end end matchesp = matches 1 end |
.prepare_terminal_settings(meta_flag) ⇒ Object
6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 |
# File 'lib/rbreadline.rb', line 6834 def prepare_terminal_settings() @readline_echoing_p = (`stty -a`.scan(/-*echo\b/).first == 'echo') # First, the basic settings to put us into character-at-a-time, no-echo # input mode. setting = " -echo -icrnl cbreak" # If this terminal doesn't care how the 8th bit is used, then we can # use it for the meta-key. If only one of even or odd parity is # specified, then the terminal is using parity, and we cannot. if (`stty -a`.scan(/-parenb\b/).first == '-parenb') setting << " pass8" end setting << " -ixoff" rl_bind_key(@_rl_tty_chars.t_start, :rl_restart_output) @_rl_eof_char = @_rl_tty_chars.t_eof #setting << " -isig" `stty #{setting}` end |
.previous_history ⇒ Object
Back up history_offset to the previous history entry, and return
a pointer to that entry. If there is no previous entry then return
a NULL pointer.
5291 5292 5293 |
# File 'lib/rbreadline.rb', line 5291 def previous_history() @history_offset!=0 ? @the_history[@history_offset-=1] : nil end |
.print_filename(to_print, full_pathname) ⇒ Object
Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
are using it, check for and output a single character for `special'
filenames. Return the number of characters we output.
6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 |
# File 'lib/rbreadline.rb', line 6432 def print_filename(to_print, full_pathname) extension_char = 0.chr printed_len = fnprint(to_print) if (@rl_filename_completion_desired && (@rl_visible_stats || @_rl_complete_mark_directories)) # If to_print != full_pathname, to_print is the basename of the # path passed. In this case, we try to expand the directory # name before checking for the stat character. if (to_print != full_pathname) if full_pathname.nil? || full_pathname.length==0 dn = "/" else dn = File.dirname(full_pathname) end s = File.(dn) if (@rl_directory_completion_hook) send(@rl_directory_completion_hook,s) end slen = s.length tlen = to_print.length new_full_pathname = s.dup if (s[-1] == ?/ ) slen-=1 else new_full_pathname[slen] = ?/ end new_full_pathname[slen .. -1] = '/' + to_print if (@rl_visible_stats) extension_char = stat_char(new_full_pathname) else if (path_isdir(new_full_pathname)) extension_char = '/' end end new_full_pathname = nil else s = File.(full_pathname) if (@rl_visible_stats) extension_char = stat_char(s) else if (path_isdir(s)) extension_char = '/' end end end s = nil if (extension_char) @rl_outstream.write(extension_char) printed_len+=1 end end printed_len end |
.printable_part(pathname) ⇒ Object
Return the portion of PATHNAME that should be output when listing
possible completions. If we are hacking filename completion, we
are only interested in the basename, the portion following the
final slash. Otherwise, we return what we were passed. Since
printing empty strings is not very informative, if we're doing
filename completion, and the basename is the empty string, we look
for the previous slash and return the portion following that. If
there's no previous slash, we just return what we were passed.
6340 6341 6342 6343 6344 6345 6346 6347 6348 |
# File 'lib/rbreadline.rb', line 6340 def printable_part(pathname) if (!@rl_filename_completion_desired) # don't need to do anything return (pathname) end temp = pathname.rindex('/') return pathname if temp.nil? File.basename(pathname) end |
.prompt_ending_index ⇒ Object
-
_rl_last_c_pos is an absolute cursor position in multibyte locales and a buffer index in others. This macro is used when deciding whether the current cursor position is in the middle of a prompt string containing invisible characters.
2545 2546 2547 2548 2549 2550 2551 |
# File 'lib/rbreadline.rb', line 2545 def prompt_ending_index() if !@rl_byte_oriented @prompt_physical_chars else (@prompt_last_invisible+1) end end |
.readline(prompt) ⇒ Object
Read a line of input. Prompt with PROMPT. An empty PROMPT means
none. A return value of NULL means that EOF was encountered.
4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 |
# File 'lib/rbreadline.rb', line 4712 def readline(prompt) # If we are at EOF return a NULL string. if (@rl_pending_input == EOF) rl_clear_pending_input() return nil end rl_set_prompt(prompt) rl_initialize() @readline_echoing_p = true if (@rl_prep_term_function) send(@rl_prep_term_function,@_rl_meta_flag) end rl_set_signals() value = readline_internal() if(@rl_deprep_term_function) send(@rl_deprep_term_function) end rl_clear_signals() value end |
.readline_default_bindings ⇒ Object
If this system allows us to look at the values of the regular
input editing characters, then bind them to their readline
equivalents, iff the characters are not bound to keymaps.
2054 2055 2056 2057 2058 |
# File 'lib/rbreadline.rb', line 2054 def readline_default_bindings() if @_rl_bind_stty_chars rl_tty_set_default_bindings(@_rl_keymap) end end |
.readline_initialize_everything ⇒ Object
Initialize the entire state of the world.
2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 |
# File 'lib/rbreadline.rb', line 2474 def readline_initialize_everything() # Set up input and output if they are not already set up. @rl_instream ||= $stdin @rl_outstream ||= $stdout # Bind _rl_in_stream and _rl_out_stream immediately. These values # may change, but hey may also be used before readline_internal () # is called. @_rl_in_stream = @rl_instream @_rl_out_stream = @rl_outstream # Allocate data structures. @rl_line_buffer ||= 0.chr * DEFAULT_BUFFER_SIZE # Initialize the terminal interface. @rl_terminal_name ||= ENV["TERM"] _rl_init_terminal_io(@rl_terminal_name) # Bind tty characters to readline functions. readline_default_bindings() # Decide whether we should automatically go into eight-bit mode. _rl_init_eightbit() # Read in the init file. rl_read_init_file(nil) # XXX if (@_rl_horizontal_scroll_mode && @_rl_term_autowrap) @_rl_screenwidth -= 1 @_rl_screenchars -= @_rl_screenheight end # Override the effect of any `set keymap' assignments in the # inputrc file. rl_set_keymap_from_edit_mode() # Try to bind a common arrow key prefix, if not already bound. bind_arrow_keys() # Enable the meta key, if this terminal has one. if @_rl_enable_meta () end # If the completion parser's default word break characters haven't # been set yet, then do so now. @rl_completer_word_break_characters ||= @rl_basic_word_break_characters end |
.readline_internal ⇒ Object
Read a line of input from the global rl_instream, doing output on
the global rl_outstream.
If rl_prompt is non-null, then that is our prompt.
4704 4705 4706 4707 4708 |
# File 'lib/rbreadline.rb', line 4704 def readline_internal() readline_internal_setup() eof = readline_internal_charloop() readline_internal_teardown(eof) end |
.readline_internal_charloop ⇒ Object
4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 |
# File 'lib/rbreadline.rb', line 4593 def readline_internal_charloop() lastc = -1 eof_found = false while (!@rl_done) lk = @_rl_last_command_was_kill # send(rl_redisplay_function) # @_rl_want_redisplay = false if (@rl_pending_input == 0) # Then initialize the argument and number of keys read. _rl_reset_argument() @rl_key_sequence_length = 0 end rl_setstate(RL_STATE_READCMD) c = rl_read_key() rl_unsetstate(RL_STATE_READCMD) # look at input.c:rl_getc() for the circumstances under which this will #be returned; punt immediately on read error without converting it to #a newline. if (c == READERR) eof_found = true break end # EOF typed to a non-blank line is a <NL>. if (c == EOF && @rl_end!=0) c = NEWLINE end # The character _rl_eof_char typed to blank line, and not as the #previous character is interpreted as EOF. if (((c == @_rl_eof_char && lastc != c) || c == EOF) && @rl_end==0) eof_found = true break end lastc = c if _rl_dispatch(c, @_rl_keymap)== -1 next end # If there was no change in _rl_last_command_was_kill, then no kill #has taken place. Note that if input is pending we are reading #a prefix command, so nothing has changed yet. if (@rl_pending_input == 0 && lk == @_rl_last_command_was_kill) @_rl_last_command_was_kill = false end _rl_internal_char_cleanup() end eof_found end |
.readline_internal_setup ⇒ Object
3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 |
# File 'lib/rbreadline.rb', line 3850 def readline_internal_setup() @_rl_in_stream = @rl_instream @_rl_out_stream = @rl_outstream if (@rl_startup_hook) send(@rl_startup_hook) end # If we're not echoing, we still want to at least print a prompt, because # rl_redisplay will not do it for us. If the calling application has a # custom redisplay function, though, let that function handle it. if (!@readline_echoing_p && @rl_redisplay_function == :rl_redisplay) if (@rl_prompt && !@rl_already_prompted) nprompt = _rl_strip_prompt(@rl_prompt) @_rl_out_stream.write(nprompt) @_rl_out_stream.flush end else if (@rl_prompt && @rl_already_prompted) rl_on_new_line_with_prompt() else rl_on_new_line() end send(@rl_redisplay_function) end if (@rl_editing_mode == @vi_mode) rl_vi_insertion_mode(1, 'i') end if (@rl_pre_input_hook) send(@rl_pre_input_hook) end end |
.readline_internal_teardown(eof) ⇒ Object
4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 |
# File 'lib/rbreadline.rb', line 4675 def readline_internal_teardown(eof) # Restore the original of this history line, iff the line that we # are editing was originally in the history, AND the line has changed. entry = current_history() if (entry && @rl_undo_list) temp = @rl_line_buffer.delete(0.chr).dup rl_revert_line(1, 0) entry = replace_history_entry(where_history(), @rl_line_buffer, nil) entry = nil @rl_line_buffer = temp+0.chr temp = nil end # At any rate, it is highly likely that this line has an undo list. Get # rid of it now. if (@rl_undo_list) rl_free_undo_list() end # Restore normal cursor, if available. _rl_set_insert_mode(RL_IM_INSERT, 0) (eof ? nil : @rl_line_buffer.delete(0.chr)) end |
.redraw_prompt(t) ⇒ Object
Redraw the last line of a multi-line prompt that may possibly contain terminal escape sequences. Called with the cursor at column 0 of the line to draw the prompt on.
8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 |
# File 'lib/rbreadline.rb', line 8581 def redraw_prompt(t) oldp = @rl_display_prompt rl_save_prompt() @rl_display_prompt = t @local_prompt,@prompt_visible_length,@prompt_last_invisible,@prompt_invis_chars_first_line,@prompt_physical_chars = (t) @local_prompt_prefix = nil @local_prompt_len = @local_prompt ? @local_prompt.length : 0 rl_forced_update_display() @rl_display_prompt = oldp rl_restore_prompt() end |
.release_sigint ⇒ Object
6798 6799 6800 6801 6802 |
# File 'lib/rbreadline.rb', line 6798 def release_sigint() return if !@sigint_blocked #Signal.trap("INT",@sigint_proc) @sigint_blocked = false end |
.remove_duplicate_matches(matches) ⇒ Object
Filter out duplicates in MATCHES. This frees up the strings in
MATCHES.
6192 6193 6194 6195 6196 6197 6198 6199 6200 |
# File 'lib/rbreadline.rb', line 6192 def remove_duplicate_matches(matches) # Sort the items. # Sort the array without matches[0], since we need it to # stay in place no matter what. if matches.length>0 matches[1..-2] = matches[1..-2].sort.uniq end matches end |
.remove_history(which) ⇒ Object
Remove history element WHICH from the history. The removed
element is returned to you so you can free the line, data,
and containing structure.
6782 6783 6784 6785 6786 6787 6788 6789 6790 |
# File 'lib/rbreadline.rb', line 6782 def remove_history(which) if (which < 0 || which >= @history_length || @history_length == 0 || @the_history.nil?) return nil end return_value = @the_history[which] @the_history.delete_at(which) @history_length-=1 return_value end |
.replace_history_data(which, old, new) ⇒ Object
Replace the DATA in the specified history entries, replacing OLD with
NEW. WHICH says which one(s) to replace: WHICH == -1 means to replace
all of the history entries where entry->data == OLD; WHICH == -2 means
to replace the `newest' history entry where entry->data == OLD; and
WHICH >= 0 means to replace that particular history entry's data, as
long as it matches OLD.
4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 |
# File 'lib/rbreadline.rb', line 4911 def replace_history_data(which,old, new) new = new.dup if new if (which < -2 || which >= @history_length || @history_length == 0 || @the_history.nil?) return end if (which >= 0) entry = @the_history[which] if (entry && entry.data == old) entry.data = new end return end last = -1 for i in 0 ... @history_length entry = @the_history[i] if entry.nil? next end if (entry.data == old) last = i if (which == -1) entry.data = new end end end if (which == -2 && last >= 0) entry = @the_history[last] entry.data = new # XXX - we don't check entry->old end end |
.replace_history_entry(which, line, data) ⇒ Object
Make the history entry at WHICH have LINE and DATA. This returns
the old entry so you can dispose of the data. In the case of an
invalid WHICH, a NULL pointer is returned.
5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 |
# File 'lib/rbreadline.rb', line 5265 def replace_history_entry (which, line, data) if (which < 0 || which >= @history_length) return nil end temp = Struct.new(:line,:timestamp,:data).new old_value = @the_history[which] temp.line = line.delete(0.chr) temp.data = data temp. = old_value..dup @the_history[which] = temp old_value end |
.rl_abort(count, key) ⇒ Object
4664 4665 4666 |
# File 'lib/rbreadline.rb', line 4664 def rl_abort(count, key) _rl_abort_internal() end |
.rl_add_undo(what, start, _end, text) ⇒ Object
-
Remember how to undo something. Concatenate some undos if that seems right.
4795 4796 4797 4798 4799 |
# File 'lib/rbreadline.rb', line 4795 def rl_add_undo(what, start, _end, text) temp = alloc_undo_entry(what, start, _end, text) temp.next = @rl_undo_list @rl_undo_list = temp end |
.rl_alphabetic(c) ⇒ Object
5063 5064 5065 5066 5067 5068 5069 5070 |
# File 'lib/rbreadline.rb', line 5063 def rl_alphabetic(c) if c =~ /\w/ return true end return !!(@_rl_allow_pathname_alphabetic_chars && @pathname_alphabetic_chars[c]) end |
.rl_arrow_keys(count, c) ⇒ Object
5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 |
# File 'lib/rbreadline.rb', line 5394 def rl_arrow_keys(count, c) rl_setstate(RL_STATE_MOREINPUT) ch = rl_read_key() rl_unsetstate(RL_STATE_MOREINPUT) case (ch.upcase) when 'A' rl_get_previous_history(count, ch) when 'B' rl_get_next_history(count, ch) when 'C' rl_forward_byte(count, ch) when 'D' rl_backward_byte(count, ch) else rl_ding() end 0 end |
.rl_attempted_completion_function ⇒ Object
Returns the value of attribute rl_attempted_completion_function.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_attempted_completion_function @rl_attempted_completion_function end |
.rl_attempted_completion_function=(value) ⇒ Object
Sets the attribute rl_attempted_completion_function
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_attempted_completion_function=(value) @rl_attempted_completion_function = value end |
.rl_attempted_completion_over ⇒ Object
Returns the value of attribute rl_attempted_completion_over.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_attempted_completion_over @rl_attempted_completion_over end |
.rl_attempted_completion_over=(value) ⇒ Object
Sets the attribute rl_attempted_completion_over
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_attempted_completion_over=(value) @rl_attempted_completion_over = value end |
.rl_backward(count, key) ⇒ Object
Backwards compatibility.
5040 5041 5042 |
# File 'lib/rbreadline.rb', line 5040 def rl_backward(count, key) rl_backward_char(count, key) end |
.rl_backward_byte(count, key) ⇒ Object
Move backward COUNT bytes.
4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 |
# File 'lib/rbreadline.rb', line 4995 def rl_backward_byte(count, key) if (count < 0) return (rl_forward_byte(-count, key)) end if (count > 0) if (@rl_point < count) @rl_point = 0 rl_ding() else @rl_point -= count end end if (@rl_point < 0) @rl_point = 0 end 0 end |
.rl_backward_char(count, key) ⇒ Object
Move backward COUNT characters.
5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 |
# File 'lib/rbreadline.rb', line 5015 def rl_backward_char(count, key) if @rl_byte_oriented return (rl_backward_byte(count, key)) end if (count < 0) return (rl_forward_char(-count, key)) end if (count > 0) point = @rl_point while (count > 0 && point > 0) point = _rl_find_prev_mbchar(@rl_line_buffer, point, MB_FIND_NONZERO) count-=1 end if (count > 0) @rl_point = 0 rl_ding() else @rl_point = point end end 0 end |
.rl_backward_char_search(count, key) ⇒ Object
7571 7572 7573 |
# File 'lib/rbreadline.rb', line 7571 def rl_backward_char_search (count, key) _rl_char_search(count, BFIND, FFIND) end |
.rl_backward_kill_line(direction, ignore) ⇒ Object
Kill backwards to the start of the line. If DIRECTION is negative, kill
forwards to the line end instead.
6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 |
# File 'lib/rbreadline.rb', line 6983 def rl_backward_kill_line(direction, ignore) if (direction < 0) return (rl_kill_line(1, ignore)) else if (@rl_point==0) rl_ding() else orig_point = @rl_point rl_beg_of_line(1, ignore) if (@rl_point != orig_point) rl_kill_text(orig_point, @rl_point) end if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end end 0 end |
.rl_backward_kill_word(count, ignore) ⇒ Object
Rubout the word before point, placing it on the kill ring.
7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 |
# File 'lib/rbreadline.rb', line 7540 def rl_backward_kill_word(count, ignore) if (count < 0) return (rl_kill_word(-count, ignore)) else orig_point = @rl_point rl_backward_word(count, ignore) if (@rl_point != orig_point) rl_kill_text(orig_point, @rl_point) end if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end 0 end |
.rl_backward_word(count, key) ⇒ Object
Move backward a word. We do what Emacs does. Handles multibyte chars.
5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 |
# File 'lib/rbreadline.rb', line 5132 def rl_backward_word(count, key) if (count < 0) return (rl_forward_word(-count, key)) end while (count>0) return 0 if (@rl_point == 0) # Like rl_forward_word (), except that we look at the characters # just before point. _p = !@rl_byte_oriented ? _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO):(@rl_point-1) c = _rl_char_value(@rl_line_buffer, _p) if (!_rl_walphabetic(c)) @rl_point = _p while (@rl_point > 0) _p = !@rl_byte_oriented ? _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO):(@rl_point-1) c = _rl_char_value(@rl_line_buffer, _p) if (_rl_walphabetic(c)) break end @rl_point = _p end end while (@rl_point>0) _p = !@rl_byte_oriented ? _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO):(@rl_point-1) c = _rl_char_value(@rl_line_buffer, _p) if (!_rl_walphabetic(c)) break else @rl_point = _p end end count -= 1 end 0 end |
.rl_basic_quote_characters ⇒ Object
Returns the value of attribute rl_basic_quote_characters.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_basic_quote_characters @rl_basic_quote_characters end |
.rl_basic_quote_characters=(value) ⇒ Object
Sets the attribute rl_basic_quote_characters
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_basic_quote_characters=(value) @rl_basic_quote_characters = value end |
.rl_basic_word_break_characters ⇒ Object
Returns the value of attribute rl_basic_word_break_characters.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_basic_word_break_characters @rl_basic_word_break_characters end |
.rl_basic_word_break_characters=(value) ⇒ Object
Sets the attribute rl_basic_word_break_characters
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_basic_word_break_characters=(value) @rl_basic_word_break_characters = value end |
.rl_beg_of_line(count, key) ⇒ Object
Move to the beginning of the line.
5045 5046 5047 5048 |
# File 'lib/rbreadline.rb', line 5045 def rl_beg_of_line(count, key) @rl_point = 0 0 end |
.rl_begin_undo_group ⇒ Object
Begin a group. Subsequent undos are undone as an atomic operation.
4862 4863 4864 4865 4866 |
# File 'lib/rbreadline.rb', line 4862 def rl_begin_undo_group() rl_add_undo(UNDO_BEGIN, 0, 0, nil) @_rl_undo_group_level+=1 0 end |
.rl_beginning_of_history(count, key) ⇒ Object
Meta-< goes to the start of the history.
7703 7704 7705 |
# File 'lib/rbreadline.rb', line 7703 def rl_beginning_of_history(count, key) rl_get_previous_history(1 + where_history(), key) end |
.rl_bind_key(key, function) ⇒ Object
Bind KEY to FUNCTION. Returns non-zero if KEY is out of range.
2370 2371 2372 2373 2374 |
# File 'lib/rbreadline.rb', line 2370 def rl_bind_key(key, function) @_rl_keymap[key] = function @rl_binding_keymap = @_rl_keymap 0 end |
.rl_bind_keyseq_if_unbound(keyseq, default_func) ⇒ Object
1926 1927 1928 |
# File 'lib/rbreadline.rb', line 1926 def rl_bind_keyseq_if_unbound(keyseq, default_func) rl_bind_keyseq_if_unbound_in_map(keyseq, default_func, @_rl_keymap) end |
.rl_bind_keyseq_if_unbound_in_map(keyseq, default_func, kmap) ⇒ Object
Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
now, this is always used to attempt to bind the arrow keys, hence the
check for rl_vi_movement_mode.
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 |
# File 'lib/rbreadline.rb', line 1914 def rl_bind_keyseq_if_unbound_in_map(keyseq, default_func, kmap) if (keyseq) func = rl_function_of_keyseq(keyseq, kmap, nil) if (func.nil? || func == :rl_vi_movement_mode) return (rl_bind_keyseq_in_map(keyseq, default_func, kmap)) else return 1 end end 0 end |
.rl_bind_keyseq_in_map(keyseq, function, map) ⇒ Object
Bind the key sequence represented by the string KEYSEQ to
FUNCTION. This makes new keymaps as necessary. The initial
place to do bindings is in MAP.
1906 1907 1908 |
# File 'lib/rbreadline.rb', line 1906 def rl_bind_keyseq_in_map(keyseq, function, map) rl_generic_bind(ISFUNC, keyseq, function, map) end |
.rl_capitalize_word(count, key) ⇒ Object
Upcase the first letter, downcase the rest.
7726 7727 7728 |
# File 'lib/rbreadline.rb', line 7726 def rl_capitalize_word(count, key) rl_change_case(count, CapCase) end |
.rl_change_case(count, op) ⇒ Object
The meaty function.
Change the case of COUNT words, performing OP on them.
OP is one of UpCase, DownCase, or CapCase.
If a negative argument is given, leave point where it started,
otherwise, leave it where it moves to.
7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 |
# File 'lib/rbreadline.rb', line 7751 def rl_change_case(count, op) start = @rl_point rl_forward_word(count, 0) _end = @rl_point if (op != UpCase && op != DownCase && op != CapCase) rl_ding() return -1 end if (count < 0) start,_end = _end,start end # We are going to modify some text, so let's prepare to undo it. (start, _end) inword = false while (start < _end) c = _rl_char_value(@rl_line_buffer, start) # This assumes that the upper and lower case versions are the same width. if !@rl_byte_oriented _next = _rl_find_next_mbchar(@rl_line_buffer, start, 1, MB_FIND_NONZERO) else _next = start + 1 end if (!_rl_walphabetic(c)) inword = false start = _next next end if (op == CapCase) nop = inword ? DownCase : UpCase inword = true else nop = op end if (isascii(c)) nc = (nop == UpCase) ? c.upcase : c.downcase @rl_line_buffer[start] = nc end start = _next end @rl_point = _end 0 end |
.rl_char_search(count, key) ⇒ Object
7441 7442 7443 |
# File 'lib/rbreadline.rb', line 7441 def rl_char_search(count, key) _rl_char_search(count, FFIND, BFIND) end |
.rl_character_len(c, pos) ⇒ Object
5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 |
# File 'lib/rbreadline.rb', line 5643 def rl_character_len(c, pos) if ((c)) return ((!@_rl_output_meta_chars) ? 4 : 1) end if (c == "\t") return (((pos | 7) + 1) - pos) end if (ctrl_char(c) || c == RUBOUT) return (2) end return ((isprint(c)) ? 1 : 2) end |
.rl_cleanup_after_signal ⇒ Object
Clean up the terminal and readline state after catching a signal, before
resending it to the calling application.
1491 1492 1493 1494 1495 1496 1497 1498 |
# File 'lib/rbreadline.rb', line 1491 def rl_cleanup_after_signal() _rl_clean_up_for_exit() if (@rl_deprep_term_function) send(@rl_deprep_term_function) end rl_clear_pending_input() rl_clear_signals() end |
.rl_clear_message ⇒ Object
How to clear things from the “echo-area”.
4158 4159 4160 4161 4162 4163 4164 4165 4166 |
# File 'lib/rbreadline.rb', line 4158 def () @rl_display_prompt = @rl_prompt if (@msg_saved_prompt) rl_restore_prompt() @msg_saved_prompt = nil end send(@rl_redisplay_function) 0 end |
.rl_clear_pending_input ⇒ Object
Clear any pending input pushed with rl_execute_next()
1628 1629 1630 1631 1632 |
# File 'lib/rbreadline.rb', line 1628 def rl_clear_pending_input() @rl_pending_input = 0 rl_unsetstate(RL_STATE_INPUTPENDING) 0 end |
.rl_clear_screen(count, key) ⇒ Object
C-l typed to a line without quoting clears the screen, and then reprints
the prompt and the current input line. Given a numeric arg, redraw only
the current line.
5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 |
# File 'lib/rbreadline.rb', line 5218 def rl_clear_screen(count, key) if (@rl_explicit_arg) rl_refresh_line(count, key) return 0 end _rl_clear_screen() # calls termcap function to clear screen rl_forced_update_display() @rl_display_fixed = true 0 end |
.rl_clear_signals ⇒ Object
1638 1639 1640 1641 1642 |
# File 'lib/rbreadline.rb', line 1638 def rl_clear_signals() if Signal.list['WINCH'] trap "WINCH",@def_proc end end |
.rl_complete(ignore, invoking_key) ⇒ Object
Complete the word at or before point. You have supplied the function
that does the initial simple matching selection algorithm (see
rl_completion_matches ()). The default is to do filename completion.
6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 |
# File 'lib/rbreadline.rb', line 6743 def rl_complete(ignore, invoking_key) if (@rl_inhibit_completion) return (_rl_insert_char(ignore, invoking_key)) elsif (@rl_last_func == :rl_complete && !@completion_changed_buffer) return (rl_complete_internal('?')) elsif (@_rl_complete_show_all) return (rl_complete_internal('!')) elsif (@_rl_complete_show_unmodified) return (rl_complete_internal('@')) else return (rl_complete_internal(TAB)) end end |
.rl_complete_internal(what_to_do) ⇒ Object
Complete the word at or before point.
WHAT_TO_DO says what to do with the completion.
`?' means list the possible completions.
TAB means do standard completion.
`*' means insert all of the possible completions.
`!' means to do standard completion, and list all possible completions if
there is more than one.
`@' means to do standard completion, and list all possible completions if
there is more than one and partial completion is not possible.
6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 |
# File 'lib/rbreadline.rb', line 6640 def rl_complete_internal(what_to_do) rl_setstate(RL_STATE_COMPLETING) set_completion_defaults(what_to_do) saved_line_buffer = @rl_line_buffer ? @rl_line_buffer.delete(0.chr) : nil our_func = @rl_completion_entry_function ? @rl_completion_entry_function : :rl_filename_completion_function # We now look backwards for the start of a filename/variable word. _end = @rl_point found_quote = false delimiter = 0.chr quote_char = 0.chr if (@rl_point!=0) # This (possibly) changes rl_point. If it returns a non-zero char, # we know we have an open quote. quote_char,found_quote,delimiter = _rl_find_completion_word() end start = @rl_point @rl_point = _end text = rl_copy_text(start, _end) matches = gen_completion_matches(text, start, _end, our_func, found_quote, quote_char) # nontrivial_lcd is set if the common prefix adds something to the word # being completed. nontrivial_lcd = !!(matches && text != matches[0]) text = nil if matches.nil? rl_ding() saved_line_buffer = nil @completion_changed_buffer = false rl_unsetstate(RL_STATE_COMPLETING) return 0 end # If we are matching filenames, the attempted completion function will # have set rl_filename_completion_desired to a non-zero value. The basic # rl_filename_completion_function does this. i = @rl_filename_completion_desired if (postprocess_matches(matches, i) == 0) rl_ding() saved_line_buffer = nil @completion_changed_buffer = false rl_unsetstate(RL_STATE_COMPLETING) return 0 end case (what_to_do) when TAB,'!','@' # Insert the first match with proper quoting. if (matches[0]) insert_match(matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, quote_char) end # If there are more matches, ring the bell to indicate. # If we are in vi mode, Posix.2 says to not ring the bell. # If the `show-all-if-ambiguous' variable is set, display # all the matches immediately. Otherwise, if this was the # only match, and we are hacking files, check the file to # see if it was a directory. If so, and the `mark-directories' # variable is set, add a '/' to the name. If not, and we # are at the end of the line, then add a space. if (matches[1]) if (what_to_do == '!') display_matches(matches) elsif (what_to_do == '@') if (!nontrivial_lcd) display_matches(matches) end elsif (@rl_editing_mode != @vi_mode) rl_ding() # There are other matches remaining. end else append_to_match(matches[0], delimiter, quote_char, nontrivial_lcd) end when '*' insert_all_matches(matches, start, quote_char) when '?' display_matches(matches) else $stderr.write("\r\nreadline: bad value #{what_to_do} for what_to_do in rl_complete\n") rl_ding() saved_line_buffer = nil rl_unsetstate(RL_STATE_COMPLETING) return 1 end matches = nil # Check to see if the line has changed through all of this manipulation. if (saved_line_buffer) @completion_changed_buffer = @rl_line_buffer.delete(0.chr) != saved_line_buffer saved_line_buffer = nil end rl_unsetstate(RL_STATE_COMPLETING) 0 end |
.rl_completer_quote_characters ⇒ Object
Returns the value of attribute rl_completer_quote_characters.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completer_quote_characters @rl_completer_quote_characters end |
.rl_completer_quote_characters=(value) ⇒ Object
Sets the attribute rl_completer_quote_characters
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completer_quote_characters=(value) @rl_completer_quote_characters = value end |
.rl_completer_word_break_characters ⇒ Object
Returns the value of attribute rl_completer_word_break_characters.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completer_word_break_characters @rl_completer_word_break_characters end |
.rl_completer_word_break_characters=(value) ⇒ Object
Sets the attribute rl_completer_word_break_characters
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completer_word_break_characters=(value) @rl_completer_word_break_characters = value end |
.rl_completion_append_character ⇒ Object
Returns the value of attribute rl_completion_append_character.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completion_append_character @rl_completion_append_character end |
.rl_completion_append_character=(value) ⇒ Object
Sets the attribute rl_completion_append_character
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_completion_append_character=(value) @rl_completion_append_character = value end |
.rl_completion_matches(text, entry_function) ⇒ Object
Return an array of (char *) which is a list of completions for TEXT.
If there are no completions, return a NULL pointer.
The first entry in the returned array is the substitution for TEXT.
The remaining entries are the possible completions.
The array is terminated with a NULL pointer.
ENTRY_FUNCTION is a function of two args, and returns a (char *).
The first argument is TEXT.
The second is a state argument it should be zero on the first call, and
non-zero on subsequent calls. It returns a NULL pointer to the caller
when there are no more matches.
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'lib/rbreadline.rb', line 1272 def rl_completion_matches(text, entry_function) matches = 0 match_list_size = 10 match_list = [] match_list[1] = nil while (string = send(entry_function, text, matches)) match_list[matches+=1] = string match_list[matches+1] = nil end # If there were any matches, then look through them finding out the # lowest common denominator. That then becomes match_list[0]. if (matches!=0) compute_lcd_of_matches(match_list, matches, text) else # There were no matches. match_list = nil end return (match_list) end |
.rl_copy_text(from, to) ⇒ Object
4836 4837 4838 |
# File 'lib/rbreadline.rb', line 4836 def rl_copy_text(from, to) return @rl_line_buffer[from...to] end |
.rl_crlf ⇒ Object
Move to the start of the next line.
4544 4545 4546 4547 4548 4549 4550 |
# File 'lib/rbreadline.rb', line 4544 def rl_crlf() if (@_rl_term_cr) @_rl_out_stream.write(@_rl_term_cr) end @_rl_out_stream.write("\n") return 0 end |
.rl_delete(count, key) ⇒ Object
Delete the character under the cursor. Given a numeric argument,
kill that many characters instead.
5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 |
# File 'lib/rbreadline.rb', line 5753 def rl_delete(count, key) if (count < 0) return (_rl_rubout_char(-count, key)) end if (@rl_point == @rl_end) rl_ding() return -1 end if (count > 1 || @rl_explicit_arg) xpoint = @rl_point rl_forward_byte(count, key) rl_kill_text(xpoint, @rl_point) @rl_point = xpoint else if !@rl_byte_oriented xpoint =_rl_find_next_mbchar(@rl_line_buffer, @rl_point, 1, MB_FIND_NONZERO) else xpoint = @rl_point + 1 end rl_delete_text(@rl_point, xpoint) end 0 end |
.rl_delete_horizontal_space(count, ignore) ⇒ Object
Delete all spaces and tabs around point.
5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 |
# File 'lib/rbreadline.rb', line 5925 def rl_delete_horizontal_space(count, ignore) start = @rl_point while (@rl_point!=0 && whitespace(@rl_line_buffer[@rl_point - 1])) @rl_point-=1 end start = @rl_point while (@rl_point < @rl_end && whitespace(@rl_line_buffer[@rl_point])) @rl_point+=1 end if (start != @rl_point) rl_delete_text(start, @rl_point) @rl_point = start end if (@rl_point < 0) @rl_point = 0 end 0 end |
.rl_delete_or_show_completions(count, key) ⇒ Object
Like the tcsh editing function delete-char-or-list. The eof character
is caught before this is invoked, so this really does the same thing as
delete-char-or-list-or-eof, as long as it's bound to the eof character.
5953 5954 5955 5956 5957 5958 5959 |
# File 'lib/rbreadline.rb', line 5953 def rl_delete_or_show_completions(count, key) if (@rl_end != 0 && @rl_point == @rl_end) return (rl_possible_completions(count, key)) else return (rl_delete(count, key)) end end |
.rl_delete_text(from, to) ⇒ Object
Delete the string between FROM and TO. FROM is inclusive, TO is not.
Returns the number of characters deleted.
4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 |
# File 'lib/rbreadline.rb', line 4804 def rl_delete_text(from, to) # Fix it if the caller is confused. if (from > to) from,to = to,from end # fix boundaries if (to > @rl_end) to = @rl_end if (from > to) from = to end end if (from < 0) from = 0 end text = rl_copy_text(from, to) diff = to - from @rl_line_buffer[from...to] = '' @rl_line_buffer << 0.chr * diff # Remember how to undo this delete. if (!@_rl_doing_an_undo) rl_add_undo(UNDO_DELETE, from, to, text) else text = nil end @rl_end -= diff @rl_line_buffer[@rl_end] = 0.chr return (diff) end |
.rl_deprep_term_function ⇒ Object
Returns the value of attribute rl_deprep_term_function.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_deprep_term_function @rl_deprep_term_function end |
.rl_deprep_term_function=(value) ⇒ Object
Sets the attribute rl_deprep_term_function
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_deprep_term_function=(value) @rl_deprep_term_function = value end |
.rl_deprep_terminal ⇒ Object
Restore the terminal’s normal settings and modes.
6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 |
# File 'lib/rbreadline.rb', line 6928 def rl_deprep_terminal() return if ENV["TERM"].nil? return if (!@terminal_prepped) # Try to keep this function from being interrupted. block_sigint() if (@_rl_enable_keypad) _rl_control_keypad(false) end @rl_outstream.flush # restore terminal setting `stty #{@otio}` @terminal_prepped = false rl_unsetstate(RL_STATE_TERMPREPPED) release_sigint() end |
.rl_digit_argument(ignore, key) ⇒ Object
Start a numeric argument with initial value KEY
7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 |
# File 'lib/rbreadline.rb', line 7683 def rl_digit_argument(ignore, key) _rl_arg_init() if (rl_isstate(RL_STATE_CALLBACK)) _rl_arg_dispatch(@_rl_argcxt, key) ("(arg: #{@rl_arg_sign * @rl_numeric_arg}) ") return 0 else rl_execute_next(key) return (rl_digit_loop()) end end |
.rl_digit_loop ⇒ Object
Handle C-u style numeric args, as well as M–, and M-digits.
7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 |
# File 'lib/rbreadline.rb', line 7667 def rl_digit_loop() while (true) return 1 if _rl_arg_overflow()!=0 c = _rl_arg_getchar() if (c >= "\xFE") _rl_abort_internal() return -1 end r = _rl_arg_dispatch(@_rl_argcxt, c) break if (r <= 0 || !rl_isstate(RL_STATE_NUMERICARG)) end return r end |
.rl_ding ⇒ Object
Ring the terminal bell.
3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 |
# File 'lib/rbreadline.rb', line 3892 def rl_ding() if @MessageBeep @MessageBeep.Call(0) elsif @readline_echoing_p if @_rl_bell_preference == VISIBLE_BELL if (@_rl_visible_bell) @_rl_out_stream.write(@_rl_visible_bell.chr) else $stderr.write("\007") $stderr.flush end elsif @_rl_bell_preference == AUDIBLE_BELL $stderr.write("\007") $stderr.flush end return 0 end return -1 end |
.rl_display_match_list(matches, len, max) ⇒ Object
A convenience function for displaying a list of strings in
columnar format on readline's output stream. MATCHES is the list
of strings, in argv format, LEN is the number of strings in MATCHES,
and MAX is the length of the longest string in MATCHES.
8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 |
# File 'lib/rbreadline.rb', line 8170 def rl_display_match_list(matches, len, max) # How many items of MAX length can we fit in the screen window? max += 2 limit = @_rl_screenwidth / max if (limit != 1 && (limit * max == @_rl_screenwidth)) limit-=1 end # Avoid a possible floating exception. If max > _rl_screenwidth, # limit will be 0 and a divide-by-zero fault will result. if (limit == 0) limit = 1 end # How many iterations of the printing loop? count = (len + (limit - 1)) / limit # Watch out for special case. If LEN is less than LIMIT, then # just do the inner printing loop. # 0 < len <= limit implies count = 1. # Sort the items if they are not already sorted. if (!@rl_ignore_completion_duplicates) matches[1,len] = matches[1,len].sort end rl_crlf() lines = 0 if (!@_rl_print_completions_horizontally) # Print the sorted items, up-and-down alphabetically, like ls. for i in 1 .. count l = i for j in 0 ... limit if (l > len || matches[l].nil?) break else temp = printable_part(matches[l]) printed_len = print_filename(temp, matches[l]) if (j + 1 < limit) @rl_outstream.write(' '*(max - printed_len)) end end l += count end rl_crlf() lines+=1 if (@_rl_page_completions && lines >= (@_rl_screenheight - 1) && i < count) lines = _rl_internal_pager(lines) return if (lines < 0) end end else # Print the sorted items, across alphabetically, like ls -x. i = 1 while(matches[i]) temp = printable_part(matches[i]) printed_len = print_filename(temp, matches[i]) # Have we reached the end of this line? if (matches[i+1]) if ((limit > 1) && (i % limit) == 0) rl_crlf() lines+=1 if (@_rl_page_completions && lines >= @_rl_screenheight - 1) lines = _rl_internal_pager(lines) return if (lines < 0) end else @rl_outstream.write(' '*(max - printed_len)) end end i += 1 end rl_crlf() end end |
.rl_display_search(search_string, reverse_p, where) ⇒ Object
Display the current state of the search in the echo-area.
SEARCH_STRING contains the string that is being searched for,
DIRECTION is zero for forward, or non-zero for reverse,
WHERE is the history list number of the current line. If it is
-1, then this line is the starting one.
7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 |
# File 'lib/rbreadline.rb', line 7207 def rl_display_search(search_string, reverse_p, where) = '(' if (reverse_p) << "reverse-" end << "i-search)`" if (search_string) << search_string end << "': " () = nil send(@rl_redisplay_function) end |
.rl_do_lowercase_version(ignore1, ignore2) ⇒ Object
What to do for some uppercase characters, like meta characters,
and some characters appearing in emacs_ctlx_keymap. This function
is just a stub, you bind keys to it and the code in _rl_dispatch ()
is special cased.
5639 5640 5641 |
# File 'lib/rbreadline.rb', line 5639 def rl_do_lowercase_version(ignore1, ignore2) 0 end |
.rl_do_undo ⇒ Object
7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 |
# File 'lib/rbreadline.rb', line 7451 def rl_do_undo() start = _end = waiting_for_begin = 0 begin return 0 if @rl_undo_list.nil? @_rl_doing_an_undo = true rl_setstate(RL_STATE_UNDOING) # To better support vi-mode, a start or end value of -1 means # rl_point, and a value of -2 means rl_end. if (@rl_undo_list.what == UNDO_DELETE || @rl_undo_list.what == UNDO_INSERT) start = trans(@rl_undo_list.start) _end = trans(@rl_undo_list.end) end case (@rl_undo_list.what) # Undoing deletes means inserting some text. when UNDO_DELETE @rl_point = start rl_insert_text(@rl_undo_list.text) @rl_undo_list.text = nil # Undoing inserts means deleting some text. when UNDO_INSERT rl_delete_text(start, _end) @rl_point = start # Undoing an END means undoing everything 'til we get to a BEGIN. when UNDO_END waiting_for_begin+=1 # Undoing a BEGIN means that we are done with this group. when UNDO_BEGIN if (waiting_for_begin!=0) waiting_for_begin-=1 else rl_ding() end end @_rl_doing_an_undo = false rl_unsetstate(RL_STATE_UNDOING) release = @rl_undo_list @rl_undo_list = @rl_undo_list.next replace_history_data(-1, release, @rl_undo_list) release = nil end while (waiting_for_begin!=0) 1 end |
.rl_downcase_word(count, key) ⇒ Object
Lowercase the word at point.
7721 7722 7723 |
# File 'lib/rbreadline.rb', line 7721 def rl_downcase_word(count, key) rl_change_case(count, DownCase) end |
.rl_emacs_editing_mode(count, key) ⇒ Object
1423 1424 1425 1426 1427 1428 |
# File 'lib/rbreadline.rb', line 1423 def rl_emacs_editing_mode(count, key) @rl_editing_mode = @emacs_mode _rl_set_insert_mode(RL_IM_INSERT, 1) # emacs mode default is insert mode @_rl_keymap = @emacs_standard_keymap 0 end |
.rl_end_of_history(count, key) ⇒ Object
Meta-> goes to the end of the history. (The current line).
7708 7709 7710 7711 7712 7713 |
# File 'lib/rbreadline.rb', line 7708 def rl_end_of_history(count, key) rl_maybe_replace_line() using_history() rl_maybe_unsave_line() 0 end |
.rl_end_of_line(count, key) ⇒ Object
Move to the end of the line.
5051 5052 5053 5054 |
# File 'lib/rbreadline.rb', line 5051 def rl_end_of_line(count, key) @rl_point = @rl_end 0 end |
.rl_end_undo_group ⇒ Object
End an undo group started with rl_begin_undo_group ().
4869 4870 4871 4872 4873 |
# File 'lib/rbreadline.rb', line 4869 def rl_end_undo_group() rl_add_undo(UNDO_END, 0, 0, nil) @_rl_undo_group_level-=1 0 end |
.rl_event_hook ⇒ Object
Returns the value of attribute rl_event_hook.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_event_hook @rl_event_hook end |
.rl_event_hook=(value) ⇒ Object
Sets the attribute rl_event_hook
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_event_hook=(value) @rl_event_hook = value end |
.rl_exchange_point_and_mark(count, key) ⇒ Object
Exchange the position of mark and point.
8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 |
# File 'lib/rbreadline.rb', line 8153 def rl_exchange_point_and_mark(count, key) if (@rl_mark > @rl_end) @rl_mark = -1 end if (@rl_mark == -1) rl_ding() return -1 else @rl_point, @rl_mark = @rl_mark, @rl_point end 0 end |
.rl_execute_next(c) ⇒ Object
Make C be the next command to be executed.
7696 7697 7698 7699 7700 |
# File 'lib/rbreadline.rb', line 7696 def rl_execute_next(c) @rl_pending_input = c rl_setstate(RL_STATE_INPUTPENDING) 0 end |
.rl_expand_prompt(prompt) ⇒ Object
*
-
Expand the prompt string into the various display components, if
-
necessary.
*
-
local_prompt = expanded last line of string in rl_display_prompt
-
(portion after the final newline)
-
local_prompt_prefix = portion before last newline of rl_display_prompt,
-
expanded via expand_prompt
-
prompt_visible_length = number of visible characters in local_prompt
-
prompt_prefix_length = number of visible characters in local_prompt_prefix
*
-
This function is called once per call to readline(). It may also be
-
called arbitrarily to expand the primary prompt.
*
-
The return value is the number of visible characters on the last line
-
of the (possibly multi-line) prompt.
*
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 |
# File 'lib/rbreadline.rb', line 1751 def (prompt) @local_prompt = @local_prompt_prefix = nil @local_prompt_len = 0 @prompt_last_invisible = @prompt_invis_chars_first_line = 0 @prompt_visible_length = @prompt_physical_chars = 0 if (prompt.nil? || prompt == '') return (0) end pi = prompt.rindex("\n") if pi.nil? # The prompt is only one logical line, though it might wrap. @local_prompt,@prompt_visible_length,@prompt_last_invisible,@prompt_invis_chars_first_line,@prompt_physical_chars = (prompt) @local_prompt_prefix = nil @local_prompt_len = @local_prompt ? @local_prompt.length : 0 return (@prompt_visible_length) else # The prompt spans multiple lines. pi += 1 if prompt.length!=pi+1 t = pi @local_prompt,@prompt_visible_length,@prompt_last_invisible,_,@prompt_physical_chars = (prompt[pi..-1]) c = prompt[t] prompt[t] = 0.chr # The portion of the prompt string up to and including the #final newline is now null-terminated. @local_prompt_prefix,@prompt_prefix_length,_,@prompt_invis_chars_first_line, = (prompt) prompt[t] = c @local_prompt_len = @local_prompt ? @local_prompt.length : 0 return (@prompt_prefix_length) end end |
.rl_extend_line_buffer(len) ⇒ Object
Increase the size of RL_LINE_BUFFER until it has enough space to hold
LEN characters.
4740 4741 4742 4743 4744 4745 |
# File 'lib/rbreadline.rb', line 4740 def rl_extend_line_buffer(len) while (len >= @rl_line_buffer.length) @rl_line_buffer << 0.chr * DEFAULT_BUFFER_SIZE end @the_line = @rl_line_buffer end |
.rl_filename_completion_function(text, state) ⇒ Object
Okay, now we write the entry_function for filename completion. In the
general case. Note that completion in the shell is a little different
because of all the pathnames that must be followed when looking up the
completion for a command.
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'lib/rbreadline.rb', line 1109 def rl_filename_completion_function(text, state) # If we don't have any state, then do some initialization. if (state == 0) # If we were interrupted before closing the directory or reading #all of its contents, close it. if(@directory) @directory.close @directory = nil end text.delete!(0.chr) @filename = text.dup if text.length == 0 text = "." end @dirname = File.dirname(text) # We aren't done yet. We also support the "~user" syntax. # Save the version of the directory that the user typed. @users_dirname = @dirname.dup if (@dirname[0] == ?~) @dirname = File.(@dirname) end # The directory completion hook should perform any necessary # dequoting. if (@rl_directory_completion_hook && send(rl_directory_completion_hook,@dirname)) @users_dirname = @dirname.dup elsif (@rl_completion_found_quote && @rl_filename_dequoting_function) # delete single and double quotes @temp = send(@rl_filename_dequoting_function,@users_dirname, @rl_completion_quote_character) @users_dirname = temp end @directory = Dir.new(@dirname) # Now dequote a non-null filename. if (@filename && @filename.length>0 && @rl_completion_found_quote && @rl_filename_dequoting_function) # delete single and double quotes temp = send(@rl_filename_dequoting_function,@filename, @rl_completion_quote_character) @filename = temp end @filename_len = @filename.length @rl_filename_completion_desired = true end # At this point we should entertain the possibility of hacking wildcarded # filenames, like /usr/man/man<WILD>/te<TAB>. If the directory name # contains globbing characters, then build an array of directories, and # then map over that list while completing. # *** UNIMPLEMENTED *** # Now that we have some state, we can read the directory. entry = nil while(@directory && (entry = @directory.read)) d_name = entry # Special case for no filename. If the user has disabled the # `match-hidden-files' variable, skip filenames beginning with `.'. #All other entries except "." and ".." match. if (@filename_len == 0) if (!@_rl_match_hidden_files && d_name[0]==?.) next end if (d_name != '.' && d_name != '..') break end else # Otherwise, if these match up to the length of filename, then # it is a match. if (@_rl_completion_case_fold) break if d_name =~ /^#{Regexp.escape(@filename)}/i else break if d_name =~ /^#{Regexp.escape(@filename)}/ end end end if entry.nil? if @directory @directory.close @directory = nil end @dirname = nil @filename = nil @users_dirname = nil return nil else if (@dirname != '.') if (@rl_complete_with_tilde_expansion && @users_dirname[0] == ?~) temp = @dirname if(temp[-1] != ?/) temp += '/' end else temp = @users_dirname if(temp[-1] != ?/) temp += '/' end end temp += entry else temp = entry.dup end return (temp) end end |
.rl_filename_quote_characters ⇒ Object
Returns the value of attribute rl_filename_quote_characters.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_filename_quote_characters @rl_filename_quote_characters end |
.rl_filename_quote_characters=(value) ⇒ Object
Sets the attribute rl_filename_quote_characters
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_filename_quote_characters=(value) @rl_filename_quote_characters = value end |
.rl_forced_update_display ⇒ Object
Actually update the display, period.
5189 5190 5191 5192 5193 5194 5195 5196 5197 |
# File 'lib/rbreadline.rb', line 5189 def rl_forced_update_display() if (@visible_line) @visible_line.gsub!(/[^\x00]/,0.chr) end rl_on_new_line() @forced_display=true if !@forced_display send(@rl_redisplay_function) 0 end |
.rl_forward(count, key) ⇒ Object
Backwards compatibility.
4990 4991 4992 |
# File 'lib/rbreadline.rb', line 4990 def rl_forward(count, key) rl_forward_char(count, key) end |
.rl_forward_byte(count, key) ⇒ Object
Move forward COUNT bytes.
4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 |
# File 'lib/rbreadline.rb', line 4944 def rl_forward_byte(count, key) if (count < 0) return (rl_backward_byte(-count, key)) end if (count > 0) _end = @rl_point + count lend = @rl_end > 0 ? @rl_end - ((@rl_editing_mode == @vi_mode)?1:0) : @rl_end if (_end > lend) @rl_point = lend rl_ding() else @rl_point = _end end end if (@rl_end < 0) @rl_end = 0 end return 0 end |
.rl_forward_char(count, key) ⇒ Object
Move forward COUNT characters.
4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 |
# File 'lib/rbreadline.rb', line 4966 def rl_forward_char(count, key) if @rl_byte_oriented return (rl_forward_byte(count, key)) end if (count < 0) return (rl_backward_char(-count, key)) end if (count > 0) point = _rl_find_next_mbchar(@rl_line_buffer, @rl_point, count, MB_FIND_NONZERO) if (@rl_end <= point && @rl_editing_mode == @vi_mode) point = _rl_find_prev_mbchar(@rl_line_buffer, @rl_end, MB_FIND_NONZERO) end if (@rl_point == point) rl_ding() end @rl_point = point if (@rl_end < 0) @rl_end = 0 end end 0 end |
.rl_forward_search_history(sign, key) ⇒ Object
Search forwards through the history looking for a string which is typed
interactively. Start with the current line.
7021 7022 7023 |
# File 'lib/rbreadline.rb', line 7021 def rl_forward_search_history(sign, key) rl_search_history(sign, key) end |
.rl_forward_word(count, key) ⇒ Object
Move forward a word. We do what Emacs does. Handles multibyte chars.
5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 |
# File 'lib/rbreadline.rb', line 5077 def rl_forward_word(count, key) if (count < 0) return (rl_backward_word(-count, key)) end while (count>0) return 0 if (@rl_point == @rl_end) # If we are not in a word, move forward until we are in one. # Then, move forward until we hit a non-alphabetic character. c = _rl_char_value(@rl_line_buffer, @rl_point) if (!_rl_walphabetic(c)) if !@rl_byte_oriented @rl_point = _rl_find_next_mbchar(@rl_line_buffer, @rl_point, 1, MB_FIND_NONZERO) else @rl_point += 1 end while (@rl_point < @rl_end) c = _rl_char_value(@rl_line_buffer, @rl_point) if (_rl_walphabetic(c)) break end if !@rl_byte_oriented @rl_point = _rl_find_next_mbchar(@rl_line_buffer, @rl_point, 1, MB_FIND_NONZERO) else @rl_point += 1 end end end return 0 if (@rl_point == @rl_end) if !@rl_byte_oriented @rl_point = _rl_find_next_mbchar(@rl_line_buffer, @rl_point, 1, MB_FIND_NONZERO) else @rl_point += 1 end while (@rl_point < @rl_end) c = _rl_char_value(@rl_line_buffer, @rl_point) if (!_rl_walphabetic(c)) break end if !@rl_byte_oriented @rl_point = _rl_find_next_mbchar(@rl_line_buffer, @rl_point, 1, MB_FIND_NONZERO) else @rl_point += 1 end end count -= 1 end 0 end |
.rl_free_undo_list ⇒ Object
4875 4876 4877 4878 |
# File 'lib/rbreadline.rb', line 4875 def rl_free_undo_list() replace_history_data(-1, @rl_undo_list, nil) @rl_undo_list = nil end |
.rl_function_of_keyseq(keyseq, map, type) ⇒ Object
Return the function (or macro) definition which would be invoked via
KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
used. TYPE, if non-NULL, is a pointer to an int which will receive the
type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
or ISMACR (macro).
1888 1889 1890 1891 |
# File 'lib/rbreadline.rb', line 1888 def rl_function_of_keyseq(keyseq, map, type) map ||= @_rl_keymap map[keyseq] end |
.rl_generic_bind(type, keyseq, data, map) ⇒ Object
Bind the key sequence represented by the string KEYSEQ to
the arbitrary pointer DATA. TYPE says what kind of data is
pointed to by DATA, right now this can be a function (ISFUNC),
a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
as necessary. The initial place to do bindings is in MAP.
1898 1899 1900 1901 |
# File 'lib/rbreadline.rb', line 1898 def rl_generic_bind(type, keyseq, data, map) map[keyseq] = data 0 end |
.rl_get_char ⇒ Object
Get a key from the buffer of characters to be read.
Return the key in KEY.
Result is KEY if there was a key, or 0 if there wasn't.
4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 |
# File 'lib/rbreadline.rb', line 4457 def rl_get_char() if (@push_index == @pop_index) return nil end key = @ibuffer[@pop_index] @pop_index += 1 if (@pop_index >= @ibuffer_len) @pop_index = 0 end return key end |
.rl_get_keymap_name_from_edit_mode ⇒ Object
2419 2420 2421 2422 2423 2424 2425 2426 2427 |
# File 'lib/rbreadline.rb', line 2419 def rl_get_keymap_name_from_edit_mode() if (@rl_editing_mode == @emacs_mode) "emacs" elsif (@rl_editing_mode == @vi_mode) "vi" else "none" end end |
.rl_get_next_history(count, key) ⇒ Object
Move down to the next history line.
5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 |
# File 'lib/rbreadline.rb', line 5363 def rl_get_next_history(count, key) if (count < 0) return (rl_get_previous_history(-count, key)) end if (count == 0) return 0 end rl_maybe_replace_line() # either not saved by rl_newline or at end of line, so set appropriately. if (@_rl_history_saved_point == -1 && (@rl_point!=0 || @rl_end!=0)) @_rl_history_saved_point = (@rl_point == @rl_end) ? -1 : @rl_point end temp = nil while (count>0) temp = next_history() if temp.nil? break end count -= 1 end if temp.nil? rl_maybe_unsave_line() else rl_replace_from_history(temp, 0) _rl_history_set_point() end 0 end |
.rl_get_previous_history(count, key) ⇒ Object
Get the previous item out of our interactive history, making it the current
line. If there is no previous history, just ding.
5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 |
# File 'lib/rbreadline.rb', line 5304 def rl_get_previous_history(count, key) if (count < 0) return (rl_get_next_history(-count, key)) end if (count == 0) return 0 end # either not saved by rl_newline or at end of line, so set appropriately. if (@_rl_history_saved_point == -1 && (@rl_point!=0 || @rl_end!=0)) @_rl_history_saved_point = (@rl_point == @rl_end) ? -1 : @rl_point end # If we don't have a line saved, then save this one. rl_maybe_save_line() # If the current line has changed, save the changes. rl_maybe_replace_line() temp = old_temp = nil while (count>0) temp = previous_history() if temp.nil? break end old_temp = temp count -= 1 end # If there was a large argument, and we moved back to the start of the # history, that is not an error. So use the last value found. if (temp.nil? && old_temp) temp = old_temp end if temp.nil? rl_ding() else rl_replace_from_history(temp, 0) _rl_history_set_point() end 0 end |
.rl_initialize ⇒ Object
Initialize readline (and terminal if not already).
3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 |
# File 'lib/rbreadline.rb', line 3721 def rl_initialize() # If we have never been called before, initialize the # terminal and data structures. if (!@rl_initialized) rl_setstate(RL_STATE_INITIALIZING) readline_initialize_everything() rl_unsetstate(RL_STATE_INITIALIZING) @rl_initialized = true rl_setstate(RL_STATE_INITIALIZED) end # Initalize the current line information. _rl_init_line_state() # We aren't done yet. We haven't even gotten started yet! @rl_done = false rl_unsetstate(RL_STATE_DONE) # Tell the history routines what is going on. _rl_start_using_history() # Make the display buffer match the state of the line. rl_reset_line_state() # No such function typed yet. @rl_last_func = nil # Parsing of key-bindings begins in an enabled state. @_rl_parsing_conditionalized_out = 0 if (@rl_editing_mode == @vi_mode) _rl_vi_initialize_line() end # Each line starts in insert mode (the default). _rl_set_insert_mode(RL_IM_DEFAULT, 1) return 0 end |
.rl_insert(count, c) ⇒ Object
5505 5506 5507 5508 |
# File 'lib/rbreadline.rb', line 5505 def rl_insert(count, c) ((@rl_insert_mode == RL_IM_INSERT) ? _rl_insert_char(count, c) : _rl_overwrite_char(count, c)) end |
.rl_insert_comment(count, key) ⇒ Object
Turn the current line into a comment in shell history.
A K*rn shell style function.
5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 |
# File 'lib/rbreadline.rb', line 5963 def rl_insert_comment(count, key) rl_beg_of_line(1, key) @rl_comment_text = @_rl_comment_begin ? @_rl_comment_begin : '#' if (!@rl_explicit_arg) rl_insert_text(@rl_comment_text) else @rl_comment_len = @rl_comment_text.length if @rl_comment_text[0,@rl_comment_len] == @rl_line_buffer[0,@rl_comment_len] rl_delete_text(@rl_point, @rl_point + @rl_comment_len) else rl_insert_text(@rl_comment_text) end end send(@rl_redisplay_function) rl_newline(1, "\n") 0 end |
.rl_insert_completions(ignore, invoking_key) ⇒ Object
7575 7576 7577 |
# File 'lib/rbreadline.rb', line 7575 def rl_insert_completions(ignore, invoking_key) rl_complete_internal('*') end |
.rl_insert_text(string) ⇒ Object
Insert a string of text into the line at point. This is the only
way that you should do insertion. _rl_insert_char () calls this
function. Returns the number of characters inserted.
4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 |
# File 'lib/rbreadline.rb', line 4750 def rl_insert_text(string) string.delete!(0.chr) l = string.length return 0 if (l == 0) if (@rl_end + l >= @rl_line_buffer.length) rl_extend_line_buffer(@rl_end + l) end @rl_line_buffer[@rl_point,0] = string # Remember how to undo this if we aren't undoing something. if (!@_rl_doing_an_undo) # If possible and desirable, concatenate the undos. if ((l == 1) && @rl_undo_list && (@rl_undo_list.what == UNDO_INSERT) && (@rl_undo_list.end == @rl_point) && (@rl_undo_list.end - @rl_undo_list.start < 20)) @rl_undo_list.end+=1 else rl_add_undo(UNDO_INSERT, @rl_point, @rl_point + l, nil) end end @rl_point += l @rl_end += l if @rl_line_buffer.length <= @rl_end @rl_line_buffer << 0.chr * (@rl_end - @rl_line_buffer.length + 1) else @rl_line_buffer[@rl_end] = "\0" end l end |
.rl_instream ⇒ Object
Returns the value of attribute rl_instream.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_instream @rl_instream end |
.rl_instream=(value) ⇒ Object
Sets the attribute rl_instream
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_instream=(value) @rl_instream = value end |
.rl_isstate(x) ⇒ Object
1623 1624 1625 |
# File 'lib/rbreadline.rb', line 1623 def rl_isstate(x) (@rl_readline_state & (x))!=0 end |
.rl_kill_full_line(count, ignore) ⇒ Object
Kill the whole line, no matter where point is.
7004 7005 7006 7007 7008 7009 7010 7011 |
# File 'lib/rbreadline.rb', line 7004 def rl_kill_full_line(count, ignore) rl_begin_undo_group() @rl_point = 0 rl_kill_text(@rl_point, @rl_end) @rl_mark = 0 rl_end_undo_group() 0 end |
.rl_kill_line(direction, ignore) ⇒ Object
Kill from here to the end of the line. If DIRECTION is negative, kill
back to the line start instead.
6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 |
# File 'lib/rbreadline.rb', line 6964 def rl_kill_line (direction, ignore) if (direction < 0) return (rl_backward_kill_line(1, ignore)) else orig_point = @rl_point rl_end_of_line(1, ignore) if (orig_point != @rl_point) rl_kill_text(orig_point, @rl_point) end @rl_point = orig_point if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end 0 end |
.rl_kill_text(from, to) ⇒ Object
The way to kill something. This appends or prepends to the last
kill, if the last command was a kill command. if FROM is less
than TO, then the text is appended, otherwise prepended. If the
last command was not a kill command, then a new slot is made for
this kill.
5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 |
# File 'lib/rbreadline.rb', line 5833 def rl_kill_text(from, to) # Is there anything to kill? if (from == to) @_rl_last_command_was_kill = true if !@_rl_last_command_was_kill return 0 end text = rl_copy_text(from, to) # Delete the copied text from the line. rl_delete_text(from, to) _rl_copy_to_kill_ring(text, from < to) @_rl_last_command_was_kill = true if !@_rl_last_command_was_kill 0 end |
.rl_kill_word(count, key) ⇒ Object
Delete the word at point, saving the text in the kill ring.
7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 |
# File 'lib/rbreadline.rb', line 7520 def rl_kill_word(count, key) if (count < 0) return (rl_backward_kill_word(-count, key)) else orig_point = @rl_point rl_forward_word(count, key) if (@rl_point != orig_point) rl_kill_text(orig_point, @rl_point) end @rl_point = orig_point if (@rl_editing_mode == @emacs_mode) rl_mark = @rl_point end end 0 end |
.rl_library_version ⇒ Object
Returns the value of attribute rl_library_version.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_library_version @rl_library_version end |
.rl_library_version=(value) ⇒ Object
Sets the attribute rl_library_version
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_library_version=(value) @rl_library_version = value end |
.rl_maybe_replace_line ⇒ Object
Perhaps put back the current line if it has changed.
5279 5280 5281 5282 5283 5284 5285 5286 |
# File 'lib/rbreadline.rb', line 5279 def rl_maybe_replace_line() temp = current_history() # If the current line has changed, save the changes. if (temp && temp.data != @rl_undo_list) temp = replace_history_entry(where_history(), @rl_line_buffer, @rl_undo_list) end 0 end |
.rl_maybe_save_line ⇒ Object
Save the current line in _rl_saved_line_for_history.
5246 5247 5248 5249 5250 5251 5252 5253 5254 |
# File 'lib/rbreadline.rb', line 5246 def rl_maybe_save_line() if @_rl_saved_line_for_history.nil? @_rl_saved_line_for_history = Struct.new(:line,:timestamp,:data).new @_rl_saved_line_for_history.line = @rl_line_buffer.dup @_rl_saved_line_for_history. = nil @_rl_saved_line_for_history.data = @rl_undo_list end 0 end |
.rl_maybe_unsave_line ⇒ Object
Restore the _rl_saved_line_for_history if there is one.
5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 |
# File 'lib/rbreadline.rb', line 5231 def rl_maybe_unsave_line() if (@_rl_saved_line_for_history) # Can't call with `1' because rl_undo_list might point to an undo # list from a history entry, as in rl_replace_from_history() below. rl_replace_line(@_rl_saved_line_for_history.line, false) @rl_undo_list = @_rl_saved_line_for_history.data @_rl_saved_line_for_history = nil @rl_point = @rl_end # rl_replace_line sets rl_end else rl_ding() end 0 end |
.rl_message(msg_buf) ⇒ Object
7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 |
# File 'lib/rbreadline.rb', line 7188 def (msg_buf) @rl_display_prompt = msg_buf if @saved_local_prompt.nil? rl_save_prompt() @msg_saved_prompt = true end @local_prompt,@prompt_visible_length,@prompt_last_invisible,@prompt_invis_chars_first_line,@prompt_physical_chars = (msg_buf) @local_prompt_prefix = nil @local_prompt_len = @local_prompt ? @local_prompt.length : 0 send(@rl_redisplay_function) 0 end |
.rl_modifying(start, _end) ⇒ Object
Save an undo entry for the text from START to END.
7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 |
# File 'lib/rbreadline.rb', line 7731 def (start, _end) if (start > _end) start,_end = _end,start end if (start != _end) temp = rl_copy_text(start, _end) rl_begin_undo_group() rl_add_undo(UNDO_DELETE, start, _end, temp) rl_add_undo(UNDO_INSERT, start, _end, nil) rl_end_undo_group() end 0 end |
.rl_named_function(name) ⇒ Object
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 |
# File 'lib/rbreadline.rb', line 2323 def rl_named_function(name) case name when "accept-line" return :rl_newline when "arrow-key-prefix" return :rl_arrow_keys when "backward-delete-char" return :rl_rubout when "character-search" return :rl_char_search when "character-search-backward" return :rl_backward_char_search when "copy-region-as-kill" return :rl_copy_region_to_kill when "delete-char" return :rl_delete when "delete-char-or-list" return :rl_delete_or_show_completions when "forward-backward-delete-char" return :rl_rubout_or_delete when "kill-whole-line" return :rl_kill_full_line when "non-incremental-forward-search-history" return :rl_noninc_forward_search when "non-incremental-reverse-search-history" return :rl_noninc_reverse_search when "non-incremental-forward-search-history-again" return :rl_noninc_forward_search_again when "non-incremental-reverse-search-history-again" return :rl_noninc_reverse_search_again when "redraw-current-line" return :rl_refresh_line when "self-insert" return :rl_insert when "undo" return :rl_undo_command when "beginning-of-line" return :rl_beg_of_line else if name =~ /^[-a-z]+$/ return ('rl_'+name.gsub('-','_')).to_sym end end nil end |
.rl_newline(count, key) ⇒ Object
What to do when a NEWLINE is pressed. We accept the whole line.
KEY is the key that invoked this command. I guess it could have
meaning in the future.
5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 |
# File 'lib/rbreadline.rb', line 5610 def rl_newline(count, key) @rl_done = true if (@_rl_history_preserve_point) @_rl_history_saved_point = (@rl_point == @rl_end) ? 1 : @rl_point end rl_setstate(RL_STATE_DONE) if (@rl_editing_mode == @vi_mode) _rl_vi_done_inserting() if (_rl_vi_textmod_command(@_rl_vi_last_command).nil?) # XXX _rl_vi_reset_last() end end # If we've been asked to erase empty lines, suppress the final update, # since _rl_update_final calls rl_crlf(). if (@rl_erase_empty_line && @rl_point == 0 && @rl_end == 0) return 0 end if @readline_echoing_p _rl_update_final() end 0 end |
.rl_noninc_forward_search(count, key) ⇒ Object
Search forward through the history list for a string. If the vi-mode
code calls this, KEY will be `?'.
7838 7839 7840 |
# File 'lib/rbreadline.rb', line 7838 def rl_noninc_forward_search(count, key) noninc_search(1, (key == '?') ? '?' : nil) end |
.rl_noninc_reverse_search(count, key) ⇒ Object
Reverse search the history list for a string. If the vi-mode code
calls this, KEY will be `/'.
7844 7845 7846 |
# File 'lib/rbreadline.rb', line 7844 def rl_noninc_reverse_search(count, key) noninc_search(-1, (key == '/') ? '/' : nil) end |
.rl_on_new_line ⇒ Object
Tell the update routines that we have moved onto a new (empty) line.
3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 |
# File 'lib/rbreadline.rb', line 3695 def rl_on_new_line() if (@visible_line) @visible_line[0] = 0.chr end @_rl_last_c_pos = @_rl_last_v_pos = 0 @_rl_vis_botlin = @last_lmargin = 0 if (@vis_lbreaks) @vis_lbreaks[0] = @vis_lbreaks[1] = 0 end @visible_wrap_offset = 0 0 end |
.rl_on_new_line_with_prompt ⇒ Object
Tell the update routines that we have moved onto a new line with the
prompt already displayed. Code originally from the version of readline
distributed with CLISP. rl_expand_prompt must have already been called
(explicitly or implicitly). This still doesn't work exactly right.
3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 |
# File 'lib/rbreadline.rb', line 3795 def rl_on_new_line_with_prompt() # Initialize visible_line and invisible_line to ensure that they can hold # the already-displayed prompt. prompt_size = @rl_prompt.length + 1 init_line_structures(prompt_size) # Make sure the line structures hold the already-displayed prompt for # redisplay. lprompt = @local_prompt ? @local_prompt : @rl_prompt @visible_line[0,lprompt.length] = lprompt @invisible_line[0,lprompt.length] = lprompt # If the prompt contains newlines, take the last tail. prompt_last_line = rl_prompt.rindex("\n") if prompt_last_line.nil? prompt_last_line = @rl_prompt else prompt_last_line = @rl_prompt[prompt_last_line..-1] end l = prompt_last_line.length if !@rl_byte_oriented @_rl_last_c_pos = _rl_col_width(prompt_last_line, 0, l) else @_rl_last_c_pos = l end # Dissect prompt_last_line into screen lines. Note that here we have # to use the real screenwidth. Readline's notion of screenwidth might be # one less, see terminal.c. real_screenwidth = @_rl_screenwidth + (@_rl_term_autowrap ? 0 : 1) @_rl_last_v_pos = l / real_screenwidth # If the prompt length is a multiple of real_screenwidth, we don't know # whether the cursor is at the end of the last line, or already at the # beginning of the next line. Output a newline just to be safe. if (l > 0 && (l % real_screenwidth) == 0) _rl_output_some_chars("\n",0,1) end @last_lmargin = 0 newlines = 0 i = 0 while (i <= l) @_rl_vis_botlin = newlines @vis_lbreaks[newlines] = i newlines += 1 i += real_screenwidth end @vis_lbreaks[newlines] = l @visible_wrap_offset = 0 @rl_display_prompt = @rl_prompt # XXX - make sure it's set return 0 end |
.rl_outstream ⇒ Object
Returns the value of attribute rl_outstream.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_outstream @rl_outstream end |
.rl_outstream=(value) ⇒ Object
Sets the attribute rl_outstream
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_outstream=(value) @rl_outstream = value end |
.rl_overwrite_mode(count, key) ⇒ Object
Toggle overwrite mode. A positive explicit argument selects overwrite
mode. A negative or zero explicit argument selects insert mode.
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 |
# File 'lib/rbreadline.rb', line 1437 def rl_overwrite_mode(count, key) if (!@rl_explicit_arg) _rl_set_insert_mode(@rl_insert_mode ^ 1, 0) elsif (count > 0) _rl_set_insert_mode(RL_IM_OVERWRITE, 0) else _rl_set_insert_mode(RL_IM_INSERT, 0) end 0 end |
.rl_parse_and_bind(string) ⇒ Object
Read the binding command from STRING and perform it.
A key binding command looks like: Keyname: function-name\0,
a variable binding command looks like: set variable value.
A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark.
2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 |
# File 'lib/rbreadline.rb', line 2380 def rl_parse_and_bind(string) # If this is a parser directive, act on it. if (string[0] == ?$) handle_parser_directive(string[1..-1]) return 0 end # If we aren't supposed to be parsing right now, then we're done. return 0 if @_rl_parsing_conditionalized_out if string =~ /^set/i _,var,value = string.downcase.split(' ') rl_variable_bind(var, value) return 0 end key,funname = string.split(/\s*:\s*/) key = instance_eval(key) rl_bind_key(key, rl_named_function(funname)) 0 end |
.rl_possible_completions(ignore, invoking_key) ⇒ Object
List the possible completions. See description of rl_complete ().
5946 5947 5948 |
# File 'lib/rbreadline.rb', line 5946 def rl_possible_completions(ignore, invoking_key) rl_complete_internal('?') end |
.rl_prep_terminal(meta_flag) ⇒ Object
6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 |
# File 'lib/rbreadline.rb', line 6880 def rl_prep_terminal() if no_terminal? @readline_echoing_p = true return end return if (@terminal_prepped) # Try to keep this function from being INTerrupted. block_sigint() if (@_rl_bind_stty_chars) # If editing in vi mode, make sure we restore the bindings in the # insertion keymap no matter what keymap we ended up in. if (@rl_editing_mode == @vi_mode) rl_tty_unset_default_bindings(@vi_insertion_keymap) else rl_tty_unset_default_bindings(@_rl_keymap) end end save_tty_chars() rl_setstate(RL_STATE_TTYCSAVED) if (@_rl_bind_stty_chars) # If editing in vi mode, make sure we set the bindings in the # insertion keymap no matter what keymap we ended up in. if (@rl_editing_mode == @vi_mode) _rl_bind_tty_special_chars(@vi_insertion_keymap) else _rl_bind_tty_special_chars(@_rl_keymap) end end prepare_terminal_settings() if (@_rl_enable_keypad) _rl_control_keypad(true) end @rl_outstream.flush @terminal_prepped = true rl_setstate(RL_STATE_TERMPREPPED) release_sigint() end |
.rl_quoted_insert(count, key) ⇒ Object
5520 5521 5522 |
# File 'lib/rbreadline.rb', line 5520 def rl_quoted_insert(count, key) _rl_insert_next(count) end |
.rl_re_read_init_file(count, ignore) ⇒ Object
Re-read the current keybindings file.
8146 8147 8148 8149 8150 |
# File 'lib/rbreadline.rb', line 8146 def rl_re_read_init_file(count, ignore) r = rl_read_init_file(nil) rl_set_keymap_from_edit_mode() r end |
.rl_read_init_file(filename) ⇒ Object
Do key bindings from a file. If FILENAME is NULL it defaults
to the first non-null filename from this list:
1. the filename used for the previous call
2. the value of the shell variable `INPUTRC'
3. ~/.inputrc
4. /etc/inputrc
If the file existed and could be opened and read, 0 is returned,
otherwise errno is returned.
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 |
# File 'lib/rbreadline.rb', line 2073 def rl_read_init_file(filename) # Default the filename. filename ||= @last_readline_init_file filename ||= ENV["INPUTRC"] if (filename.nil? || filename == '') filename = DEFAULT_INPUTRC # Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure if (_rl_read_init_file(filename, 0) == 0) return 0 end filename = SYS_INPUTRC end if RUBY_PLATFORM =~ /mswin|mingw/ return 0 if (_rl_read_init_file(filename, 0) == 0) filename = "~/_inputrc" end return (_rl_read_init_file(filename, 0)) end |
.rl_read_key ⇒ Object
Read a key, including pending input.
4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 |
# File 'lib/rbreadline.rb', line 4411 def rl_read_key() @rl_key_sequence_length+=1 if (@rl_pending_input!=0) c = @rl_pending_input rl_clear_pending_input() else # If the user has an event function, then call it periodically. if (@rl_event_hook) while (@rl_event_hook && (c=rl_get_char()).nil?) send(@rl_event_hook) if (@rl_done) # XXX - experimental return ("\n") end if (rl_gather_tyi() < 0) # XXX - EIO @rl_done = true return ("\n") end end else if (c=rl_get_char()).nil? # do we have one cached? c = send(@rl_getc_function,@rl_instream) end end end return (c) end |
.rl_readline_name ⇒ Object
Returns the value of attribute rl_readline_name.
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_readline_name @rl_readline_name end |
.rl_readline_name=(value) ⇒ Object
Sets the attribute rl_readline_name
1097 1098 1099 |
# File 'lib/rbreadline.rb', line 1097 def rl_readline_name=(value) @rl_readline_name = value end |
.rl_redisplay ⇒ Object
Basic redisplay algorithm.
3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 |
# File 'lib/rbreadline.rb', line 3057 def rl_redisplay() return if !@readline_echoing_p _rl_wrapped_multicolumn = 0 @rl_display_prompt ||= "" if (@invisible_line.nil? || @vis_lbreaks.nil?) init_line_structures(0) rl_on_new_line() end # Draw the line into the buffer. @cpos_buffer_position = -1 line = @invisible_line out = inv_botlin = 0 # Mark the line as modified or not. We only do this for history # lines. modmark = 0 if (@_rl_mark_modified_lines && current_history() && @rl_undo_list) line[out] = '*' out += 1 line[out] = 0.chr modmark = 1 end # If someone thought that the redisplay was handled, but the currently # visible line has a different modification state than the one about # to become visible, then correct the caller's misconception. if (@visible_line[0] != @invisible_line[0]) @rl_display_fixed = false end # If the prompt to be displayed is the `primary' readline prompt (the # one passed to readline()), use the values we have already expanded. # If not, use what's already in rl_display_prompt. WRAP_OFFSET is the # number of non-visible characters in the prompt string. if (@rl_display_prompt == @rl_prompt || @local_prompt) if (@local_prompt_prefix && @forced_display) _rl_output_some_chars(@local_prompt_prefix,0,@local_prompt_prefix.length) end if (@local_prompt_len > 0) temp = @local_prompt_len + out + 2 if (temp >= @line_size) @line_size = (temp + 1024) - (temp % 1024) if @visible_line.length >= @line_size @visible_line = @visible_line[0,@line_size] else @visible_line += 0.chr * (@line_size-@visible_line.length) end if @invisible_line.length >= @line_size @invisible_line = @invisible_line[0,@line_size] else @invisible_line += 0.chr * (@line_size-@invisible_line.length) end if @encoding=='X' @visible_line.force_encoding('ASCII-8BIT') @invisible_line.force_encoding('ASCII-8BIT') end line = @invisible_line end line[out,@local_prompt_len] = @local_prompt out += @local_prompt_len end line[out] = 0.chr @wrap_offset = @local_prompt_len - @prompt_visible_length else prompt_this_line = @rl_display_prompt.rindex("\n") if prompt_this_line.nil? prompt_this_line = 0 else prompt_this_line+=1 pmtlen = prompt_this_line # temp var if (@forced_display) _rl_output_some_chars(@rl_display_prompt,0,pmtlen) # Make sure we are at column zero even after a newline, #regardless of the state of terminal output processing. if (pmtlen < 2 || @rl_display_prompt[prompt_this_line-2] != ?\r) cr() end end end @prompt_physical_chars = pmtlen = @rl_display_prompt.length - prompt_this_line temp = pmtlen + out + 2 if (temp >= @line_size) @line_size = (temp + 1024) - (temp % 1024) if @visible_line.length >= @line_size @visible_line = @visible_line[0,@line_size] else @visible_line += 0.chr * (@line_size-@visible_line.length) end if @invisible_line.length >= @line_size @invisible_line = @invisible_line[0,@line_size] else @invisible_line += 0.chr * (@line_size-@invisible_line.length) end if @encoding=='X' @visible_line.force_encoding('ASCII-8BIT') @invisible_line.force_encoding('ASCII-8BIT') end line = @invisible_line end line[out,pmtlen] = @rl_display_prompt[prompt_this_line,pmtlen] out += pmtlen line[out] = 0.chr @wrap_offset = @prompt_invis_chars_first_line = 0 end # inv_lbreaks[i] is where line i starts in the buffer. @inv_lbreaks[newlines = 0] = 0 lpos = @prompt_physical_chars + modmark @_rl_wrapped_line = Array.new(@visible_line.length,0) num = 0 # prompt_invis_chars_first_line is the number of invisible characters in # the first physical line of the prompt. # wrap_offset - prompt_invis_chars_first_line is the number of invis # chars on the second line. # what if lpos is already >= _rl_screenwidth before we start drawing the # contents of the command line? while (lpos >= @_rl_screenwidth) # fix from Darin Johnson <[email protected]> for prompt string with # invisible characters that is longer than the screen width. The # prompt_invis_chars_first_line variable could be made into an array # saying how many invisible characters there are per line, but that's # probably too much work for the benefit gained. How many people have # prompts that exceed two physical lines? # Additional logic fix from Edward Catmur <[email protected]> if (!@rl_byte_oriented) n0 = num temp = @local_prompt_len while (num < temp) z = _rl_col_width(@local_prompt, n0, num) if (z > @_rl_screenwidth) num = _rl_find_prev_mbchar(@local_prompt, num, MB_FIND_ANY) break elsif (z == @_rl_screenwidth) break end num+=1 end temp = num else temp = ((newlines + 1) * @_rl_screenwidth) end # Now account for invisible characters in the current line. temp += (@local_prompt_prefix.nil? ? ((newlines == 0) ? @prompt_invis_chars_first_line : ((newlines == 1) ? @wrap_offset : 0)) : ((newlines == 0) ? @wrap_offset : 0)) @inv_lbreaks[newlines+=1] = temp if !@rl_byte_oriented lpos -= _rl_col_width(@local_prompt, n0, num) else lpos -= @_rl_screenwidth end end @prompt_last_screen_line = newlines # Draw the rest of the line (after the prompt) into invisible_line, keeping # track of where the cursor is (cpos_buffer_position), the number of the line containing # the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin). # It maintains an array of line breaks for display (inv_lbreaks). # This handles expanding tabs for display and displaying meta characters. lb_linenum = 0 _in = 0 if !@rl_byte_oriented && @rl_end>0 case @encoding when 'E' wc = @rl_line_buffer[0,@rl_end].scan(/./me)[0] wc_bytes = wc ? wc.length : 1 when 'S' wc = @rl_line_buffer[0,@rl_end].scan(/./ms)[0] wc_bytes = wc ? wc.length : 1 when 'U' wc = @rl_line_buffer[0,@rl_end].scan(/./mu)[0] wc_bytes = wc ? wc.length : 1 when 'X' wc = @rl_line_buffer[0,@rl_end].force_encoding(@encoding_name)[0] wc_bytes = wc ? wc.bytesize : 1 end else wc_bytes = 1 end while(_in < @rl_end) c = @rl_line_buffer[_in,1] if(c == 0.chr) @rl_end = _in break end if (!@rl_byte_oriented) case @encoding when 'U' wc_width = wc && wc.unpack('U').first >= 0x1000 ? 2 : 1 when 'X' wc_width = wc && wc.ord > 0x1000 ? 2 : 1 else wc_width = wc ? wc.length : 1 end end if (out + 8 >= @line_size) # XXX - 8 for \t @line_size *= 2 if @visible_line.length>=@line_size @visible_line = @visible_line[0,@line_size] else @visible_line += 0.chr * (@line_size-@visible_line.length) end if @invisible_line.length>=@line_size @invisible_line = @invisible_line[0,@line_size] else @invisible_line += 0.chr * (@line_size-@invisible_line.length) end line = @invisible_line end if (_in == @rl_point) @cpos_buffer_position = out lb_linenum = newlines end if (false && (c)) if (!@_rl_output_meta_chars && false) line[out,4] = "\\%03o" % c.ord if (lpos + 4 >= @_rl_screenwidth) temp = @_rl_screenwidth - lpos @inv_lbreaks[newlines+=1] = out + temp lpos = 4 - temp else lpos += 4 end out += 4 else line[out] = c out += 1 lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end end elsif (c == "\t") newout = out + 8 - lpos % 8 temp = newout - out if (lpos + temp >= @_rl_screenwidth) temp2 = @_rl_screenwidth - lpos @inv_lbreaks[newlines+=1] = out + temp2 lpos = temp - temp2 while (out < newout) line[out] = ' ' out += 1 end else while (out < newout) line[out] = ' ' out += 1 end lpos += temp end elsif (c == "\n" && !@_rl_horizontal_scroll_mode && @_rl_term_up) line[out] = 0.chr # XXX - sentinel out += 1 @inv_lbreaks[newlines+=1] = out lpos = 0 elsif (ctrl_char(c) || c == RUBOUT) line[out] = '^' out += 1 lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end line[out] = ctrl_char(c) ? (c[0].ord|0x40).chr.upcase : '?' out += 1 lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end else if (!@rl_byte_oriented) _rl_wrapped_multicolumn = 0 if (@_rl_screenwidth < lpos + wc_width) for i in lpos ... @_rl_screenwidth # The space will be removed in update_line() line[out] = ' ' out += 1 _rl_wrapped_multicolumn+=1 lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end end end if (_in == @rl_point) @cpos_buffer_position = out lb_linenum = newlines end line[out,wc_bytes] = @rl_line_buffer[_in,wc_bytes] out += wc_bytes for i in 0 ... wc_width lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end end else line[out] = c out += 1 lpos+=1 if (lpos >= @_rl_screenwidth) @inv_lbreaks[newlines+=1] = out @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn lpos = 0 end end end if (!@rl_byte_oriented) _in += wc_bytes case @encoding when 'E' wc = @rl_line_buffer[_in,@rl_end - _in].scan(/./me)[0] wc_bytes = wc ? wc.length : 1 when 'S' wc = @rl_line_buffer[_in,@rl_end - _in].scan(/./ms)[0] wc_bytes = wc ? wc.length : 1 when 'U' wc = @rl_line_buffer[_in,@rl_end - _in].scan(/./mu)[0] wc_bytes = wc ? wc.length : 1 when 'X' wc = @rl_line_buffer[_in,@rl_end - _in].force_encoding(@encoding_name)[0] wc_bytes = wc ? wc.bytesize : 1 end else _in+=1 end end line[out] = 0.chr if (@cpos_buffer_position < 0) @cpos_buffer_position = out lb_linenum = newlines end inv_botlin = lb_botlin = newlines @inv_lbreaks[newlines+1] = out cursor_linenum = lb_linenum # CPOS_BUFFER_POSITION == position in buffer where cursor should be placed. # CURSOR_LINENUM == line number where the cursor should be placed. # PWP: now is when things get a bit hairy. The visible and invisible # line buffers are really multiple lines, which would wrap every # (screenwidth - 1) characters. Go through each in turn, finding # the changed region and updating it. The line order is top to bottom. # If we can move the cursor up and down, then use multiple lines, # otherwise, let long lines display in a single terminal line, and # horizontally scroll it. if (!@_rl_horizontal_scroll_mode && @_rl_term_up) if (!@rl_display_fixed || @forced_display) @forced_display = false # If we have more than a screenful of material to display, then # only display a screenful. We should display the last screen, # not the first. if (out >= @_rl_screenchars) if (!@rl_byte_oriented) out = _rl_find_prev_mbchar(line, @_rl_screenchars, MB_FIND_ANY) else out = @_rl_screenchars - 1 end end # The first line is at character position 0 in the buffer. The # second and subsequent lines start at inv_lbreaks[N], offset by # OFFSET (which has already been calculated above). # For each line in the buffer, do the updating display. for linenum in 0 .. inv_botlin # This can lead us astray if we execute a program that changes #the locale from a non-multibyte to a multibyte one. o_cpos = @_rl_last_c_pos @cpos_adjusted = false update_line(@visible_line,vis_pos(linenum), inv_line(linenum), linenum, vis_llen(linenum), inv_llen(linenum), inv_botlin) if (linenum == 0 && !@rl_byte_oriented && !@cpos_adjusted && @_rl_last_c_pos != o_cpos && @_rl_last_c_pos > @wrap_offset && o_cpos < @prompt_last_invisible) @_rl_last_c_pos -= @wrap_offset end # If this is the line with the prompt, we might need to # compensate for invisible characters in the new line. Do # this only if there is not more than one new line (which # implies that we completely overwrite the old visible line) # and the new line is shorter than the old. Make sure we are # at the end of the new line before clearing. if (linenum == 0 && inv_botlin == 0 && @_rl_last_c_pos == out && (@wrap_offset > @visible_wrap_offset) && (@_rl_last_c_pos < @visible_first_line_len)) if !@rl_byte_oriented nleft = @_rl_screenwidth - @_rl_last_c_pos else nleft = @_rl_screenwidth + @wrap_offset - @_rl_last_c_pos end if (nleft!=0) _rl_clear_to_eol(nleft) end end # Since the new first line is now visible, save its length. if (linenum == 0) @visible_first_line_len = (inv_botlin > 0) ? @inv_lbreaks[1] : out - @wrap_offset end end # We may have deleted some lines. If so, clear the left over # blank ones at the bottom out. if (@_rl_vis_botlin > inv_botlin) while(linenum <= @_rl_vis_botlin) tt = vis_chars(linenum) _rl_move_vert(linenum) _rl_move_cursor_relative(0, tt) _rl_clear_to_eol((linenum == @_rl_vis_botlin) ? tt.length : @_rl_screenwidth) linenum += 1 end end @_rl_vis_botlin = inv_botlin # CHANGED_SCREEN_LINE is set to 1 if we have moved to a # different screen line during this redisplay. changed_screen_line = @_rl_last_v_pos != cursor_linenum if (changed_screen_line) _rl_move_vert(cursor_linenum) # If we moved up to the line with the prompt using _rl_term_up, # the physical cursor position on the screen stays the same, # but the buffer position needs to be adjusted to account # for invisible characters. if (@rl_byte_oriented && cursor_linenum == 0 && @wrap_offset!=0) @_rl_last_c_pos += @wrap_offset end end # We have to reprint the prompt if it contains invisible # characters, since it's not generally OK to just reprint # the characters from the current cursor position. But we # only need to reprint it if the cursor is before the last # invisible character in the prompt string. nleft = @prompt_visible_length + @wrap_offset if (cursor_linenum == 0 && @wrap_offset > 0 && @_rl_last_c_pos > 0 && @_rl_last_c_pos < prompt_ending_index() && @local_prompt) if (@_rl_term_cr) @rl_outstream.write(@_rl_term_cr) end _rl_output_some_chars(@local_prompt,0,nleft) if !@rl_byte_oriented @_rl_last_c_pos = _rl_col_width(@local_prompt, 0, nleft) - @wrap_offset else @_rl_last_c_pos = nleft end end # Where on that line? And where does that line start # in the buffer? pos = @inv_lbreaks[cursor_linenum] # nleft == number of characters in the line buffer between the # start of the line and the desired cursor position. nleft = @cpos_buffer_position - pos # NLEFT is now a number of characters in a buffer. When in a # multibyte locale, however, _rl_last_c_pos is an absolute cursor # position that doesn't take invisible characters in the prompt # into account. We use a fudge factor to compensate. # Since _rl_backspace() doesn't know about invisible characters in the # prompt, and there's no good way to tell it, we compensate for # those characters here and call _rl_backspace() directly. if (@wrap_offset!=0 && cursor_linenum == 0 && nleft < @_rl_last_c_pos) # TX == new physical cursor position in multibyte locale. if !@rl_byte_oriented tx = _rl_col_width(@visible_line, pos, pos+nleft) - @visible_wrap_offset else tx = nleft end if (@_rl_last_c_pos > tx) _rl_backspace(@_rl_last_c_pos - tx) # XXX @_rl_last_c_pos = tx end end # We need to note that in a multibyte locale we are dealing with # _rl_last_c_pos as an absolute cursor position, but moving to a # point specified by a buffer position (NLEFT) that doesn't take # invisible characters into account. if !@rl_byte_oriented _rl_move_cursor_relative(nleft, @invisible_line,pos) elsif (nleft != @_rl_last_c_pos) _rl_move_cursor_relative(nleft, @invisible_line,pos) end end else # Do horizontal scrolling. # Always at top line. @_rl_last_v_pos = 0 # Compute where in the buffer the displayed line should start. This # will be LMARGIN. # The number of characters that will be displayed before the cursor. ndisp = @cpos_buffer_position - @wrap_offset nleft = @prompt_visible_length + @wrap_offset # Where the new cursor position will be on the screen. This can be # longer than SCREENWIDTH; if it is, lmargin will be adjusted. phys_c_pos = @cpos_buffer_position - (@last_lmargin!=0 ? @last_lmargin : @wrap_offset) t = @_rl_screenwidth / 3 # If the number of characters had already exceeded the screenwidth, #last_lmargin will be > 0. # If the number of characters to be displayed is more than the screen # width, compute the starting offset so that the cursor is about # two-thirds of the way across the screen. if (phys_c_pos > @_rl_screenwidth - 2) lmargin = @cpos_buffer_position - (2 * t) if (lmargin < 0) lmargin = 0 end # If the left margin would be in the middle of a prompt with # invisible characters, don't display the prompt at all. if (@wrap_offset!=0 && lmargin > 0 && lmargin < nleft) lmargin = nleft end elsif (ndisp < @_rl_screenwidth - 2) # XXX - was -1 lmargin = 0 elsif (phys_c_pos < 1) # If we are moving back towards the beginning of the line and # the last margin is no longer correct, compute a new one. lmargin = ((@cpos_buffer_position - 1) / t) * t # XXX if (@wrap_offset!=0 && lmargin > 0 && lmargin < nleft) lmargin = nleft end else lmargin = @last_lmargin end # If the first character on the screen isn't the first character #in the display line, indicate this with a special character. if (lmargin > 0) line[lmargin] = '<' end # If SCREENWIDTH characters starting at LMARGIN do not encompass # the whole line, indicate that with a special character at the # right edge of the screen. If LMARGIN is 0, we need to take the # wrap offset into account. t = lmargin + m_offset(lmargin, @wrap_offset) + @_rl_screenwidth if (t < out) line[t - 1] = '>' end if (!@rl_display_fixed || @forced_display || lmargin != @last_lmargin) @forced_display = false update_line(@visible_line,@last_lmargin,@invisible_line[lmargin..-1], 0, @_rl_screenwidth + @visible_wrap_offset, @_rl_screenwidth + (lmargin ? 0 : @wrap_offset), 0) # If the visible new line is shorter than the old, but the number # of invisible characters is greater, and we are at the end of # the new line, we need to clear to eol. t = @_rl_last_c_pos - m_offset(lmargin, @wrap_offset) if ((m_offset(lmargin, @wrap_offset) > @visible_wrap_offset) && (@_rl_last_c_pos == out) && t < @visible_first_line_len) nleft = @_rl_screenwidth - t _rl_clear_to_eol(nleft) end @visible_first_line_len = out - lmargin - m_offset(lmargin, @wrap_offset) if (@visible_first_line_len > @_rl_screenwidth) @visible_first_line_len = @_rl_screenwidth end _rl_move_cursor_relative(@cpos_buffer_position - lmargin, @invisible_line ,lmargin) @last_lmargin = lmargin end end @rl_outstream.flush # Swap visible and non-visible lines. @visible_line,@invisible_line = @invisible_line,@visible_line @vis_lbreaks,@inv_lbreaks = @inv_lbreaks,@vis_lbreaks @rl_display_fixed = false # If we are displaying on a single line, and last_lmargin is > 0, we # are not displaying any invisible characters, so set visible_wrap_offset # to 0. if (@_rl_horizontal_scroll_mode && @last_lmargin!=0) @visible_wrap_offset = 0 else @visible_wrap_offset = @wrap_offset end end |
.rl_refresh_line(ignore1, ignore2) ⇒ Object
Clear the current line. Numeric argument to C-l does this.
5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 |
# File 'lib/rbreadline.rb', line 5201 def rl_refresh_line(ignore1, ignore2) curr_line = _rl_current_display_line() _rl_move_vert(curr_line) _rl_move_cursor_relative(0, @rl_line_buffer) # XXX is this right _rl_clear_to_eol(0) # arg of 0 means to not use spaces rl_forced_update_display() @rl_display_fixed = true 0 end |
.rl_replace_from_history(entry, flags) ⇒ Object
6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 |
# File 'lib/rbreadline.rb', line 6765 def rl_replace_from_history(entry, flags) # Can't call with `1' because rl_undo_list might point to an undo list # from a history entry, just like we're setting up here. rl_replace_line(entry.line, false) @rl_undo_list = entry.data @rl_point = @rl_end @rl_mark = 0 if (@rl_editing_mode == @vi_mode) @rl_point = 0 @rl_mark = @rl_end end end |
.rl_replace_line(text, clear_undo) ⇒ Object
Replace the current line buffer contents with TEXT. If CLEAR_UNDO is
non-zero, we free the current undo list.
4894 4895 4896 4897 4898 4899 4900 4901 4902 |
# File 'lib/rbreadline.rb', line 4894 def rl_replace_line(text, clear_undo) len = text.delete(0.chr).length @rl_line_buffer = text.dup + 0.chr @rl_end = len if (clear_undo) rl_free_undo_list() end _rl_fix_point(true) end |
.rl_reset_line_state ⇒ Object
3708 3709 3710 3711 3712 3713 3714 |
# File 'lib/rbreadline.rb', line 3708 def rl_reset_line_state() rl_on_new_line() @rl_display_prompt = @rl_prompt ? @rl_prompt : "" @forced_display = true 0 end |
.rl_resize_terminal ⇒ Object
8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 |
# File 'lib/rbreadline.rb', line 8627 def rl_resize_terminal() if @readline_echoing_p _rl_get_screen_size(@rl_instream.fileno, 1) if @rl_redisplay_function != :rl_redisplay rl_forced_update_display() else _rl_redisplay_after_sigwinch() end end end |
.rl_restart_output(count, key) ⇒ Object
1634 1635 1636 |
# File 'lib/rbreadline.rb', line 1634 def rl_restart_output(count, key) 0 end |
.rl_restore_prompt ⇒ Object
7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 |
# File 'lib/rbreadline.rb', line 7168 def rl_restore_prompt() @local_prompt = nil @local_prompt_prefix = nil @local_prompt = @saved_local_prompt @local_prompt_prefix = @saved_local_prefix @local_prompt_len = @saved_local_length @prompt_prefix_length = @saved_prefix_length @prompt_last_invisible = @saved_last_invisible @prompt_visible_length = @saved_visible_length @prompt_invis_chars_first_line = @saved_invis_chars_first_line @prompt_physical_chars = @saved_physical_chars # can test saved_local_prompt to see if prompt info has been saved. @saved_local_prompt = @saved_local_prefix = nil @saved_local_length = 0 @saved_last_invisible = @saved_visible_length = @saved_prefix_length = 0 @saved_invis_chars_first_line = @saved_physical_chars = 0 end |
.rl_reverse_search_history(sign, key) ⇒ Object
Search backwards through the history looking for a string which is typed
interactively. Start with the current line.
7015 7016 7017 |
# File 'lib/rbreadline.rb', line 7015 def rl_reverse_search_history(sign, key) rl_search_history(-sign, key) end |
.rl_revert_line(count, key) ⇒ Object
Revert the current line to its previous state.
7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 |
# File 'lib/rbreadline.rb', line 7557 def rl_revert_line(count, key) if @rl_undo_list.nil? rl_ding() else while (@rl_undo_list) rl_do_undo() end if (@rl_editing_mode == @vi_mode) @rl_point = @rl_mark = 0 # rl_end should be set correctly end end 0 end |
.rl_rubout(count, key) ⇒ Object
Rubout the character behind point.
5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 |
# File 'lib/rbreadline.rb', line 5695 def rl_rubout(count, key) if (count < 0) return (rl_delete(-count, key)) end if (@rl_point==0) rl_ding() return -1 end if (@rl_insert_mode == RL_IM_OVERWRITE) return (_rl_overwrite_rubout(count, key)) end _rl_rubout_char(count, key) end |
.rl_rubout_or_delete(count, key) ⇒ Object
Delete the character under the cursor, unless the insertion
point is at the end of the line, in which case the character
behind the cursor is deleted. COUNT is obeyed and may be used
to delete forward or backward that many characters.
5916 5917 5918 5919 5920 5921 5922 |
# File 'lib/rbreadline.rb', line 5916 def rl_rubout_or_delete(count, key) if (@rl_end != 0 && @rl_point == @rl_end) return (_rl_rubout_char(count, key)) else return (rl_delete(count, key)) end end |
.rl_save_prompt ⇒ Object
7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 |
# File 'lib/rbreadline.rb', line 7152 def rl_save_prompt() @saved_local_prompt = @local_prompt @saved_local_prefix = @local_prompt_prefix @saved_prefix_length = @prompt_prefix_length @saved_local_length = @local_prompt_len @saved_last_invisible = @prompt_last_invisible @saved_visible_length = @prompt_visible_length @saved_invis_chars_first_line = @prompt_invis_chars_first_line @saved_physical_chars = @prompt_physical_chars @local_prompt = @local_prompt_prefix = nil @local_prompt_len = 0 @prompt_last_invisible = @prompt_visible_length = @prompt_prefix_length = 0 @prompt_invis_chars_first_line = @prompt_physical_chars = 0 end |
.rl_search_history(direction, invoking_key) ⇒ Object
Search through the history looking for an interactively typed string.
This is analogous to i-search. We start the search in the current line.
DIRECTION is which direction to search; >= 0 means forward, < 0 means
backwards.
7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 |
# File 'lib/rbreadline.rb', line 7029 def rl_search_history(direction, invoking_key) rl_setstate(RL_STATE_ISEARCH) cxt = _rl_isearch_init(direction) rl_display_search(cxt.search_string, (cxt.sflags & SF_REVERSE)!=0, -1) # If we are using the callback interface, all we do is set up here and # return. The key is that we leave RL_STATE_ISEARCH set. if (rl_isstate(RL_STATE_CALLBACK)) return (0) end r = -1 while(true) c = _rl_search_getchar(cxt) # We might want to handle EOF here (c == 0) r = _rl_isearch_dispatch(cxt, cxt.lastc) break if (r <= 0) end # The searching is over. The user may have found the string that she # was looking for, or else she may have exited a failing search. If # LINE_INDEX is -1, then that shows that the string searched for was # not found. We use this to determine where to place rl_point. _rl_isearch_cleanup(cxt, r) end |
.rl_set_keymap_from_edit_mode ⇒ Object
2411 2412 2413 2414 2415 2416 2417 |
# File 'lib/rbreadline.rb', line 2411 def rl_set_keymap_from_edit_mode() if (@rl_editing_mode == @emacs_mode) @_rl_keymap = @emacs_standard_keymap elsif (@rl_editing_mode == @vi_mode) @_rl_keymap = @vi_insertion_keymap end end |
.rl_set_mark(count, key) ⇒ Object
A bindable command to set the mark.
6958 6959 6960 |
# File 'lib/rbreadline.rb', line 6958 def rl_set_mark(count, key) _rl_set_mark_at_pos(@rl_explicit_arg ? count : @rl_point) end |
.rl_set_prompt(prompt) ⇒ Object
Set up the prompt and expand it. Called from readline() and
rl_callback_handler_install ().
1787 1788 1789 1790 1791 1792 |
# File 'lib/rbreadline.rb', line 1787 def rl_set_prompt(prompt) @rl_prompt = prompt ? prompt.dup : nil @rl_display_prompt = @rl_prompt ? @rl_prompt : "" @rl_visible_prompt_length = (@rl_prompt) 0 end |
.rl_set_signals ⇒ Object
1644 1645 1646 1647 1648 |
# File 'lib/rbreadline.rb', line 1644 def rl_set_signals() if Signal.list['WINCH'] @def_proc = trap "WINCH",Proc.new{rl_sigwinch_handler(0)} end end |
.rl_setstate(x) ⇒ Object
1615 1616 1617 |
# File 'lib/rbreadline.rb', line 1615 def rl_setstate(x) (@rl_readline_state |= (x)) end |
.rl_sigwinch_handler(sig) ⇒ Object
8638 8639 8640 8641 8642 |
# File 'lib/rbreadline.rb', line 8638 def rl_sigwinch_handler(sig) rl_setstate(RL_STATE_SIGHANDLER) rl_resize_terminal() rl_unsetstate(RL_STATE_SIGHANDLER) end |
.rl_stuff_char(key) ⇒ Object
Add KEY to the buffer of characters to be read. Returns 1 if the
character was stuffed correctly; 0 otherwise.
4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 |
# File 'lib/rbreadline.rb', line 4258 def rl_stuff_char(key) return 0 if (ibuffer_space() == 0) if (key == EOF) key = NEWLINE @rl_pending_input = EOF rl_setstate(RL_STATE_INPUTPENDING) end @ibuffer[@push_index] = key @push_index += 1 if (@push_index >= @ibuffer_len) @push_index = 0 end return 1 end |
.rl_tab_insert(count, key) ⇒ Object
Insert a tab character.
5525 5526 5527 |
# File 'lib/rbreadline.rb', line 5525 def rl_tab_insert(count, key) _rl_insert_char(count, "\t") end |
.rl_tilde_expand(ignore, key) ⇒ Object
A function for simple tilde expansion.
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
# File 'lib/rbreadline.rb', line 1450 def (ignore, key) _end = @rl_point start = _end - 1 if (@rl_point == @rl_end && @rl_line_buffer[@rl_point] == ?~ ) homedir = File.("~") _rl_replace_text(homedir, start, _end) return (0) elsif (@rl_line_buffer[start] != ?~) while(!whitespace(@rl_line_buffer[start,1]) && start >= 0) start -= 1 end start+=1 end _end = start begin _end+=1 end while(!whitespace(@rl_line_buffer[_end,1]) && _end < @rl_end) if (whitespace(@rl_line_buffer[_end,1]) || _end >= @rl_end) _end-=1 end # If the first character of the current word is a tilde, perform #tilde expansion and insert the result. If not a tilde, do # nothing. if (@rl_line_buffer[start] == ?~) len = _end - start + 1 temp = @rl_line_buffer[start,len] homedir = File.(temp) temp = nil _rl_replace_text(homedir, start, _end) end 0 end |
.rl_transpose_chars(count, key) ⇒ Object
Transpose the characters at point. If point is at the end of the line,
then transpose the characters before point.
7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 |
# File 'lib/rbreadline.rb', line 7226 def rl_transpose_chars(count, key) return 0 if (count == 0) if (@rl_point==0 || @rl_end < 2) rl_ding() return -1 end rl_begin_undo_group() if (@rl_point == @rl_end) if !@rl_byte_oriented @rl_point = _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO) else @rl_point -= 1 end count = 1 end prev_point = @rl_point if !@rl_byte_oriented @rl_point = _rl_find_prev_mbchar(@rl_line_buffer, @rl_point, MB_FIND_NONZERO) else @rl_point -= 1 end char_length = prev_point - @rl_point dummy = @rl_line_buffer[@rl_point,char_length] rl_delete_text(@rl_point, @rl_point + char_length) @rl_point += count _rl_fix_point(0) rl_insert_text(dummy) rl_end_undo_group() dummy = nil 0 end |
.rl_transpose_words(count, key) ⇒ Object
Transpose the words at point. If point is at the end of the line,
transpose the two words before point.
8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 |
# File 'lib/rbreadline.rb', line 8093 def rl_transpose_words(count, key) orig_point = @rl_point return if (count==0) # Find the two words. rl_forward_word(count, key) w2_end = @rl_point rl_backward_word(1, key) w2_beg = @rl_point rl_backward_word(count, key) w1_beg = @rl_point rl_forward_word(1, key) w1_end = @rl_point # Do some check to make sure that there really are two words. if ((w1_beg == w2_beg) || (w2_beg < w1_end)) rl_ding() @rl_point = orig_point return -1 end # Get the text of the words. word1 = rl_copy_text(w1_beg, w1_end) word2 = rl_copy_text(w2_beg, w2_end) # We are about to do many insertions and deletions. Remember them # as one operation. rl_begin_undo_group() # Do the stuff at word2 first, so that we don't have to worry # about word1 moving. @rl_point = w2_beg rl_delete_text(w2_beg, w2_end) rl_insert_text(word1) @rl_point = w1_beg rl_delete_text(w1_beg, w1_end) rl_insert_text(word2) # This is exactly correct since the text before this point has not # changed in length. @rl_point = w2_end # I think that does it. rl_end_undo_group() word1 = nil word2 = nil 0 end |
.rl_tty_set_default_bindings(kmap) ⇒ Object
New public way to set the system default editing chars to their readline
equivalents.
2042 2043 2044 2045 2046 2047 2048 2049 |
# File 'lib/rbreadline.rb', line 2042 def rl_tty_set_default_bindings(kmap) h = Hash[*`stty -a`.scan(/(\w+) = ([^;]+);/).flatten] h.each {|k,v| v.gsub!(/\^(.)/){($1[0].ord ^ ((?a..?z).include?($1[0]) ? 0x60 : 0x40)).chr}} kmap[h['erase']] = :rl_rubout kmap[h['kill']] = :rl_unix_line_discard kmap[h['werase']] = :rl_unix_word_rubout kmap[h['lnext']] = :rl_quoted_insert end |
.rl_tty_unset_default_bindings(kmap) ⇒ Object
Rebind all of the tty special chars that readline worries about back
to self-insert. Call this before saving the current terminal special
chars with save_tty_chars(). This only works on POSIX termios or termio
systems.
6870 6871 6872 6873 6874 6875 6876 6877 6878 |
# File 'lib/rbreadline.rb', line 6870 def rl_tty_unset_default_bindings(kmap) # Don't bother before we've saved the tty special chars at least once. return if (!rl_isstate(RL_STATE_TTYCSAVED)) kmap[@_rl_tty_chars.t_erase] = :rl_insert kmap[@_rl_tty_chars.t_kill] = :rl_insert kmap[@_rl_tty_chars.t_lnext] = :rl_insert kmap[@_rl_tty_chars.t_werase] = :rl_insert end |
.rl_undo_command(count, key) ⇒ Object
Do some undoing of things that were done.
7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 |
# File 'lib/rbreadline.rb', line 7504 def rl_undo_command(count, key) if (count < 0) return 0 # Nothing to do. end while (count>0) if (rl_do_undo()) count-=1 else rl_ding() break end end 0 end |
.rl_unix_filename_rubout(count, key) ⇒ Object
This deletes one filename component in a Unix pathname. That is, it
deletes backward to directory separator (`/') or whitespace.
5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 |
# File 'lib/rbreadline.rb', line 5880 def rl_unix_filename_rubout(count, key) if (@rl_point == 0) rl_ding() else orig_point = @rl_point if (count <= 0) count = 1 end while (count>0) c = @rl_line_buffer[@rl_point - 1,1] while (@rl_point>0 && (whitespace(c) || c == '/')) @rl_point-=1 c = @rl_line_buffer[@rl_point - 1,1] end while (@rl_point>0 && !whitespace(c) && c != '/') @rl_point-=1 c = @rl_line_buffer[@rl_point - 1,1] end count -= 1 end rl_kill_text(orig_point, @rl_point) if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end 0 end |
.rl_unix_line_discard(count, key) ⇒ Object
Here is C-u doing what Unix does. You don’t have to use these key-bindings. We have a choice of killing the entire line, or killing from where we are to the start of the line. We choose the latter, because if you are a Unix weenie, then you haven’t backspaced into the line at all, and if you aren’t, then you know what you are doing.
7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 |
# File 'lib/rbreadline.rb', line 7271 def rl_unix_line_discard(count, key) if (@rl_point == 0) rl_ding() else rl_kill_text(@rl_point, 0) @rl_point = 0 if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end 0 end |
.rl_unix_word_rubout(count, key) ⇒ Object
This does what C-w does in Unix. We can’t prevent people from
using behaviour that they expect.
5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 |
# File 'lib/rbreadline.rb', line 5850 def rl_unix_word_rubout(count, key) if (@rl_point == 0) rl_ding() else orig_point = @rl_point if (count <= 0) count = 1 end while (count>0) while (@rl_point>0 && whitespace(@rl_line_buffer[@rl_point - 1,1])) @rl_point-=1 end while (@rl_point>0 && !whitespace(@rl_line_buffer[@rl_point - 1,1])) @rl_point-=1 end count -= 1 end rl_kill_text(orig_point, @rl_point) if (@rl_editing_mode == @emacs_mode) @rl_mark = @rl_point end end 0 end |
.rl_unsetstate(x) ⇒ Object
1619 1620 1621 |
# File 'lib/rbreadline.rb', line 1619 def rl_unsetstate(x) (@rl_readline_state &= ~(x)) end |
.rl_upcase_word(count, key) ⇒ Object
Uppercase the word at point.
7716 7717 7718 |
# File 'lib/rbreadline.rb', line 7716 def rl_upcase_word(count, key) rl_change_case(count, UpCase) end |
.rl_username_completion_function(text, state) ⇒ Object
A completion function for usernames.
TEXT contains a partial username preceded by a random
character (usually `~').
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/rbreadline.rb', line 1222 def rl_username_completion_function(text, state) return nil if RUBY_PLATFORM =~ /mswin|mingw/ if (state == 0) first_char = text[0] first_char_loc = (text[0] == ?~ ? 1 : 0) username = text[first_char_loc..-1] namelen = username.length Etc.setpwent() end while (entry = Etc.getpwent()) # Null usernames should result in all users as possible completions. break if (namelen == 0 || entry.name =~ /^#{username}/ ) end if entry.nil? Etc.endpwent() return nil else value = text.dup value[first_char_loc..-1] = entry.name if (first_char == ?~) @rl_filename_completion_desired = true end return (value) end end |
.rl_variable_bind(name, value) ⇒ Object
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 |
# File 'lib/rbreadline.rb', line 2237 def rl_variable_bind(name,value) case name when "bind-tty-special-chars" @_rl_bind_stty_chars = value.nil? || value=='1' || value == 'on' when "blink-matching-paren" @rl_blink_matching_paren = value.nil? || value=='1' || value == 'on' when "byte-oriented" @rl_byte_oriented = value.nil? || value=='1' || value == 'on' when "completion-ignore-case" @_rl_completion_case_fold = value.nil? || value=='1' || value == 'on' when "convert-meta" @_rl_convert_meta_chars_to_ascii = value.nil? || value=='1' || value == 'on' when "disable-completion" @rl_inhibit_completion = value.nil? || value=='1' || value == 'on' when "enable-keypad" @_rl_enable_keypad = value.nil? || value=='1' || value == 'on' when "expand-tilde" @rl_complete_with_tilde_expansion = value.nil? || value=='1' || value == 'on' when "history-preserve-point" @_rl_history_preserve_point = value.nil? || value=='1' || value == 'on' when "horizontal-scroll-mode" @_rl_horizontal_scroll_mode = value.nil? || value=='1' || value == 'on' when "input-meta" @_rl_meta_flag = value.nil? || value=='1' || value == 'on' when "mark-directories" @_rl_complete_mark_directories = value.nil? || value=='1' || value == 'on' when "mark-modified-lines" @_rl_mark_modified_lines = value.nil? || value=='1' || value == 'on' when "mark-symlinked-directories" @_rl_complete_mark_symlink_dirs = value.nil? || value=='1' || value == 'on' when "match-hidden-files" @_rl_match_hidden_files = value.nil? || value=='1' || value == 'on' when "meta-flag" @_rl_meta_flag = value.nil? || value=='1' || value == 'on' when "output-meta" @_rl_output_meta_chars = value.nil? || value=='1' || value == 'on' when "page-completions" @_rl_page_completions = value.nil? || value=='1' || value == 'on' when "prefer-visible-bell" @_rl_prefer_visible_bell = value.nil? || value=='1' || value == 'on' when "print-completions-horizontally" @_rl_print_completions_horizontally = value.nil? || value=='1' || value == 'on' when "show-all-if-ambiguous" @_rl_complete_show_all = value.nil? || value=='1' || value == 'on' when "show-all-if-unmodified" @_rl_complete_show_unmodified = value.nil? || value=='1' || value == 'on' when "visible-stats" @rl_visible_stats = value.nil? || value=='1' || value == 'on' when "bell-style" case value when "none","off" @_rl_bell_preference = NO_BELL when "audible", "on" @_rl_bell_preference = AUDIBLE_BELL when "visible" @_rl_bell_preference = VISIBLE_BELL else @_rl_bell_preference = AUDIBLE_BELL end when "comment-begin" @_rl_comment_begin = value.dup when "completion-query-items" @rl_completion_query_items = value.to_i when "editing-mode" case value when "vi" @_rl_keymap = @vi_insertion_keymap @rl_editing_mode = @vi_mode when "emacs" @_rl_keymap = @emacs_standard_keymap @rl_editing_mode = @emacs_mode end when "isearch-terminators" @_rl_isearch_terminators = instance_eval(value) when "keymap" case value when "emacs","emacs-standard","emacs-meta","emacs-ctlx" @_rl_keymap = @emacs_standard_keymap when "vi","vi-move","vi-command" @_rl_keymap = @vi_movement_keymap when "vi-insert" @_rl_keymap = @vi_insertion_keymap end end end |
.rl_vi_check ⇒ Object
4668 4669 4670 4671 4672 4673 |
# File 'lib/rbreadline.rb', line 4668 def rl_vi_check() if (@rl_point!=0 && @rl_point == @rl_end) @rl_point-=1 end 0 end |
.rl_vi_editing_mode(count, key) ⇒ Object
1408 1409 1410 1411 1412 1413 |
# File 'lib/rbreadline.rb', line 1408 def rl_vi_editing_mode(count, key) _rl_set_insert_mode(RL_IM_INSERT, 1) # vi mode ignores insert mode @rl_editing_mode = @vi_mode rl_vi_insertion_mode(1, key) 0 end |
.rl_vi_insertion_mode(count, key) ⇒ Object
Switching from one mode to the other really just involves
switching keymaps.
1417 1418 1419 1420 1421 |
# File 'lib/rbreadline.rb', line 1417 def rl_vi_insertion_mode(count, key) @_rl_keymap = @vi_insertion_keymap @_rl_vi_last_key_before_insert = key 0 end |
.rl_yank(count, ignore) ⇒ Object
Yank back the last killed text. This ignores arguments.
7285 7286 7287 7288 7289 7290 7291 7292 7293 |
# File 'lib/rbreadline.rb', line 7285 def rl_yank(count, ignore) if @rl_kill_ring.nil? _rl_abort_internal() return -1 end _rl_set_mark_at_pos(@rl_point) rl_insert_text(@rl_kill_ring[@rl_kill_index]) 0 end |
.rl_yank_last_arg(count, key) ⇒ Object
7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 |
# File 'lib/rbreadline.rb', line 7375 def rl_yank_last_arg(count, key) if (@rl_last_func != :rl_yank_last_arg) @history_skip = 0 @explicit_arg_p = @rl_explicit_arg @count_passed = count @direction = 1 else if (@undo_needed) rl_do_undo() end if (count < 1) @direction = -@direction end @history_skip += @direction if (@history_skip < 0) @history_skip = 0 end end if (@explicit_arg_p) retval = rl_yank_nth_arg_internal(@count_passed, key, @history_skip) else retval = rl_yank_nth_arg_internal('$', key, @history_skip) end @undo_needed = retval == 0 retval end |
.rl_yank_nth_arg(count, ignore) ⇒ Object
Yank the COUNTth argument from the previous history line.
7362 7363 7364 |
# File 'lib/rbreadline.rb', line 7362 def rl_yank_nth_arg(count, ignore) rl_yank_nth_arg_internal(count, ignore, 0) end |
.rl_yank_nth_arg_internal(count, ignore, history_skip) ⇒ Object
Yank the COUNTh argument from the previous history line, skipping
HISTORY_SKIP lines before looking for the `previous line'.
7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 |
# File 'lib/rbreadline.rb', line 7325 def rl_yank_nth_arg_internal(count, ignore, history_skip) pos = where_history() if (history_skip>0) history_skip.times { entry = previous_history() } end entry = previous_history() history_set_pos(pos) if entry.nil? rl_ding() return -1 end arg = history_arg_extract(count, count, entry.line) if (arg.nil? || arg=='') rl_ding() arg = nil return -1 end rl_begin_undo_group() _rl_set_mark_at_pos(@rl_point) # Vi mode always inserts a space before yanking the argument, and it # inserts it right *after* rl_point. if (@rl_editing_mode == @vi_mode) rl_vi_append_mode(1, ignore) rl_insert_text(" ") end rl_insert_text(arg) arg = nil rl_end_undo_group() return 0 end |
.rl_yank_pop(count, key) ⇒ Object
If the last command was yank, or yank_pop, and the text just
before point is identical to the current kill item, then
delete that text from the line, rotate the index down, and
yank back some other text.
7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 |
# File 'lib/rbreadline.rb', line 7299 def rl_yank_pop(count, key) if (((@rl_last_func != :rl_yank_pop) && (@rl_last_func != :rl_yank)) || @rl_kill_ring.nil?) _rl_abort_internal() return -1 end l = @rl_kill_ring[@rl_kill_index].length n = @rl_point - l if (n >= 0 && @rl_line_buffer[n,l] == @rl_kill_ring[@rl_kill_index][0,l]) rl_delete_text(n, @rl_point) @rl_point = n @rl_kill_index-=1 if (@rl_kill_index < 0) @rl_kill_index = @rl_kill_ring_length - 1 end rl_yank(1, 0) return 0 else _rl_abort_internal() return -1 end end |
.save_tty_chars ⇒ Object
6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 |
# File 'lib/rbreadline.rb', line 6804 def save_tty_chars() @_rl_last_tty_chars = @_rl_tty_chars h = Hash[*`stty -a`.scan(/(\w+) = ([^;]+);/).flatten] h.each {|k,v| v.gsub!(/\^(.)/){($1[0].ord ^ ((?a..?z).include?($1[0]) ? 0x60 : 0x40)).chr}} @_rl_tty_chars.t_erase = h['erase'] @_rl_tty_chars.t_kill = h['kill'] @_rl_tty_chars.t_intr = h['intr'] @_rl_tty_chars.t_quit = h['quit'] @_rl_tty_chars.t_start = h['start'] @_rl_tty_chars.t_stop = h['stop'] @_rl_tty_chars.t_eof = h['eof'] @_rl_tty_chars.t_eol = "\n" @_rl_tty_chars.t_eol2 = h['eol2'] @_rl_tty_chars.t_susp = h['susp'] @_rl_tty_chars.t_dsusp = h['dsusp'] @_rl_tty_chars.t_reprint = h['rprnt'] @_rl_tty_chars.t_flush = h['flush'] @_rl_tty_chars.t_werase = h['werase'] @_rl_tty_chars.t_lnext = h['lnext'] @_rl_tty_chars.t_status = -1 @otio = `stty -g` end |
.set_completion_defaults(what_to_do) ⇒ Object
Set default values for readline word completion. These are the variables
that application completion functions can change or inspect.
6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 |
# File 'lib/rbreadline.rb', line 6029 def set_completion_defaults(what_to_do) # Only the completion entry function can change these. @rl_filename_completion_desired = false @rl_filename_quoting_desired = true @rl_completion_type = what_to_do @rl_completion_suppress_append = @rl_completion_suppress_quote = false # The completion entry function may optionally change this. @rl_completion_mark_symlink_dirs = @_rl_complete_mark_symlink_dirs end |
.sh_set_lines_and_columns(lines, cols) ⇒ Object
Set the environment variables LINES and COLUMNS to lines and cols,
respectively.
1831 1832 1833 1834 |
# File 'lib/rbreadline.rb', line 1831 def sh_set_lines_and_columns(lines, cols) ENV["LINES"] = lines.to_s ENV["COLUMNS"] = cols.to_s end |
.space_to_eol(count) ⇒ Object
Clear to the end of the line using spaces. COUNT is the minimum
number of character spaces to clear,
4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 |
# File 'lib/rbreadline.rb', line 4512 def space_to_eol(count) if @hConsoleHandle csbi = 0.chr * 24 @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi) cursor_pos = csbi[4,4].unpack('L').first written = 0.chr * 4 @FillConsoleOutputCharacter.Call(@hConsoleHandle,0x20,count,cursor_pos,written) else @rl_outstream.write(' ' * count) end @_rl_last_c_pos += count end |
.stat_char(filename) ⇒ Object
Return the character which best describes FILENAME.
`@' for symbolic links
`/' for directories
`*' for executables
`=' for sockets
`|' for FIFOs
`%' for character special devices
`#' for block special devices
6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 |
# File 'lib/rbreadline.rb', line 6415 def stat_char(filename) return nil if !File.exists?(filename) return '/' if File.directory?(filename) return '%' if File.chardev?(filename) return '#' if File.blockdev?(filename) return '@' if File.symlink?(filename) return '=' if File.socket?(filename) return '|' if File.pipe?(filename) return '*' if File.executable?(filename) nil end |
.stifle_history(max) ⇒ Object
Stifle the history list, remembering only MAX number of lines.
8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 |
# File 'lib/rbreadline.rb', line 8308 def stifle_history(max) max = 0 if (max < 0) if (@history_length > max) @the_history.slice!(0,(@history_length - max)) @history_length = max end @history_stifled = true @max_input_history = @history_max_entries = max end |
.tgetflag(name) ⇒ Object
1879 1880 1881 |
# File 'lib/rbreadline.rb', line 1879 def tgetflag(name) `infocmp -C -r`.scan(/\w{2}/).include?(name) end |
.trans(i) ⇒ Object
Undo the next thing in the list. Return 0 if there
is nothing to undo, or non-zero if there was.
7447 7448 7449 |
# File 'lib/rbreadline.rb', line 7447 def trans(i) ((i) == -1 ? @rl_point : ((i) == -2 ? @rl_end : (i))) end |
.unstifle_history ⇒ Object
Stop stifling the history. This returns the previous maximum
number of history entries. The value is positive if the history
was stifled, negative if it wasn't.
8323 8324 8325 8326 8327 8328 8329 8330 |
# File 'lib/rbreadline.rb', line 8323 def unstifle_history() if (@history_stifled) @history_stifled = false return (@history_max_entries) else return (-@history_max_entries) end end |
.update_line(old, ostart, new, current_line, omax, nmax, inv_botlin) ⇒ Object
PWP: update_line() is based on finding the middle difference of each
line on the screen; vis:
/old first difference
/beginning of line | /old last same /old EOL
v v v v
old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as new: eddie> Oh, my little buggy says to me, as lurgid as
^ ^ ^ ^
\beginning of line | \new last same \new end of line
\new first difference
All are character pointers for the sake of speed. Special cases for
no differences, as well as for end of line additions must be handled.
Could be made even smarter, but this works well enough
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 |
# File 'lib/rbreadline.rb', line 2656 def update_line(old, ostart, new, current_line, omax, nmax, inv_botlin) # If we're at the right edge of a terminal that supports xn, we're # ready to wrap around, so do so. This fixes problems with knowing # the exact cursor position and cut-and-paste with certain terminal # emulators. In this calculation, TEMP is the physical screen # position of the cursor. if @encoding == 'X' old.force_encoding('ASCII-8BIT') new.force_encoding('ASCII-8BIT') end if !@rl_byte_oriented temp = @_rl_last_c_pos else temp = @_rl_last_c_pos - w_offset(@_rl_last_v_pos, @visible_wrap_offset) end if (temp == @_rl_screenwidth && @_rl_term_autowrap && !@_rl_horizontal_scroll_mode && @_rl_last_v_pos == current_line - 1) if (!@rl_byte_oriented) # This fixes only double-column characters, but if the wrapped # character comsumes more than three columns, spaces will be # inserted in the string buffer. if (@_rl_wrapped_line[current_line] > 0) _rl_clear_to_eol(@_rl_wrapped_line[current_line]) end if new[0] != ?\0 case @encoding when 'E' wc = new.scan(/./me)[0] ret = wc.length tempwidth = wc.length when 'S' wc = new.scan(/./ms)[0] ret = wc.length tempwidth = wc.length when 'U' wc = new.scan(/./mu)[0] ret = wc.length tempwidth = wc.unpack('U').first >= 0x1000 ? 2 : 1 when 'X' wc = new[0..-1].force_encoding(@encoding_name)[0] ret = wc.bytesize tempwidth = wc.ord >= 0x1000 ? 2 : 1 else ret = 1 tempwidth = 1 end else tempwidth = 0 end if (tempwidth > 0) bytes = ret @rl_outstream.write(new[0,bytes]) @_rl_last_c_pos = tempwidth @_rl_last_v_pos+=1 if old[ostart] != ?\0 case @encoding when 'E' wc = old[ostart..-1].scan(/./me)[0] ret = wc.length when 'S' wc = old[ostart..-1].scan(/./ms)[0] ret = wc.length when 'U' wc = old[ostart..-1].scan(/./mu)[0] ret = wc.length when 'X' wc = old[ostart..-1].force_encoding(@encoding_name)[0] ret = wc.bytesize end else ret = 0 end if (ret != 0 && bytes != 0) if ret != bytes len = old[ostart..-1].index(0.chr,ret) old[ostart+bytes,len-ret] = old[ostart+ret,len-ret] end old[ostart,bytes] = new[0,bytes] end else @rl_outstream.write(' ') @_rl_last_c_pos = 1 @_rl_last_v_pos+=1 if (old[ostart] != ?\0 && new[0] != ?\0) old[ostart] = new[0] end end else if (new[0] != ?\0) @rl_outstream.write(new[0,1]) else @rl_outstream.write(' ') end @_rl_last_c_pos = 1 @_rl_last_v_pos+=1 if (old[ostart]!= ?\0 && new[0] != ?\0) old[ostart] = new[0] end end end # Find first difference. if (!@rl_byte_oriented) # See if the old line is a subset of the new line, so that the # only change is adding characters. if (index = old.index(0.chr)) && omax+ostart>index omax = index - ostart end if (index = new.index(0.chr)) && nmax>index nmax = index end temp = (omax < nmax) ? omax : nmax if old[ostart,temp]==new[0,temp] ofd = temp nfd = temp else if (omax == nmax && new[0,omax]==old[ostart,omax]) ofd = omax nfd = nmax else new_offset = 0 old_offset = ostart ofd = 0 nfd = 0 while(ofd < omax && old[ostart+ofd] != ?\0 && _rl_compare_chars(old, old_offset, new, new_offset)) old_offset = _rl_find_next_mbchar(old, old_offset, 1, MB_FIND_ANY) new_offset = _rl_find_next_mbchar(new, new_offset, 1, MB_FIND_ANY) ofd = old_offset - ostart nfd = new_offset end end end else ofd = 0 nfd = 0 while(ofd < omax && old[ostart+ofd] != ?\0 && old[ostart+ofd] == new[nfd]) ofd += 1 nfd += 1 end end # Move to the end of the screen line. ND and OD are used to keep track # of the distance between ne and new and oe and old, respectively, to # move a subtraction out of each loop. oe = old.index(0.chr,ostart+ofd) - ostart if oe.nil? || oe>omax oe = omax end ne = new.index(0.chr,nfd) if ne.nil? || ne>omax ne = nmax end # If no difference, continue to next line. if (ofd == oe && nfd == ne) return end wsatend = true # flag for trailing whitespace if (!@rl_byte_oriented) ols = _rl_find_prev_mbchar(old, ostart+oe, MB_FIND_ANY) - ostart nls = _rl_find_prev_mbchar(new, ne, MB_FIND_ANY) while ((ols > ofd) && (nls > nfd)) if (!_rl_compare_chars(old, ostart+ols, new, nls)) break end if (old[ostart+ols] == ?\x20) wsatend = false end ols = _rl_find_prev_mbchar(old, ols+ostart, MB_FIND_ANY) - ostart nls = _rl_find_prev_mbchar(new, nls, MB_FIND_ANY) end else ols = oe - 1 # find last same nls = ne - 1 while ((ols > ofd) && (nls > nfd) && old[ostart+ols] == new[nls]) if (old[ostart+ols] != ?\x20 ) wsatend = false end ols-=1 nls-=1 end end if (wsatend) ols = oe nls = ne elsif (!_rl_compare_chars(old, ostart+ols, new, nls)) if (old[ostart+ols] != ?\0) # don't step past the NUL if !@rl_byte_oriented ols = _rl_find_next_mbchar(old, ostart+ols, 1, MB_FIND_ANY) - ostart else ols+=1 end end if (new[nls] != ?\0 ) if !@rl_byte_oriented nls = _rl_find_next_mbchar(new, nls, 1, MB_FIND_ANY) else nls+=1 end end end # count of invisible characters in the current invisible line. current_invis_chars = w_offset(current_line, @wrap_offset) if (@_rl_last_v_pos != current_line) _rl_move_vert(current_line) if (@rl_byte_oriented && current_line == 0 && @visible_wrap_offset!=0) @_rl_last_c_pos += @visible_wrap_offset end end # If this is the first line and there are invisible characters in the # prompt string, and the prompt string has not changed, and the current # cursor position is before the last invisible character in the prompt, # and the index of the character to move to is past the end of the prompt # string, then redraw the entire prompt string. We can only do this # reliably if the terminal supports a `cr' capability. # This is not an efficiency hack -- there is a problem with redrawing # portions of the prompt string if they contain terminal escape # sequences (like drawing the `unbold' sequence without a corresponding # `bold') that manifests itself on certain terminals. lendiff = @local_prompt_len if (current_line == 0 && !@_rl_horizontal_scroll_mode && @_rl_term_cr && lendiff > @prompt_visible_length && @_rl_last_c_pos > 0 && ofd >= lendiff && @_rl_last_c_pos < prompt_ending_index()) @rl_outstream.write(@_rl_term_cr) _rl_output_some_chars(@local_prompt,0,lendiff) if !@rl_byte_oriented # We take wrap_offset into account here so we can pass correct # information to _rl_move_cursor_relative. @_rl_last_c_pos = _rl_col_width(@local_prompt, 0, lendiff) - @wrap_offset @cpos_adjusted = true else @_rl_last_c_pos = lendiff end end # When this function returns, _rl_last_c_pos is correct, and an absolute # cursor postion in multibyte mode, but a buffer index when not in a # multibyte locale. _rl_move_cursor_relative(ofd, old, ostart) if (current_line == 0 && !@rl_byte_oriented && @_rl_last_c_pos == @prompt_physical_chars) @cpos_adjusted = true end # if (len (new) > len (old)) # lendiff == difference in buffer # col_lendiff == difference on screen # When not using multibyte characters, these are equal lendiff = (nls - nfd) - (ols - ofd) if !@rl_byte_oriented col_lendiff = _rl_col_width(new, nfd, nls) - _rl_col_width(old, ostart+ofd, ostart+ols) else col_lendiff = lendiff end # If we are changing the number of invisible characters in a line, and # the spot of first difference is before the end of the invisible chars, # lendiff needs to be adjusted. if (current_line == 0 && !@_rl_horizontal_scroll_mode && current_invis_chars != @visible_wrap_offset) if !@rl_byte_oriented lendiff += @visible_wrap_offset - current_invis_chars col_lendiff += @visible_wrap_offset - current_invis_chars else lendiff += @visible_wrap_offset - current_invis_chars col_lendiff = lendiff end end # Insert (diff (len (old), len (new)) ch. temp = ne - nfd if !@rl_byte_oriented col_temp = _rl_col_width(new,nfd,ne) else col_temp = temp end if (col_lendiff > 0) # XXX - was lendiff # Non-zero if we're increasing the number of lines. gl = current_line >= @_rl_vis_botlin && inv_botlin > @_rl_vis_botlin # Sometimes it is cheaper to print the characters rather than # use the terminal's capabilities. If we're growing the number # of lines, make sure we actually cause the new line to wrap # around on auto-wrapping terminals. if (@_rl_terminal_can_insert && ((2 * col_temp) >= col_lendiff || @_rl_term_IC) && (!@_rl_term_autowrap || !gl)) # If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and # _rl_horizontal_scroll_mode == 1, inserting the characters with # _rl_term_IC or _rl_term_ic will screw up the screen because of the # invisible characters. We need to just draw them. if (old[ostart+ols] != ?\0 && (!@_rl_horizontal_scroll_mode || @_rl_last_c_pos > 0 || lendiff <= @prompt_visible_length || current_invis_chars==0)) insert_some_chars(new[nfd..-1], lendiff, col_lendiff) @_rl_last_c_pos += col_lendiff elsif ((@rl_byte_oriented) && old[ostart+ols] == ?\0 && lendiff > 0) # At the end of a line the characters do not have to # be "inserted". They can just be placed on the screen. # However, this screws up the rest of this block, which # assumes you've done the insert because you can. _rl_output_some_chars(new,nfd, lendiff) @_rl_last_c_pos += col_lendiff else # We have horizontal scrolling and we are not inserting at # the end. We have invisible characters in this line. This # is a dumb update. _rl_output_some_chars(new,nfd, temp) @_rl_last_c_pos += col_temp return end # Copy (new) chars to screen from first diff to last match. temp = nls - nfd if ((temp - lendiff) > 0) _rl_output_some_chars(new,(nfd + lendiff),temp - lendiff) # XXX -- this bears closer inspection. Fixes a redisplay bug # reported against bash-3.0-alpha by Andreas Schwab involving # multibyte characters and prompt strings with invisible # characters, but was previously disabled. @_rl_last_c_pos += _rl_col_width(new,nfd+lendiff, nfd+lendiff+temp-col_lendiff) end else # cannot insert chars, write to EOL _rl_output_some_chars(new,nfd, temp) @_rl_last_c_pos += col_temp # If we're in a multibyte locale and were before the last invisible # char in the current line (which implies we just output some invisible # characters) we need to adjust _rl_last_c_pos, since it represents # a physical character position. end else # Delete characters from line. # If possible and inexpensive to use terminal deletion, then do so. if (@_rl_term_dc && (2 * col_temp) >= -col_lendiff) # If all we're doing is erasing the invisible characters in the # prompt string, don't bother. It screws up the assumptions # about what's on the screen. if (@_rl_horizontal_scroll_mode && @_rl_last_c_pos == 0 && -lendiff == @visible_wrap_offset) col_lendiff = 0 end if (col_lendiff!=0) delete_chars(-col_lendiff) # delete (diff) characters end # Copy (new) chars to screen from first diff to last match temp = nls - nfd if (temp > 0) _rl_output_some_chars(new,nfd, temp) @_rl_last_c_pos += _rl_col_width(new,nfd,nfd+temp) end # Otherwise, print over the existing material. else if (temp > 0) _rl_output_some_chars(new,nfd, temp) @_rl_last_c_pos += col_temp # XXX end lendiff = (oe) - (ne) if !@rl_byte_oriented col_lendiff = _rl_col_width(old, ostart, ostart+oe) - _rl_col_width(new, 0, ne) else col_lendiff = lendiff end if (col_lendiff!=0) if (@_rl_term_autowrap && current_line < inv_botlin) space_to_eol(col_lendiff) else _rl_clear_to_eol(col_lendiff) end end end end end |
.using_history ⇒ Object
6023 6024 6025 |
# File 'lib/rbreadline.rb', line 6023 def using_history() @history_offset = @history_length end |
.vis_chars(line) ⇒ Object
2619 2620 2621 |
# File 'lib/rbreadline.rb', line 2619 def vis_chars(line) @visible_line[@vis_lbreaks[line] .. -1] end |
.vis_line(line) ⇒ Object
2627 2628 2629 |
# File 'lib/rbreadline.rb', line 2627 def vis_line(line) ((line) > @_rl_vis_botlin) ? "" : vis_chars(line) end |
.vis_llen(l) ⇒ Object
2611 2612 2613 |
# File 'lib/rbreadline.rb', line 2611 def vis_llen(l) ((l) > @_rl_vis_botlin ? 0 : (@vis_lbreaks[l+1] - @vis_lbreaks[l])) end |
.vis_pos(line) ⇒ Object
2623 2624 2625 |
# File 'lib/rbreadline.rb', line 2623 def vis_pos(line) @vis_lbreaks[line] end |
.w_offset(line, offset) ⇒ Object
2607 2608 2609 |
# File 'lib/rbreadline.rb', line 2607 def w_offset(line, offset) ((line) == 0 ? offset : 0) end |
.where_history ⇒ Object
Returns the magic number which says what history element we are
looking at now. In this implementation, it returns history_offset.
5258 5259 5260 |
# File 'lib/rbreadline.rb', line 5258 def where_history() @history_offset end |
.whitespace(c) ⇒ Object
2603 2604 2605 |
# File 'lib/rbreadline.rb', line 2603 def whitespace(c) (c == ' ' || c == "\t") end |