PageRenderTime 67ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 3ms

/External.LCA_RESTRICTED/Languages/Ruby/ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb

http://ironperunis.codeplex.com
Ruby | 8664 lines | 6081 code | 1132 blank | 1451 comment | 1492 complexity | f47b1b860555f8d12b5502f59f11cbf8 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, Apache-2.0, ISC, GPL-2.0, CPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. # rbreadline.rb -- a general facility for reading lines of input
  2. # with emacs style editing and completion.
  3. #
  4. # Inspired by GNU Readline, translation to Ruby
  5. # Copyright (C) 2009 by Park Heesob phasis@gmail.com
  6. #
  7. class Fixnum
  8. def ord; self; end
  9. end
  10. module RbReadline
  11. require 'etc'
  12. RL_LIBRARY_VERSION = "5.2"
  13. RL_READLINE_VERSION = 0x0502
  14. RB_READLINE_VERSION = "0.2.0"
  15. EOF = "\xFF"
  16. ESC = "\C-["
  17. PAGE = "\C-L"
  18. SPACE = "\x20"
  19. RETURN = "\C-M"
  20. ABORT_CHAR = "\C-G"
  21. TAB = "\t"
  22. RUBOUT = "x7f"
  23. NEWLINE = "\n"
  24. DEFAULT_BUFFER_SIZE = 256
  25. DEFAULT_MAX_KILLS = 10
  26. MB_FIND_NONZERO = 1
  27. MB_FIND_ANY = 0
  28. MB_LEN_MAX = 4
  29. DEFAULT_INPUTRC = "~/.inputrc"
  30. SYS_INPUTRC = "/etc/inputrc"
  31. UpCase = 1
  32. DownCase = 2
  33. CapCase = 3
  34. # Possible history errors passed to hist_error.
  35. EVENT_NOT_FOUND = 0
  36. BAD_WORD_SPEC = 1
  37. SUBST_FAILED = 2
  38. BAD_MODIFIER = 3
  39. NO_PREV_SUBST = 4
  40. # Possible definitions for history starting point specification.
  41. ANCHORED_SEARCH = 1
  42. NON_ANCHORED_SEARCH = 0
  43. # Possible definitions for what style of writing the history file we want.
  44. HISTORY_APPEND = 0
  45. HISTORY_OVERWRITE = 1
  46. # Input error; can be returned by (*rl_getc_function) if readline is reading
  47. # a top-level command (RL_ISSTATE (RL_STATE_READCMD)).
  48. READERR = 0xFE.chr
  49. # Definitions available for use by readline clients.
  50. RL_PROMPT_START_IGNORE = 1.chr
  51. RL_PROMPT_END_IGNORE = 2.chr
  52. # Possible values for do_replace argument to rl_filename_quoting_function,
  53. # called by rl_complete_internal.
  54. NO_MATCH = 0
  55. SINGLE_MATCH = 1
  56. MULT_MATCH = 2
  57. # Callback data for reading numeric arguments
  58. NUM_SAWMINUS = 0x01
  59. NUM_SAWDIGITS = 0x02
  60. NUM_READONE = 0x04
  61. # A context for reading key sequences longer than a single character when
  62. # using the callback interface.
  63. KSEQ_DISPATCHED = 0x01
  64. KSEQ_SUBSEQ = 0x02
  65. KSEQ_RECURSIVE = 0x04
  66. # Possible state values for rl_readline_state
  67. RL_STATE_NONE = 0x000000 # no state before first call
  68. RL_STATE_INITIALIZING = 0x000001 # initializing
  69. RL_STATE_INITIALIZED = 0x000002 # initialization done
  70. RL_STATE_TERMPREPPED = 0x000004 # terminal is prepped
  71. RL_STATE_READCMD = 0x000008 # reading a command key
  72. RL_STATE_METANEXT = 0x000010 # reading input after ESC
  73. RL_STATE_DISPATCHING = 0x000020 # dispatching to a command
  74. RL_STATE_MOREINPUT = 0x000040 # reading more input in a command function
  75. RL_STATE_ISEARCH = 0x000080 # doing incremental search
  76. RL_STATE_NSEARCH = 0x000100 # doing non-inc search
  77. RL_STATE_SEARCH = 0x000200 # doing a history search
  78. RL_STATE_NUMERICARG = 0x000400 # reading numeric argument
  79. RL_STATE_MACROINPUT = 0x000800 # getting input from a macro
  80. RL_STATE_MACRODEF = 0x001000 # defining keyboard macro
  81. RL_STATE_OVERWRITE = 0x002000 # overwrite mode
  82. RL_STATE_COMPLETING = 0x004000 # doing completion
  83. RL_STATE_SIGHANDLER = 0x008000 # in readline sighandler
  84. RL_STATE_UNDOING = 0x010000 # doing an undo
  85. RL_STATE_INPUTPENDING = 0x020000 # rl_execute_next called
  86. RL_STATE_TTYCSAVED = 0x040000 # tty special chars saved
  87. RL_STATE_CALLBACK = 0x080000 # using the callback interface
  88. RL_STATE_VIMOTION = 0x100000 # reading vi motion arg
  89. RL_STATE_MULTIKEY = 0x200000 # reading multiple-key command
  90. RL_STATE_VICMDONCE = 0x400000 # entered vi command mode at least once
  91. RL_STATE_DONE = 0x800000 # done accepted line
  92. NO_BELL = 0
  93. AUDIBLE_BELL = 1
  94. VISIBLE_BELL = 2
  95. # The actions that undo knows how to undo. Notice that UNDO_DELETE means
  96. # to insert some text, and UNDO_INSERT means to delete some text. I.e.,
  97. # the code tells undo what to undo, not how to undo it.
  98. UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END = 0,1,2,3
  99. # Definitions used when searching the line for characters.
  100. # NOTE: it is necessary that opposite directions are inverses
  101. FTO = 1 # forward to
  102. BTO = -1 # backward to
  103. FFIND = 2 # forward find
  104. BFIND = -2 # backward find
  105. # Possible values for the found_quote flags word used by the completion
  106. # functions. It says what kind of (shell-like) quoting we found anywhere
  107. # in the line.
  108. RL_QF_SINGLE_QUOTE = 0x01
  109. RL_QF_DOUBLE_QUOTE = 0x02
  110. RL_QF_BACKSLASH = 0x04
  111. RL_QF_OTHER_QUOTE = 0x08
  112. KEYMAP_SIZE = 257
  113. ANYOTHERKEY = KEYMAP_SIZE-1
  114. @hConsoleHandle = nil
  115. @MessageBeep = nil
  116. RL_IM_INSERT = 1
  117. RL_IM_OVERWRITE = 0
  118. RL_IM_DEFAULT = RL_IM_INSERT
  119. @no_mode = -1
  120. @vi_mode = 0
  121. @emacs_mode = 1
  122. ISFUNC = 0
  123. ISKMAP = 1
  124. ISMACR = 2
  125. HISTORY_WORD_DELIMITERS = " \t\n;&()|<>"
  126. HISTORY_QUOTE_CHARACTERS = "\"'`"
  127. RL_SEARCH_ISEARCH = 0x01 # incremental search
  128. RL_SEARCH_NSEARCH = 0x02 # non-incremental search
  129. RL_SEARCH_CSEARCH = 0x04 # intra-line char search
  130. # search flags
  131. SF_REVERSE = 0x01
  132. SF_FOUND = 0x02
  133. SF_FAILED = 0x04
  134. @slashify_in_quotes = "\\`\"$"
  135. @sigint_proc = nil
  136. @sigint_blocked = false
  137. @rl_prep_term_function = :rl_prep_terminal
  138. @rl_deprep_term_function = :rl_deprep_terminal
  139. @_rl_history_saved_point = -1
  140. @rl_max_kills = DEFAULT_MAX_KILLS
  141. @rl_kill_ring = nil
  142. @rl_kill_index = 0
  143. @rl_kill_ring_length = 0
  144. @pending_bytes = ''
  145. @stored_count = 0
  146. @_rl_isearch_terminators = nil
  147. @_rl_iscxt = nil
  148. @last_isearch_string = nil
  149. @last_isearch_string_len = 0
  150. @default_isearch_terminators = "\033\012"
  151. @_rl_history_preserve_point = false
  152. @terminal_prepped = false
  153. @otio = nil
  154. @msg_saved_prompt = false
  155. @_rl_nscxt = nil
  156. @noninc_search_string = nil
  157. @noninc_history_pos = 0
  158. @prev_line_found = nil
  159. rl_history_search_len = 0
  160. rl_history_search_pos = 0
  161. history_search_string = nil
  162. history_string_size = 0
  163. @_rl_tty_chars = Struct.new(:t_eol,:t_eol2,:t_erase,:t_werase,:t_kill,:t_reprint,:t_intr,:t_eof,
  164. :t_quit,:t_susp,:t_dsusp,:t_start,:t_stop,:t_lnext,:t_flush,:t_status).new
  165. @_rl_last_tty_chars = nil
  166. # Variables exported by this file.
  167. # The character that represents the start of a history expansion
  168. # request. This is usually `!'.
  169. @history_expansion_char = ?!
  170. # The character that invokes word substitution if found at the start of
  171. # a line. This is usually `^'.
  172. @history_subst_char = ?^
  173. # During tokenization, if this character is seen as the first character
  174. # of a word, then it, and all subsequent characters upto a newline are
  175. # ignored. For a Bourne shell, this should be '#'. Bash special cases
  176. # the interactive comment character to not be a comment delimiter.
  177. @history_comment_char = ?\0
  178. # The list of characters which inhibit the expansion of text if found
  179. # immediately following history_expansion_char.
  180. @history_no_expand_chars = " \t\n\r="
  181. # If set to a non-zero value, single quotes inhibit history expansion.
  182. # The default is 0.
  183. @history_quotes_inhibit_expansion = 0
  184. # Used to split words by history_tokenize_internal.
  185. @history_word_delimiters = HISTORY_WORD_DELIMITERS
  186. # If set, this points to a function that is called to verify that a
  187. # particular history expansion should be performed.
  188. @history_inhibit_expansion_function = nil
  189. @rl_event_hook = nil
  190. # The visible cursor position. If you print some text, adjust this.
  191. # NOTE: _rl_last_c_pos is used as a buffer index when not in a locale
  192. # supporting multibyte characters, and an absolute cursor position when
  193. # in such a locale. This is an artifact of the donated multibyte support.
  194. # Care must be taken when modifying its value.
  195. @_rl_last_c_pos = 0
  196. @_rl_last_v_pos = 0
  197. @cpos_adjusted = false
  198. @cpos_buffer_position = 0
  199. # Number of lines currently on screen minus 1.
  200. @_rl_vis_botlin = 0
  201. # Variables used only in this file.
  202. # The last left edge of text that was displayed. This is used when
  203. # doing horizontal scrolling. It shifts in thirds of a screenwidth.
  204. @last_lmargin = 0
  205. # The line display buffers. One is the line currently displayed on
  206. # the screen. The other is the line about to be displayed.
  207. @visible_line = nil
  208. @invisible_line = nil
  209. # A buffer for `modeline' messages.
  210. @msg_buf = 0.chr * 128
  211. # Non-zero forces the redisplay even if we thought it was unnecessary.
  212. @forced_display = false
  213. # Default and initial buffer size. Can grow.
  214. @line_size = 1024
  215. # Variables to keep track of the expanded prompt string, which may
  216. # include invisible characters.
  217. @local_prompt = nil
  218. @local_prompt_prefix = nil
  219. @local_prompt_len = 0
  220. @prompt_visible_length = 0
  221. @prompt_prefix_length = 0
  222. # The number of invisible characters in the line currently being
  223. # displayed on the screen.
  224. @visible_wrap_offset = 0
  225. # The number of invisible characters in the prompt string. Static so it
  226. # can be shared between rl_redisplay and update_line
  227. @wrap_offset = 0
  228. @prompt_last_invisible = 0
  229. # The length (buffer offset) of the first line of the last (possibly
  230. # multi-line) buffer displayed on the screen.
  231. @visible_first_line_len = 0
  232. # Number of invisible characters on the first physical line of the prompt.
  233. # Only valid when the number of physical characters in the prompt exceeds
  234. # (or is equal to) _rl_screenwidth.
  235. @prompt_invis_chars_first_line = 0
  236. @prompt_last_screen_line = 0
  237. @prompt_physical_chars = 0
  238. # Variables to save and restore prompt and display information.
  239. # These are getting numerous enough that it's time to create a struct.
  240. @saved_local_prompt = nil
  241. @saved_local_prefix = nil
  242. @saved_last_invisible = 0
  243. @saved_visible_length = 0
  244. @saved_prefix_length = 0
  245. @saved_local_length = 0
  246. @saved_invis_chars_first_line = 0
  247. @saved_physical_chars = 0
  248. @inv_lbreaks = nil
  249. @vis_lbreaks = nil
  250. @_rl_wrapped_line = nil
  251. @term_buffer = nil
  252. @term_string_buffer = nil
  253. @tcap_initialized = false
  254. # While we are editing the history, this is the saved
  255. # version of the original line.
  256. @_rl_saved_line_for_history = nil
  257. # An array of HIST_ENTRY. This is where we store the history.
  258. @the_history = nil
  259. @history_base = 1
  260. # Non-zero means that we have enforced a limit on the amount of
  261. # history that we save.
  262. @history_stifled = false
  263. # If HISTORY_STIFLED is non-zero, then this is the maximum number of
  264. # entries to remember.
  265. @history_max_entries = 0
  266. @max_input_history = 0 # backwards compatibility
  267. # The current location of the interactive history pointer. Just makes
  268. # life easier for outside callers.
  269. @history_offset = 0
  270. # The number of strings currently stored in the history list.
  271. @history_length = 0
  272. @_rl_vi_last_command = 'i' # default `.' puts you in insert mode
  273. # Non-zero means enter insertion mode.
  274. @_rl_vi_doing_insert = 0
  275. # Command keys which do movement for xxx_to commands.
  276. @vi_motion = " hl^$0ftFT;,%wbeWBE|"
  277. # Keymap used for vi replace characters. Created dynamically since
  278. # rarely used.
  279. @vi_replace_map = nil
  280. # The number of characters inserted in the last replace operation.
  281. @vi_replace_count = 0
  282. # If non-zero, we have text inserted after a c[motion] command that put
  283. # us implicitly into insert mode. Some people want this text to be
  284. # attached to the command so that it is `redoable' with `.'.
  285. @vi_continued_command = false
  286. @vi_insert_buffer = nil
  287. @vi_insert_buffer_size = 0
  288. @_rl_vi_last_repeat = 1
  289. @_rl_vi_last_arg_sign = 1
  290. @_rl_vi_last_motion = 0
  291. @_rl_vi_last_search_char = 0
  292. @_rl_vi_last_replacement = 0
  293. @_rl_vi_last_key_before_insert = 0
  294. @vi_redoing = 0
  295. # Text modification commands. These are the `redoable' commands.
  296. @vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~"
  297. # Arrays for the saved marks.
  298. @vi_mark_chars = Array.new(26,-1)
  299. @emacs_standard_keymap = {
  300. "\C-@" => :rl_set_mark ,
  301. "\C-a" => :rl_beg_of_line ,
  302. "\C-b" => :rl_backward_char ,
  303. "\C-d" => :rl_delete ,
  304. "\C-e" => :rl_end_of_line ,
  305. "\C-f" => :rl_forward_char ,
  306. "\C-g" => :rl_abort ,
  307. "\C-h" => :rl_rubout ,
  308. "\C-i" => :rl_complete ,
  309. "\C-j" => :rl_newline ,
  310. "\C-k" => :rl_kill_line ,
  311. "\C-l" => :rl_clear_screen ,
  312. "\C-m" => :rl_newline ,
  313. "\C-n" => :rl_get_next_history ,
  314. "\C-p" => :rl_get_previous_history ,
  315. "\C-q" => :rl_quoted_insert ,
  316. "\C-r" => :rl_reverse_search_history ,
  317. "\C-s" => :rl_forward_search_history ,
  318. "\C-t" => :rl_transpose_chars ,
  319. "\C-u" => :rl_unix_line_discard ,
  320. "\C-v" => :rl_quoted_insert ,
  321. "\C-w" => :rl_unix_word_rubout ,
  322. "\C-y" => :rl_yank ,
  323. "\C-]" => :rl_char_search ,
  324. "\C-_" => :rl_undo_command ,
  325. "\x7F" => :rl_rubout ,
  326. "\e\C-g" => :rl_abort ,
  327. "\e\C-h" => :rl_backward_kill_word ,
  328. "\e\C-i" => :rl_tab_insert ,
  329. "\e\C-j" => :rl_vi_editing_mode ,
  330. "\e\C-m" => :rl_vi_editing_mode ,
  331. "\e\C-r" => :rl_revert_line ,
  332. "\e\C-y" => :rl_yank_nth_arg ,
  333. "\e\C-[" => :rl_complete ,
  334. "\e\C-]" => :rl_backward_char_search ,
  335. "\e " => :rl_set_mark ,
  336. "\e#" => :rl_insert_comment ,
  337. "\e&" => :rl_tilde_expand ,
  338. "\e*" => :rl_insert_completions ,
  339. "\e-" => :rl_digit_argument ,
  340. "\e." => :rl_yank_last_arg ,
  341. "\e0" => :rl_digit_argument ,
  342. "\e1" => :rl_digit_argument ,
  343. "\e2" => :rl_digit_argument ,
  344. "\e3" => :rl_digit_argument ,
  345. "\e4" => :rl_digit_argument ,
  346. "\e5" => :rl_digit_argument ,
  347. "\e6" => :rl_digit_argument ,
  348. "\e7" => :rl_digit_argument ,
  349. "\e8" => :rl_digit_argument ,
  350. "\e9" => :rl_digit_argument ,
  351. "\e<" => :rl_beginning_of_history ,
  352. "\e=" => :rl_possible_completions ,
  353. "\e>" => :rl_end_of_history ,
  354. "\e?" => :rl_possible_completions ,
  355. "\eB" => :rl_backward_word ,
  356. "\eC" => :rl_capitalize_word ,
  357. "\eD" => :rl_kill_word ,
  358. "\eF" => :rl_forward_word ,
  359. "\eL" => :rl_downcase_word ,
  360. "\eN" => :rl_noninc_forward_search ,
  361. "\eP" => :rl_noninc_reverse_search ,
  362. "\eR" => :rl_revert_line ,
  363. "\eT" => :rl_transpose_words ,
  364. "\eU" => :rl_upcase_word ,
  365. "\eY" => :rl_yank_pop ,
  366. "\e\\" => :rl_delete_horizontal_space ,
  367. "\e_" => :rl_yank_last_arg ,
  368. "\eb" => :rl_backward_word ,
  369. "\ec" => :rl_capitalize_word ,
  370. "\ed" => :rl_kill_word ,
  371. "\ef" => :rl_forward_word ,
  372. "\el" => :rl_downcase_word ,
  373. "\en" => :rl_noninc_forward_search ,
  374. "\ep" => :rl_noninc_reverse_search ,
  375. "\er" => :rl_revert_line ,
  376. "\et" => :rl_transpose_words ,
  377. "\eu" => :rl_upcase_word ,
  378. "\ey" => :rl_yank_pop ,
  379. "\e~" => :rl_tilde_expand ,
  380. "\377" => :rl_backward_kill_word ,
  381. "\C-x\C-g" => :rl_abort ,
  382. "\C-x\C-r" => :rl_re_read_init_file ,
  383. "\C-x\C-u" => :rl_undo_command ,
  384. "\C-x\C-x" => :rl_exchange_point_and_mark ,
  385. "\C-x(" => :rl_start_kbd_macro ,
  386. "\C-x)" => :rl_end_kbd_macro ,
  387. "\C-xE" => :rl_call_last_kbd_macro ,
  388. "\C-xe" => :rl_call_last_kbd_macro ,
  389. "\C-x\x7F" => :rl_backward_kill_line
  390. }
  391. @vi_movement_keymap = {
  392. "\C-d" => :rl_vi_eof_maybe ,
  393. "\C-e" => :rl_emacs_editing_mode ,
  394. "\C-g" => :rl_abort ,
  395. "\C-h" => :rl_backward_char ,
  396. "\C-j" => :rl_newline ,
  397. "\C-k" => :rl_kill_line ,
  398. "\C-l" => :rl_clear_screen ,
  399. "\C-m" => :rl_newline ,
  400. "\C-n" => :rl_get_next_history ,
  401. "\C-p" => :rl_get_previous_history ,
  402. "\C-q" => :rl_quoted_insert ,
  403. "\C-r" => :rl_reverse_search_history ,
  404. "\C-s" => :rl_forward_search_history ,
  405. "\C-t" => :rl_transpose_chars ,
  406. "\C-u" => :rl_unix_line_discard ,
  407. "\C-v" => :rl_quoted_insert ,
  408. "\C-w" => :rl_unix_word_rubout ,
  409. "\C-y" => :rl_yank ,
  410. "\C-_" => :rl_vi_undo ,
  411. " " => :rl_forward_char ,
  412. "#" => :rl_insert_comment ,
  413. "$" => :rl_end_of_line ,
  414. "%" => :rl_vi_match ,
  415. "&" => :rl_vi_tilde_expand ,
  416. "*" => :rl_vi_complete ,
  417. "+" => :rl_get_next_history ,
  418. "," => :rl_vi_char_search ,
  419. "-" => :rl_get_previous_history ,
  420. "." => :rl_vi_redo ,
  421. "/" => :rl_vi_search ,
  422. "0" => :rl_beg_of_line ,
  423. "1" => :rl_vi_arg_digit ,
  424. "2" => :rl_vi_arg_digit ,
  425. "3" => :rl_vi_arg_digit ,
  426. "4" => :rl_vi_arg_digit ,
  427. "5" => :rl_vi_arg_digit ,
  428. "6" => :rl_vi_arg_digit ,
  429. "7" => :rl_vi_arg_digit ,
  430. "8" => :rl_vi_arg_digit ,
  431. "9" => :rl_vi_arg_digit ,
  432. "" => :rl_vi_char_search ,
  433. "=" => :rl_vi_complete ,
  434. "?" => :rl_vi_search ,
  435. "A" => :rl_vi_append_eol ,
  436. "B" => :rl_vi_prev_word ,
  437. "C" => :rl_vi_change_to ,
  438. "D" => :rl_vi_delete_to ,
  439. "E" => :rl_vi_end_word ,
  440. "F" => :rl_vi_char_search ,
  441. "G" => :rl_vi_fetch_history ,
  442. "I" => :rl_vi_insert_beg ,
  443. "N" => :rl_vi_search_again ,
  444. "P" => :rl_vi_put ,
  445. "R" => :rl_vi_replace ,
  446. "S" => :rl_vi_subst ,
  447. "T" => :rl_vi_char_search ,
  448. "U" => :rl_revert_line ,
  449. "W" => :rl_vi_next_word ,
  450. "X" => :rl_vi_rubout ,
  451. "Y" => :rl_vi_yank_to ,
  452. "\\" => :rl_vi_complete ,
  453. "^" => :rl_vi_first_print ,
  454. "_" => :rl_vi_yank_arg ,
  455. "`" => :rl_vi_goto_mark ,
  456. "a" => :rl_vi_append_mode ,
  457. "b" => :rl_vi_prev_word ,
  458. "c" => :rl_vi_change_to ,
  459. "d" => :rl_vi_delete_to ,
  460. "e" => :rl_vi_end_word ,
  461. "f" => :rl_vi_char_search ,
  462. "h" => :rl_backward_char ,
  463. "i" => :rl_vi_insertion_mode ,
  464. "j" => :rl_get_next_history ,
  465. "k" => :rl_get_previous_history ,
  466. "l" => :rl_forward_char ,
  467. "m" => :rl_vi_set_mark ,
  468. "n" => :rl_vi_search_again ,
  469. "p" => :rl_vi_put ,
  470. "r" => :rl_vi_change_char ,
  471. "s" => :rl_vi_subst ,
  472. "t" => :rl_vi_char_search ,
  473. "u" => :rl_vi_undo ,
  474. "w" => :rl_vi_next_word ,
  475. "x" => :rl_vi_delete ,
  476. "y" => :rl_vi_yank_to ,
  477. "|" => :rl_vi_column ,
  478. "~" => :rl_vi_change_case
  479. }
  480. @vi_insertion_keymap = {
  481. "\C-a" => :rl_insert ,
  482. "\C-b" => :rl_insert ,
  483. "\C-c" => :rl_insert ,
  484. "\C-d" => :rl_vi_eof_maybe ,
  485. "\C-e" => :rl_insert ,
  486. "\C-f" => :rl_insert ,
  487. "\C-g" => :rl_insert ,
  488. "\C-h" => :rl_rubout ,
  489. "\C-i" => :rl_complete ,
  490. "\C-j" => :rl_newline ,
  491. "\C-k" => :rl_insert ,
  492. "\C-l" => :rl_insert ,
  493. "\C-m" => :rl_newline ,
  494. "\C-n" => :rl_insert ,
  495. "\C-o" => :rl_insert ,
  496. "\C-p" => :rl_insert ,
  497. "\C-q" => :rl_insert ,
  498. "\C-r" => :rl_reverse_search_history ,
  499. "\C-s" => :rl_forward_search_history ,
  500. "\C-t" => :rl_transpose_chars ,
  501. "\C-u" => :rl_unix_line_discard ,
  502. "\C-v" => :rl_quoted_insert ,
  503. "\C-w" => :rl_unix_word_rubout ,
  504. "\C-x" => :rl_insert ,
  505. "\C-y" => :rl_yank ,
  506. "\C-z" => :rl_insert ,
  507. "\C-[" => :rl_vi_movement_mode ,
  508. "\C-\\" => :rl_insert ,
  509. "\C-]" => :rl_insert ,
  510. "\C-^" => :rl_insert ,
  511. "\C-_" => :rl_vi_undo ,
  512. "\x7F" => :rl_rubout
  513. }
  514. @rl_library_version = RL_LIBRARY_VERSION
  515. @rl_readline_version = RL_READLINE_VERSION
  516. @rl_readline_name = "other"
  517. @rl_getc_function = :rl_getc
  518. # Non-zero tells rl_delete_text and rl_insert_text to not add to
  519. # the undo list.
  520. @_rl_doing_an_undo = false
  521. # How many unclosed undo groups we currently have.
  522. @_rl_undo_group_level = 0
  523. # The current undo list for THE_LINE.
  524. @rl_undo_list = nil
  525. # Application-specific redisplay function.
  526. @rl_redisplay_function = :rl_redisplay
  527. # Global variables declared here.
  528. # What YOU turn on when you have handled all redisplay yourself.
  529. @rl_display_fixed = false
  530. @_rl_suppress_redisplay = 0
  531. @_rl_want_redisplay = false
  532. # The stuff that gets printed out before the actual text of the line.
  533. # This is usually pointing to rl_prompt.
  534. @rl_display_prompt = nil
  535. # True if this is `real' readline as opposed to some stub substitute.
  536. @rl_gnu_readline_p = true
  537. for i in 32 .. 255
  538. @emacs_standard_keymap[i.chr] = :rl_insert unless @emacs_standard_keymap[i.chr]
  539. @vi_insertion_keymap[i.chr] = :rl_insert unless @vi_insertion_keymap[i.chr]
  540. end
  541. # A pointer to the keymap that is currently in use.
  542. # By default, it is the standard emacs keymap.
  543. @_rl_keymap = @emacs_standard_keymap
  544. # The current style of editing.
  545. @rl_editing_mode = @emacs_mode
  546. # The current insert mode: input (the default) or overwrite
  547. @rl_insert_mode = RL_IM_DEFAULT
  548. # Non-zero if we called this function from _rl_dispatch(). It's present
  549. # so functions can find out whether they were called from a key binding
  550. # or directly from an application.
  551. @rl_dispatching = false
  552. # Non-zero if the previous command was a kill command.
  553. @_rl_last_command_was_kill = false
  554. # The current value of the numeric argument specified by the user.
  555. @rl_numeric_arg = 1
  556. # Non-zero if an argument was typed.
  557. @rl_explicit_arg = false
  558. # Temporary value used while generating the argument.
  559. @rl_arg_sign = 1
  560. # Non-zero means we have been called at least once before.
  561. @rl_initialized = false
  562. # Flags word encapsulating the current readline state.
  563. @rl_readline_state = RL_STATE_NONE
  564. # The current offset in the current input line.
  565. @rl_point = 0
  566. # Mark in the current input line.
  567. @rl_mark = 0
  568. # Length of the current input line.
  569. @rl_end = 0
  570. # Make this non-zero to return the current input_line.
  571. @rl_done = false
  572. # The last function executed by readline.
  573. @rl_last_func = nil
  574. # Top level environment for readline_internal ().
  575. @readline_top_level = nil
  576. # The streams we interact with.
  577. @_rl_in_stream = nil
  578. @_rl_out_stream = nil
  579. # The names of the streams that we do input and output to.
  580. @rl_instream = nil
  581. @rl_outstream = nil
  582. @pop_index = 0
  583. @push_index = 0
  584. @ibuffer = 0.chr * 512
  585. @ibuffer_len = @ibuffer.length - 1
  586. # Non-zero means echo characters as they are read. Defaults to no echo
  587. # set to 1 if there is a controlling terminal, we can get its attributes,
  588. # and the attributes include `echo'. Look at rltty.c:prepare_terminal_settings
  589. # for the code that sets it.
  590. @readline_echoing_p = false
  591. # Current prompt.
  592. @rl_prompt = nil
  593. @rl_visible_prompt_length = 0
  594. # Set to non-zero by calling application if it has already printed rl_prompt
  595. # and does not want readline to do it the first time.
  596. @rl_already_prompted = false
  597. # The number of characters read in order to type this complete command.
  598. @rl_key_sequence_length = 0
  599. # If non-zero, then this is the address of a function to call just
  600. # before readline_internal_setup () prints the first prompt.
  601. @rl_startup_hook = nil
  602. # If non-zero, this is the address of a function to call just before
  603. # readline_internal_setup () returns and readline_internal starts
  604. # reading input characters.
  605. @rl_pre_input_hook = nil
  606. # The character that can generate an EOF. Really read from
  607. # the terminal driver... just defaulted here.
  608. @_rl_eof_char = "\cD"
  609. # Non-zero makes this the next keystroke to read.
  610. @rl_pending_input = 0
  611. # Pointer to a useful terminal name.
  612. @rl_terminal_name = nil
  613. # Non-zero means to always use horizontal scrolling in line display.
  614. @_rl_horizontal_scroll_mode = false
  615. # Non-zero means to display an asterisk at the starts of history lines
  616. # which have been modified.
  617. @_rl_mark_modified_lines = false
  618. # The style of `bell' notification preferred. This can be set to NO_BELL,
  619. # AUDIBLE_BELL, or VISIBLE_BELL.
  620. @_rl_bell_preference = AUDIBLE_BELL
  621. # String inserted into the line by rl_insert_comment ().
  622. @_rl_comment_begin = nil
  623. # Keymap holding the function currently being executed.
  624. @rl_executing_keymap = nil
  625. # Keymap we're currently using to dispatch.
  626. @_rl_dispatching_keymap = nil
  627. # Non-zero means to erase entire line, including prompt, on empty input lines.
  628. @rl_erase_empty_line = false
  629. # Non-zero means to read only this many characters rather than up to a
  630. # character bound to accept-line.
  631. @rl_num_chars_to_read = 0
  632. # Line buffer and maintenence.
  633. @rl_line_buffer = nil
  634. # Key sequence `contexts'
  635. @_rl_kscxt = nil
  636. # Non-zero means do not parse any lines other than comments and
  637. # parser directives.
  638. @_rl_parsing_conditionalized_out = false
  639. # Non-zero means to convert characters with the meta bit set to
  640. # escape-prefixed characters so we can indirect through
  641. # emacs_meta_keymap or vi_escape_keymap.
  642. @_rl_convert_meta_chars_to_ascii = true
  643. # Non-zero means to output characters with the meta bit set directly
  644. # rather than as a meta-prefixed escape sequence.
  645. @_rl_output_meta_chars = false
  646. # Non-zero means to look at the termios special characters and bind
  647. # them to equivalent readline functions at startup.
  648. @_rl_bind_stty_chars = true
  649. @rl_completion_display_matches_hook = nil
  650. XOK = 1
  651. @_rl_term_clreol = nil
  652. @_rl_term_clrpag = nil
  653. @_rl_term_cr = nil
  654. @_rl_term_backspace = nil
  655. @_rl_term_goto = nil
  656. @_rl_term_pc = nil
  657. # Non-zero if we determine that the terminal can do character insertion.
  658. @_rl_terminal_can_insert = false
  659. # How to insert characters.
  660. @_rl_term_im = nil
  661. @_rl_term_ei = nil
  662. @_rl_term_ic = nil
  663. @_rl_term_ip = nil
  664. @_rl_term_IC = nil
  665. # How to delete characters.
  666. @_rl_term_dc = nil
  667. @_rl_term_DC = nil
  668. @_rl_term_forward_char = nil
  669. # How to go up a line.
  670. @_rl_term_up = nil
  671. # A visible bell; char if the terminal can be made to flash the screen.
  672. @_rl_visible_bell = nil
  673. # Non-zero means the terminal can auto-wrap lines.
  674. @_rl_term_autowrap = true
  675. # Non-zero means that this terminal has a meta key.
  676. @term_has_meta = 0
  677. # The sequences to write to turn on and off the meta key, if this
  678. # terminal has one.
  679. @_rl_term_mm = nil
  680. @_rl_term_mo = nil
  681. # The key sequences output by the arrow keys, if this terminal has any.
  682. @_rl_term_ku = nil
  683. @_rl_term_kd = nil
  684. @_rl_term_kr = nil
  685. @_rl_term_kl = nil
  686. # How to initialize and reset the arrow keys, if this terminal has any.
  687. @_rl_term_ks = nil
  688. @_rl_term_ke = nil
  689. # The key sequences sent by the Home and End keys, if any.
  690. @_rl_term_kh = nil
  691. @_rl_term_kH = nil
  692. @_rl_term_at7 = nil
  693. # Delete key
  694. @_rl_term_kD = nil
  695. # Insert key
  696. @_rl_term_kI = nil
  697. # Cursor control
  698. @_rl_term_vs = nil # very visible
  699. @_rl_term_ve = nil # normal
  700. # Variables that hold the screen dimensions, used by the display code.
  701. @_rl_screenwidth = @_rl_screenheight = @_rl_screenchars = 0
  702. # Non-zero means the user wants to enable the keypad.
  703. @_rl_enable_keypad = false
  704. # Non-zero means the user wants to enable a meta key.
  705. @_rl_enable_meta = true
  706. # ****************************************************************
  707. #
  708. # Completion matching, from readline's point of view.
  709. #
  710. # ****************************************************************
  711. # Variables known only to the readline library.
  712. # If non-zero, non-unique completions always show the list of matches.
  713. @_rl_complete_show_all = false
  714. # If non-zero, non-unique completions show the list of matches, unless it
  715. # is not possible to do partial completion and modify the line.
  716. @_rl_complete_show_unmodified = false
  717. # If non-zero, completed directory names have a slash appended.
  718. @_rl_complete_mark_directories = true
  719. # If non-zero, the symlinked directory completion behavior introduced in
  720. # readline-4.2a is disabled, and symlinks that point to directories have
  721. # a slash appended (subject to the value of _rl_complete_mark_directories).
  722. # This is user-settable via the mark-symlinked-directories variable.
  723. @_rl_complete_mark_symlink_dirs = false
  724. # If non-zero, completions are printed horizontally in alphabetical order,
  725. # like `ls -x'.
  726. @_rl_print_completions_horizontally = false
  727. @_rl_completion_case_fold = false
  728. # If non-zero, don't match hidden files (filenames beginning with a `.' on
  729. # Unix) when doing filename completion.
  730. @_rl_match_hidden_files = true
  731. # Global variables available to applications using readline.
  732. # Non-zero means add an additional character to each filename displayed
  733. # during listing completion iff rl_filename_completion_desired which helps
  734. # to indicate the type of file being listed.
  735. @rl_visible_stats = false
  736. # If non-zero, then this is the address of a function to call when
  737. # completing on a directory name. The function is called with
  738. # the address of a string (the current directory name) as an arg.
  739. @rl_directory_completion_hook = nil
  740. @rl_directory_rewrite_hook = nil
  741. # Non-zero means readline completion functions perform tilde expansion.
  742. @rl_complete_with_tilde_expansion = false
  743. # Pointer to the generator function for completion_matches ().
  744. # NULL means to use rl_filename_completion_function (), the default filename
  745. # completer.
  746. @rl_completion_entry_function = nil
  747. # Pointer to alternative function to create matches.
  748. # Function is called with TEXT, START, and END.
  749. # START and END are indices in RL_LINE_BUFFER saying what the boundaries
  750. # of TEXT are.
  751. # If this function exists and returns NULL then call the value of
  752. # rl_completion_entry_function to try to match, otherwise use the
  753. # array of strings returned.
  754. @rl_attempted_completion_function = nil
  755. # Non-zero means to suppress normal filename completion after the
  756. # user-specified completion function has been called.
  757. @rl_attempted_completion_over = false
  758. # Set to a character indicating the type of completion being performed
  759. # by rl_complete_internal, available for use by application completion
  760. # functions.
  761. @rl_completion_type = 0
  762. # Up to this many items will be displayed in response to a
  763. # possible-completions call. After that, we ask the user if
  764. # she is sure she wants to see them all. A negative value means
  765. # don't ask.
  766. @rl_completion_query_items = 100
  767. @_rl_page_completions = 1
  768. # The basic list of characters that signal a break between words for the
  769. # completer routine. The contents of this variable is what breaks words
  770. # in the shell, i.e. " \t\n\"\\'`@$><="
  771. @rl_basic_word_break_characters = " \t\n\"\\'`@$><=|&{(" # })
  772. # List of basic quoting characters.
  773. @rl_basic_quote_characters = "\"'"
  774. # The list of characters that signal a break between words for
  775. # rl_complete_internal. The default list is the contents of
  776. # rl_basic_word_break_characters.
  777. @rl_completer_word_break_characters = nil
  778. # Hook function to allow an application to set the completion word
  779. # break characters before readline breaks up the line. Allows
  780. # position-dependent word break characters.
  781. @rl_completion_word_break_hook = nil
  782. # List of characters which can be used to quote a substring of the line.
  783. # Completion occurs on the entire substring, and within the substring
  784. # rl_completer_word_break_characters are treated as any other character,
  785. # unless they also appear within this list.
  786. @rl_completer_quote_characters = nil
  787. # List of characters that should be quoted in filenames by the completer.
  788. @rl_filename_quote_characters = nil
  789. # List of characters that are word break characters, but should be left
  790. # in TEXT when it is passed to the completion function. The shell uses
  791. # this to help determine what kind of completing to do.
  792. @rl_special_prefixes = nil
  793. # If non-zero, then disallow duplicates in the matches.
  794. @rl_ignore_completion_duplicates = true
  795. # Non-zero means that the results of the matches are to be treated
  796. # as filenames. This is ALWAYS zero on entry, and can only be changed
  797. # within a completion entry finder function.
  798. @rl_filename_completion_desired = false
  799. # Non-zero means that the results of the matches are to be quoted using
  800. # double quotes (or an application-specific quoting mechanism) if the
  801. # filename contains any characters in rl_filename_quote_chars. This is
  802. # ALWAYS non-zero on entry, and can only be changed within a completion
  803. # entry finder function.
  804. @rl_filename_quoting_desired = true
  805. # This function, if defined, is called by the completer when real
  806. # filename completion is done, after all the matching names have been
  807. # generated. It is passed a (char**) known as matches in the code below.
  808. # It consists of a NULL-terminated array of pointers to potential
  809. # matching strings. The 1st element (matches[0]) is the maximal
  810. # substring that is common to all matches. This function can re-arrange
  811. # the list of matches as required, but all elements of the array must be
  812. # free()'d if they are deleted. The main intent of this function is
  813. # to implement FIGNORE a la SunOS csh.
  814. @rl_ignore_some_completions_function = nil
  815. # Set to a function to quote a filename in an application-specific fashion.
  816. # Called with the text to quote, the type of match found (single or multiple)
  817. # and a pointer to the quoting character to be used, which the function can
  818. # reset if desired.
  819. #rl_filename_quoting_function = rl_quote_filename
  820. # Function to call to remove quoting characters from a filename. Called
  821. # before completion is attempted, so the embedded quotes do not interfere
  822. # with matching names in the file system. Readline doesn't do anything
  823. # with this it's set only by applications.
  824. @rl_filename_dequoting_function = nil
  825. # Function to call to decide whether or not a word break character is
  826. # quoted. If a character is quoted, it does not break words for the
  827. # completer.
  828. @rl_char_is_quoted_p = nil
  829. # If non-zero, the completion functions don't append anything except a
  830. # possible closing quote. This is set to 0 by rl_complete_internal and
  831. # may be changed by an application-specific completion function.
  832. @rl_completion_suppress_append = false
  833. # Character appended to completed words when at the end of the line. The
  834. # default is a space.
  835. @rl_completion_append_character = ' '
  836. # If non-zero, the completion functions don't append any closing quote.
  837. # This is set to 0 by rl_complete_internal and may be changed by an
  838. # application-specific completion function.
  839. @rl_completion_suppress_quote = false
  840. # Set to any quote character readline thinks it finds before any application
  841. # completion function is called.
  842. @rl_completion_quote_character = 0
  843. # Set to a non-zero value if readline found quoting anywhere in the word to
  844. # be completed set before any application completion function is called.
  845. @rl_completion_found_quote = false
  846. # If non-zero, a slash will be appended to completed filenames that are
  847. # symbolic links to directory names, subject to the value of the
  848. # mark-directories variable (which is user-settable). This exists so
  849. # that application completion functions can override the user's preference
  850. # (set via the mark-symlinked-directories variable) if appropriate.
  851. # It's set to the value of _rl_complete_mark_symlink_dirs in
  852. # rl_complete_internal before any application-specific completion
  853. # function is called, so without that function doing anything, the user's
  854. # preferences are honored.
  855. @rl_completion_mark_symlink_dirs = false
  856. # If non-zero, inhibit completion (temporarily).
  857. @rl_inhibit_completion = false
  858. # Variables local to this file.
  859. # Local variable states what happened during the last completion attempt.
  860. @completion_changed_buffer = nil
  861. # Non-zero means treat 0200 bit in terminal input as Meta bit.
  862. @_rl_meta_flag = false
  863. # Stack of previous values of parsing_conditionalized_out.
  864. @if_stack = []
  865. @if_stack_depth = 0
  866. # The last key bindings file read.
  867. @last_readline_init_file = nil
  868. # The file we're currently reading key bindings from.
  869. @current_readline_init_file = nil
  870. @current_readline_init_include_level = 0
  871. @current_readline_init_lineno = 0
  872. ENV["HOME"] ||= ENV["HOMEDRIVE"]+ENV["HOMEPATH"]
  873. @directory = nil
  874. @filename = nil
  875. @dirname = nil
  876. @users_dirname = nil
  877. @filename_len = 0
  878. attr_accessor :rl_attempted_completion_function,:rl_deprep_term_function,
  879. :rl_event_hook,:rl_attempted_completion_over,:rl_basic_quote_characters,
  880. :rl_basic_word_break_characters,:rl_completer_quote_characters,
  881. :rl_completer_word_break_characters,:rl_completion_append_character,
  882. :rl_filename_quote_characters,:rl_instream,:rl_library_version,:rl_outstream,
  883. :rl_readline_name,:history_length,:history_base
  884. module_function
  885. # Okay, now we write the entry_function for filename completion. In the
  886. # general case. Note that completion in the shell is a little different
  887. # because of all the pathnames that must be followed when looking up the
  888. # completion for a command.
  889. def rl_filename_completion_function(text, state)
  890. # If we don't have any state, then do some initialization.
  891. if (state == 0)
  892. # If we were interrupted before closing the directory or reading
  893. #all of its contents, close it.
  894. if(@directory)
  895. @directory.close
  896. @directory = nil
  897. end
  898. text.delete!(0.chr)
  899. @filename = text.dup
  900. if text.length == 0
  901. text = "."
  902. end
  903. @dirname = File.dirname(text)
  904. # We aren't done yet. We also support the "~user" syntax.
  905. # Save the version of the directory that the user typed.
  906. @users_dirname = @dirname.dup
  907. if (@dirname[0] == ?~)
  908. @dirname = File.expand_path(@dirname)
  909. end
  910. # The directory completion hook should perform any necessary
  911. # dequoting.
  912. if (@rl_directory_completion_hook && send(rl_directory_completion_hook,@dirname))
  913. @users_dirname = @dirname.dup
  914. elsif (@rl_completion_found_quote && @rl_filename_dequoting_function)
  915. # delete single and double quotes
  916. @temp = send(@rl_filename_dequoting_function,@users_dirname, @rl_completion_quote_character)
  917. @users_dirname = temp
  918. end
  919. @directory = Dir.new(@dirname)
  920. # Now dequote a non-null filename.
  921. if (@filename && @filename.length>0 && @rl_completion_found_quote && @rl_filename_dequoting_function)
  922. # delete single and double quotes
  923. temp = send(@rl_filename_dequoting_function,@filename, @rl_completion_quote_character)
  924. @filename = temp
  925. end
  926. @filename_len = @filename.length
  927. @rl_filename_completion_desired = true
  928. end
  929. # At this point we should entertain the possibility of hacking wildcarded
  930. # filenames, like /usr/man/man<WILD>/te<TAB>. If the directory name
  931. # contains globbing characters, then build an array of directories, and
  932. # then map over that list while completing.
  933. # *** UNIMPLEMENTED ***
  934. # Now that we have some state, we can read the directory.
  935. entry = nil
  936. while(@directory && (entry = @directory.read))
  937. d_name = entry
  938. # Special case for no filename. If the user has disabled the
  939. # `match-hidden-files' variable, skip filenames beginning with `.'.
  940. #All other entries except "." and ".." match.
  941. if (@filename_len == 0)
  942. if (!@_rl_match_hidden_files && d_name[0]==?.)
  943. next
  944. end
  945. if (d_name != '.' && d_name != '..')
  946. break
  947. end
  948. else
  949. # Otherwise, if these match up to the length of filename, then
  950. # it is a match.
  951. if (@_rl_completion_case_fold)
  952. break if d_name =~ /^#{Regexp.escape(@filename)}/i
  953. else
  954. break if d_name =~ /^#{Regexp.escape(@filename)}/
  955. end
  956. end
  957. end
  958. if entry.nil?
  959. if @directory
  960. @directory.close
  961. @directory = nil
  962. end
  963. @dirname = nil
  964. @filename = nil
  965. @users_dirname = nil
  966. return nil
  967. else
  968. if (@dirname != '.')
  969. if (@rl_complete_with_tilde_expansion && @users_dirname[0] == ?~)
  970. temp = @dirname
  971. if(temp[-1] != ?/)
  972. temp += '/'
  973. end
  974. else
  975. temp = @users_dirname
  976. if(temp[-1] != ?/)
  977. temp += '/'
  978. end
  979. end
  980. temp += entry
  981. else
  982. temp = entry.dup
  983. end
  984. return (temp)
  985. end
  986. end
  987. # A completion function for usernames.
  988. # TEXT contains a partial username preceded by a random
  989. # character (usually `~').
  990. def rl_username_completion_function(text, state)
  991. return nil if RUBY_PLATFORM =~ /mswin|mingw/
  992. if (state == 0)
  993. first_char = text[0]
  994. first_char_loc = (text[0] == ?~ ? 1 : 0)
  995. username = text[first_char_loc..-1]
  996. namelen = username.length
  997. Etc.setpwent()
  998. end
  999. while (entry = Etc.getpwent())
  1000. # Null usernames should result in all users as possible completions.
  1001. break if (namelen == 0 || entry.name =~ /^#{username}/ )
  1002. end
  1003. if entry.nil?
  1004. Etc.endpwent()
  1005. return nil
  1006. else
  1007. value = text.dup
  1008. value[first_char_loc..-1] = entry.name
  1009. if (first_char == ?~)
  1010. @rl_filename_completion_desired = true
  1011. end
  1012. return (value)
  1013. end
  1014. end
  1015. #*************************************************************
  1016. #
  1017. # Application-callable completion match generator functions
  1018. #
  1019. #*************************************************************
  1020. # Return an array of (char *) which is a list of completions for TEXT.
  1021. # If there are no completions, return a NULL pointer.
  1022. # The first entry in the returned array is the substitution for TEXT.
  1023. # The remaining entries are the possible completions.
  1024. # The array is terminated with a NULL pointer.
  1025. #
  1026. # ENTRY_FUNCTION is a function of two args, and returns a (char *).
  1027. # The first argument is TEXT.
  1028. # The second is a state argument it should be zero on the first call, and
  1029. # non-zero on subsequent calls. It returns a NULL pointer to the caller
  1030. # when there are no more matches.
  1031. #
  1032. def rl_completion_matches(text, entry_function)
  1033. matches = 0
  1034. match_list_size = 10
  1035. match_list = []
  1036. match_list[1] = nil
  1037. while (string = send(entry_function, text, matches))
  1038. match_list[matches+=1] = string
  1039. match_list[matches+1] = nil
  1040. end
  1041. # If there were any matches, then look through them finding out the
  1042. # lowest common denominator. That then becomes match_list[0].
  1043. if (matches!=0)
  1044. compute_lcd_of_matches(match_list, matches, text)
  1045. else # There were no matches.
  1046. match_list = nil
  1047. end
  1048. return (match_list)
  1049. end
  1050. def _rl_to_lower(char)
  1051. char.nil? ? nil : char.chr.downcase
  1052. end
  1053. # Find the common prefix of the list of matches, and put it into
  1054. # matches[0].
  1055. def compute_lcd_of_matches(match_list, matches, text)
  1056. # If only one match, just use that. Otherwise, compare each
  1057. # member of the list with the next, finding out where they
  1058. # stop matching.
  1059. if (matches == 1)
  1060. match_list[0] = match_list[1]
  1061. match_list[1] = nil
  1062. return 1
  1063. end
  1064. i = 1
  1065. low = 100000
  1066. while(i<matches)
  1067. if (@_rl_completion_case_fold)
  1068. si = 0
  1069. while((c1 = _rl_to_lower(match_list[i][si])) &&
  1070. (c2 = _rl_to_lower(match_list[i + 1][si])))
  1071. if !@rl_byte_oriented
  1072. if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si))
  1073. break
  1074. elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1)
  1075. si += v - 1
  1076. end
  1077. else
  1078. break if (c1 != c2)
  1079. end
  1080. si += 1
  1081. end
  1082. else
  1083. si = 0
  1084. while((c1 = match_list[i][si]) &&
  1085. (c2 = match_list[i + 1][si]))
  1086. if !@rl_byte_oriented
  1087. if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si))
  1088. break
  1089. elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1)
  1090. si += v - 1
  1091. end
  1092. else
  1093. break if (c1 != c2)
  1094. end
  1095. si += 1
  1096. end
  1097. end
  1098. if (low > si)
  1099. low = si
  1100. end
  1101. i += 1
  1102. end
  1103. # If there were multiple matches, but none matched up to even the
  1104. # first character, and the user typed something, use that as the
  1105. # value of matches[0].
  1106. if (low == 0 && text && text.length>0 )
  1107. match_list[0] = text.dup
  1108. else
  1109. # XXX - this might need changes in the presence of multibyte chars
  1110. # If we are ignoring case, try to preserve the case of the string
  1111. # the user typed in the face of multiple matches differing in case.
  1112. if (@_rl_completion_case_fold)
  1113. # We're making an assumption here:
  1114. # IF we're completing filenames AND
  1115. # the application has defined a filename dequoting function AND
  1116. # we found a quote character AND
  1117. # the application has requested filename quoting
  1118. # THEN
  1119. # we assume that TEXT was dequoted before checking against
  1120. # the file system and needs to be dequoted here before we
  1121. # check against the list of matches
  1122. # FI
  1123. if (@rl_filename_completion_desired &&
  1124. @rl_filename_dequoting_function &&
  1125. @rl_completion_found_quote &&
  1126. @rl_filename_quoting_desired)
  1127. dtext = send(@rl_filename_dequoting_function,text, @rl_completion_quote_character)
  1128. text = dtext
  1129. end
  1130. # sort the list to get consistent answers.
  1131. match_list = [match_list[0]] + match_list[1..-1].sort
  1132. si = text.length
  1133. if (si <= low)
  1134. for i in 1 .. matches
  1135. if match_list[i][0,si] == text
  1136. match_list[0] = match_list[i][0,low]
  1137. break
  1138. end
  1139. # no casematch, use first entry
  1140. if (i > matches)
  1141. match_list[0] = match_list[1][0,low]
  1142. end
  1143. end
  1144. else
  1145. # otherwise, just use the text the user typed.
  1146. match_list[0] = text[0,low]
  1147. end
  1148. else
  1149. match_list[0] = match_list[1][0,low]
  1150. end
  1151. end
  1152. return matches
  1153. end
  1154. def rl_vi_editing_mode(count, key)
  1155. _rl_set_insert_mode(RL_IM_INSERT, 1) # vi mode ignores insert mode
  1156. @rl_editing_mode = @vi_mode
  1157. rl_vi_insertion_mode(1, key)
  1158. 0
  1159. end
  1160. # Switching from one mode to the other really just involves
  1161. # switching keymaps.
  1162. def rl_vi_insertion_mode(count, key)
  1163. @_rl_keymap = @vi_insertion_keymap
  1164. @_rl_vi_last_key_before_insert = key
  1165. 0
  1166. end
  1167. def rl_emacs_editing_mode(count, key)
  1168. @rl_editing_mode = @emacs_mode
  1169. _rl_set_insert_mode(RL_IM_INSERT, 1) # emacs mode default is insert mode
  1170. @_rl_keymap = @emacs_standard_keymap
  1171. 0
  1172. end
  1173. # Function for the rest of the library to use to set insert/overwrite mode.
  1174. def _rl_set_insert_mode(im, force)
  1175. @r…

Large files files are truncated, but you can click here to view the full file