Module: RbReadline

Included in:
Readline
Defined in:
lib/rbreadline.rb,
lib/rbreadline/version.rb

Constant Summary collapse

RL_LIBRARY_VERSION =
"5.2"
RL_READLINE_VERSION =
0x0502
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
RB_READLINE_VERSION =
"0.5.5"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#history_base=(value) ⇒ Object

Sets the attribute history_base

Parameters:

  • value

    the value to set the attribute history_base to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def history_base=(value)
  @history_base = value
end

#history_length=(value) ⇒ Object

Sets the attribute history_length

Parameters:

  • value

    the value to set the attribute history_length to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def history_length=(value)
  @history_length = value
end

#rl_point=(value) ⇒ Object

Sets the attribute rl_point

Parameters:

  • value

    the value to set the attribute rl_point to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_point=(value)
  @rl_point = 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.


4991
4992
4993
4994
4995
4996
4997
4998
4999
# File 'lib/rbreadline.rb', line 4991

def __rl_fix_point(x)
  if (x > @rl_end)
    @rl_end
  elsif (x < 0)
    0
  else
    x
  end
end

._extract_last_quote(string, quote_char) ⇒ Object



7603
7604
7605
7606
7607
# File 'lib/rbreadline.rb', line 7603

def _extract_last_quote(string, quote_char)
  quote_char = Regexp.escape(quote_char)
  string =~ /(#{quote_char}(?:\\.|[^#{quote_char}])+?#{quote_char}) *$/
  $1
end

._rl_abort_internalObject

How to abort things.



4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
# File 'lib/rbreadline.rb', line 4796

def _rl_abort_internal()
  rl_ding()
  rl_clear_message()
  _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


8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
# File 'lib/rbreadline.rb', line 8616

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'
    x = string.scan(/./me)
    i, len = 0, x.length
    while (pos < point && i < len)
      pos += x[i].length
      i += 1
    end
  when 'S'
    x = string.scan(/./ms)
    i, len = 0, x.length
    while (pos < point && i < len)
      pos += x[i].length
      i += 1
    end
  when 'U'
    x = string.scan(/./mu)
    i, len = 0, x.length
    while (pos < point && i < len)
      pos += x[i].length
      i += 1
    end
  when 'X'
    enc = string.encoding
    str = string.force_encoding(@encoding_name)
    len = str.length
    if point <= length / 2
      # count byte size from head
      i = 0
      while (pos < point && i < len)
        pos += str[i].bytesize
        i += 1
      end
    else
      # count byte size from tail
      pos = str.bytesize
      i = len - 1
      while (pos > point && i >= 0)
        pos -= str[i].bytesize
        i -= 1
      end
      pos += str[i + 1].bytesize if pos < point
    end
    string.force_encoding(enc)
  else
    pos = point
  end
  pos - point
end

._rl_any_typeinObject



5561
5562
5563
# File 'lib/rbreadline.rb', line 5561

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.


7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
# File 'lib/rbreadline.rb', line 7806

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_clear_message()
      rl_unsetstate(RL_STATE_NUMERICARG)
      if key.is_a?(Integer) && key < 0
        return -1
      end
      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_clear_message()
    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_getcharObject



7795
7796
7797
7798
7799
7800
7801
# File 'lib/rbreadline.rb', line 7795

def _rl_arg_getchar()
  rl_message("(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_initObject



7789
7790
7791
7792
7793
# File 'lib/rbreadline.rb', line 7789

def _rl_arg_init()
  rl_save_prompt()
  @_rl_argcxt = 0
  rl_setstate(RL_STATE_NUMERICARG)
end

._rl_arg_overflowObject



7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
# File 'lib/rbreadline.rb', line 7866

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_clear_message()
    rl_unsetstate(RL_STATE_NUMERICARG)
    return 1
  end
  0
end

._rl_backspace(count) ⇒ Object

Move the cursor back.



4681
4682
4683
4684
4685
4686
4687
4688
# File 'lib/rbreadline.rb', line 4681

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



6992
6993
6994
6995
6996
6997
# File 'lib/rbreadline.rb', line 6992

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



7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
# File 'lib/rbreadline.rb', line 7636

def _rl_char_search(count, fdir, bdir)
  mbchar = ''
  mb_len = _rl_read_mbchar(mbchar, MB_LEN_MAX)

  if (mbchar.is_a?(Integer) && c < 0) || mbchar == 0.chr
    return -1
  end

  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



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
# File 'lib/rbreadline.rb', line 7609

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



5203
5204
5205
# File 'lib/rbreadline.rb', line 5203

def _rl_char_value(buf,ind)
  buf[ind,1]
end

._rl_clean_up_for_exitObject



1518
1519
1520
1521
1522
1523
1524
1525
# File 'lib/rbreadline.rb', line 1518

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_screenObject



4672
4673
4674
4675
4676
4677
4678
# File 'lib/rbreadline.rb', line 4672

def _rl_clear_screen()
  if (@_rl_term_clrpag)
    @rl_outstream.write(@_rl_term_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,


4649
4650
4651
4652
4653
4654
4655
# File 'lib/rbreadline.rb', line 4649

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



3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
# File 'lib/rbreadline.rb', line 3887

def _rl_col_width(string,start,_end)
  return 0 if _end <= start

  # Find the first occurance of 0.chr, which marks the end of the string.
  # Because newlines are also in the string as 0.chrs (they are tracked
  # seperately), we need to ignore any 0.chrs that lie before _end.
  index = string[_end...string.length].index(0.chr)

  str = index ? string[0,index+_end] : 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.


8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
# File 'lib/rbreadline.rb', line 8736

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



7029
7030
7031
7032
7033
7034
7035
# File 'lib/rbreadline.rb', line 7029

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.


5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
# File 'lib/rbreadline.rb', line 5934

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_lineObject

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.


5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
# File 'lib/rbreadline.rb', line 5317

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.


4361
4362
4363
4364
# File 'lib/rbreadline.rb', line 4361

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



4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
# File 'lib/rbreadline.rb', line 4367

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].ord < 0x7f)
      _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_keyObject



2478
2479
2480
2481
2482
# File 'lib/rbreadline.rb', line 2478

def _rl_enable_meta_key()
  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.



5862
5863
5864
5865
5866
5867
5868
5869
# File 'lib/rbreadline.rb', line 5862

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_lineObject



4707
4708
4709
4710
4711
4712
# File 'lib/rbreadline.rb', line 4707

def _rl_erase_entire_line()
  cr()
  _rl_clear_to_eol(0)
  cr()
  @rl_outstream.flush
end

._rl_find_completion_wordObject



6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
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
6237
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
6268
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
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
# File 'lib/rbreadline.rb', line 6190

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 !@rl_byte_oriented
        scan = _rl_find_next_mbchar(@rl_line_buffer, scan, 1, MB_FIND_ANY)
      else
        scan += 1
      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,1] == "\\")
        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
    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.


8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
# File 'lib/rbreadline.rb', line 8677

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

  str = (flags == MB_FIND_NONZERO) ? string.sub(/\x00+$/,'') : string

  case @encoding
  when 'E'
    point += str[point..-1].scan(/./me)[0,count].to_s.length
  when 'S'
    point += str[point..-1].scan(/./ms)[0,count].to_s.length
  when 'U'
    point += str[point..-1].scan(/./mu)[0,count].to_s.length
  when 'X'
    point += str[point..-1].force_encoding(@encoding_name)[0,count].bytesize
  else
    point += count
    point = str.length if point >= str.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.


8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
# File 'lib/rbreadline.rb', line 8710

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



5001
5002
5003
5004
5005
5006
# File 'lib/rbreadline.rb', line 5001

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.



8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
# File 'lib/rbreadline.rb', line 8757

def _rl_get_char_len(src)
  return 0 if src[0,1] == 0.chr || 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.


1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
# File 'lib/rbreadline.rb', line 1859

def _rl_get_screen_size(tty, ignore_env)

  if @hConsoleHandle
    csbi = Fiddle::Pointer.malloc(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 = 0
    retry_if_interrupted do
      wr, wc = `stty size`.split(' ').map { |x| x.to_i }
    end
    @_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_pointObject



5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
# File 'lib/rbreadline.rb', line 5495

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_eightbitObject



2079
2080
2081
# File 'lib/rbreadline.rb', line 2079

def _rl_init_eightbit()

end

._rl_init_line_stateObject



2598
2599
2600
2601
# File 'lib/rbreadline.rb', line 2598

def _rl_init_line_state()
  @rl_point = @rl_end = @rl_mark = 0
  @rl_line_buffer = ""
end

._rl_init_terminal_io(terminal_name) ⇒ Object



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
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
# File 'lib/rbreadline.rb', line 1971

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

  # 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_input_availableObject



4060
4061
4062
# File 'lib/rbreadline.rb', line 4060

def _rl_input_available
  IO.select([ $stdin ], nil, [ $stdin ], @_keyboard_input_timeout)
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.


5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
# File 'lib/rbreadline.rb', line 5580

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.



5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
# File 'lib/rbreadline.rb', line 5658

def _rl_insert_next(count)
  rl_setstate(RL_STATE_MOREINPUT)
  c = rl_read_key()
  rl_unsetstate(RL_STATE_MOREINPUT)

  if c.is_a?(Integer) && c < 0
    return -1
  end

  _rl_insert_char(count, c)
end

._rl_insert_typein(c) ⇒ Object



5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
# File 'lib/rbreadline.rb', line 5565

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_cleanupObject



4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
# File 'lib/rbreadline.rb', line 4714

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



6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
# File 'lib/rbreadline.rb', line 6541

def _rl_internal_pager(lines)
  @rl_outstream.write("--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



8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
# File 'lib/rbreadline.rb', line 8822

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



4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
# File 'lib/rbreadline.rb', line 4347

def _rl_isearch_cleanup(cxt, r)
  if (r >= 0)
    _rl_isearch_fini(cxt)
  end
  @_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.


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
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
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
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
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
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
# File 'lib/rbreadline.rb', line 4067

def _rl_isearch_dispatch(cxt, c)
  f = nil

  if c.is_a?(Integer) && c < 0
    cxt.sflags |= SF_FAILED
    cxt.history_pos = cxt.last_found_line
    return -1
  end

  # 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.lastc.class == String && 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_index -= 1
      cxt.search_string.chop!
    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()
    rl_clear_message()
    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



4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
# File 'lib/rbreadline.rb', line 4311

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.
  rl_clear_message()
end

._rl_isearch_init(direction) ⇒ Object



7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
# File 'lib/rbreadline.rb', line 7269

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 = []
  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 << 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 = ""

  # 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



8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
# File 'lib/rbreadline.rb', line 8169

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.


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
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
# File 'lib/rbreadline.rb', line 1532

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)

    # Use NEW when comparing against the last invisible character in the
    # prompt string, since they're both buffer indices and DPOS is a desired
    # display position.
    if (new > @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 = Fiddle::Pointer.malloc(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.



1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
# File 'lib/rbreadline.rb', line 1618

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



8228
8229
8230
8231
8232
8233
8234
8235
# File 'lib/rbreadline.rb', line 8228

def _rl_nsearch_abort(cxt)
  rl_maybe_unsave_line()
  rl_clear_message()
  @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



8221
8222
8223
8224
8225
8226
# File 'lib/rbreadline.rb', line 8221

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.


8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
# File 'lib/rbreadline.rb', line 8240

def _rl_nsearch_dispatch(cxt, c)
  case (c)
  when "\C-W"
    rl_unix_word_rubout(1, c)
  when "\C-U"
    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.


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
# File 'lib/rbreadline.rb', line 8274

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



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
# File 'lib/rbreadline.rb', line 8195

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,1] = 0.chr
  @rl_end = @rl_point = 0

  _p = _rl_make_prompt_for_search(pchar ? pchar : ':')
  rl_message(_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.



3914
3915
3916
3917
3918
3919
3920
3921
# File 'lib/rbreadline.rb', line 3914

def _rl_output_some_chars(string,start,count)
  case @encoding
  when 'X'
    @_rl_out_stream.write(string[start, count].force_encoding(@encoding_name))
  else
    @_rl_out_stream.write(string[start, count])
  end
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.


5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
# File 'lib/rbreadline.rb', line 5626

def _rl_overwrite_char(count, c)

  # Read an entire multibyte character sequence to insert COUNT times.
  if (count > 0 && !@rl_byte_oriented)
    mbkey = ''
    _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.


5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
# File 'lib/rbreadline.rb', line 5810

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



2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
# File 'lib/rbreadline.rb', line 2112

def _rl_read_init_file(filename, include_level)
  @current_readline_init_file = filename
  @current_readline_init_include_level = include_level

  openname = File.expand_path(filename)
  begin
    buffer = nil
    File.open(openname) do |file|
      buffer = file.read
    end
  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



8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
# File 'lib/rbreadline.rb', line 8776

def _rl_read_mbchar(mbchar, size)
  mb_len = 0
  while (mb_len < size)
    rl_setstate(RL_STATE_MOREINPUT)
    c = rl_read_key()
    rl_unsetstate(RL_STATE_MOREINPUT)

    break if c.is_a?(Integer) && c < 0

    mbchar << c
    mb_len += 1
    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.


8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
# File 'lib/rbreadline.rb', line 8805

def _rl_read_mbstring(first, mb, mlen)
  c = first
  (0...mlen).each do
    mb << c
    if _rl_get_char_len(mb) == -2
      # Read more for multibyte character
      rl_setstate(RL_STATE_MOREINPUT)
      c = rl_read_key()
      break if c.is_a?(Integer) && c < 0
      rl_unsetstate(RL_STATE_MOREINPUT)
    else
      break
    end
  end
  c
end

._rl_redisplay_after_sigwinchObject

Redisplay the current line after a SIGWINCH is received.



8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
# File 'lib/rbreadline.rb', line 8853

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)


5030
5031
5032
5033
5034
5035
5036
5037
# File 'lib/rbreadline.rb', line 5030

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_argumentObject

Create a default argument.



4017
4018
4019
4020
4021
# File 'lib/rbreadline.rb', line 4017

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



5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
# File 'lib/rbreadline.rb', line 5871

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



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 7229

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,:mb).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



4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
# File 'lib/rbreadline.rb', line 4044

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.



1449
1450
1451
# File 'lib/rbreadline.rb', line 1449

def _rl_set_insert_mode(im, force)
  @rl_insert_mode = im
end

._rl_set_mark_at_pos(position) ⇒ Object

Set the mark at POSITION.



7124
7125
7126
7127
7128
# File 'lib/rbreadline.rb', line 7124

def _rl_set_mark_at_pos(position)
  return -1 if (position > @rl_end)
  @rl_mark = position
  0
end

._rl_start_using_historyObject

Set the history pointer back to the last entry in the history.



2604
2605
2606
2607
# File 'lib/rbreadline.rb', line 2604

def _rl_start_using_history()
  using_history()
  @_rl_saved_line_for_history = nil
end

._rl_strip_prompt(pmt) ⇒ Object



3883
3884
3885
# File 'lib/rbreadline.rb', line 3883

def _rl_strip_prompt(pmt)
  return expand_prompt(pmt).first
end

._rl_subseq_getchar(key) ⇒ Object



4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
# File 'lib/rbreadline.rb', line 4633

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



1312
1313
1314
# File 'lib/rbreadline.rb', line 1312

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.


4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
# File 'lib/rbreadline.rb', line 4621

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_finalObject



5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
# File 'lib/rbreadline.rb', line 5732

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],1] == 0.chr )
    @_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_insertingObject



5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
# File 'lib/rbreadline.rb', line 5692

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_lineObject



3839
3840
3841
# File 'lib/rbreadline.rb', line 3839

def _rl_vi_initialize_line
  rl_unsetstate(RL_STATE_VICMDONCE)
end

._rl_vi_reset_lastObject



5725
5726
5727
5728
5729
5730
# File 'lib/rbreadline.rb', line 5725

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



5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
# File 'lib/rbreadline.rb', line 5679

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?



5721
5722
5723
# File 'lib/rbreadline.rb', line 5721

def _rl_vi_textmod_command(c)
  return @vi_textmod[c]
end

._rl_walphabetic(c) ⇒ Object



5219
5220
5221
# File 'lib/rbreadline.rb', line 5219

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.


6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
# File 'lib/rbreadline.rb', line 6153

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



6133
6134
6135
6136
6137
6138
6139
6140
# File 'lib/rbreadline.rb', line 6133

def alloc_history_entry(string, ts)
  temp = Struct.new(:line,:data,:timestamp).new
  temp.line = string ? string.encode('UTF-8', invalid: :replace, undef: :replace, replace: '').delete(0.chr) : string
  temp.data = nil
  temp.timestamp = ts

  return temp
end

.alloc_undo_entry(what, start, _end, text) ⇒ Object



4930
4931
4932
4933
4934
4935
4936
4937
4938
# File 'lib/rbreadline.rb', line 4930

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).



8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
# File 'lib/rbreadline.rb', line 8469

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.expand_path(text)
    return temp_string_index unless File.exists? filename

    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,1] == 0.chr && @rl_line_buffer[@rl_point - 1,1] == '/' )

        elsif (@rl_line_buffer[@rl_point,1] != '/')
          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_keysObject

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.


2540
2541
2542
2543
2544
# File 'lib/rbreadline.rb', line 2540

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.



2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
# File 'lib/rbreadline.rb', line 2503

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.



1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
# File 'lib/rbreadline.rb', line 1953

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_sigintObject



6942
6943
6944
6945
6946
# File 'lib/rbreadline.rb', line 6942

def block_sigint()
  return if @sigint_blocked
  @sigint_proc = Signal.trap("INT", "IGNORE")
  @sigint_blocked = true
end

.clear_historyObject



8551
8552
8553
8554
# File 'lib/rbreadline.rb', line 8551

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].


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
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
# File 'lib/rbreadline.rb', line 1318

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

.crObject

Move to the start of the current line.



4700
4701
4702
4703
4704
4705
# File 'lib/rbreadline.rb', line 4700

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



2610
2611
2612
# File 'lib/rbreadline.rb', line 2610

def cr_faster(new, cur)
  (new + 1) < (cur - new)
end

.ctrl_char(c) ⇒ Object



2667
2668
2669
# File 'lib/rbreadline.rb', line 2667

def ctrl_char(c)
  c < "\x20"
end

.current_historyObject

Return the history entry at the current position, as determined by

history_offset.  If there is no entry there, return a NULL pointer.


2659
2660
2661
# File 'lib/rbreadline.rb', line 2659

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.



8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
# File 'lib/rbreadline.rb', line 8596

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.



6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
# File 'lib/rbreadline.rb', line 6722

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



4056
4057
4058
# File 'lib/rbreadline.rb', line 4056

def endsrch_char(c)
  ((ctrl_char(c) || meta_char(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'.


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
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/rbreadline.rb', line 1676

def expand_prompt(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



6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
# File 'lib/rbreadline.rb', line 6502

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



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
# File 'lib/rbreadline.rb', line 6672

def fnwidth(string)
  left = string.length + 1
  width = pos = 0
  while (string[pos] && string[pos,1] != 0.chr)
    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



6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
# File 'lib/rbreadline.rb', line 6321

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



1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
# File 'lib/rbreadline.rb', line 1813

def get_term_capabilities(buffer)
  hash = {}
    `infocmp -C`.split(':').select{|x| x =~ /(.*)=(.*)/ and hash[$1]=$2.gsub("\\r", "\r").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.



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
# File 'lib/rbreadline.rb', line 6645

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 || (c.is_a?(Integer) && c < 0))
      _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 `$'.


2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
# File 'lib/rbreadline.rb', line 2235

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_inittimeObject



6142
6143
6144
6145
6146
6147
6148
6149
# File 'lib/rbreadline.rb', line 6142

def hist_inittime()
  t = Time.now.to_i
  ts = "X%u" % t
  ret = ts.dup
  ret[0,1] = @history_comment_char

  ret
end

.history_arg_extract(first, last, string) ⇒ Object



7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
# File 'lib/rbreadline.rb', line 7576

def history_arg_extract(first, last, string)
  if first != "$" || last != "$"
    fail "RbReadline.history_arg_extract called with currently unsupported args."
  end

  # Find the last index of an unescaped quote character.
  last_unescaped_quote_char = -1
  RbReadline::HISTORY_QUOTE_CHARACTERS.each_char do |quote_char|
    quote_char = Regexp.escape(quote_char)
    if index = string =~ /(?:\\.|[^#{quote_char}\\])#{quote_char} *$/
      last_unescaped_quote_char = index if index > last_unescaped_quote_char
    end
  end
  last_unescaped_quote_char += 1 # Because of the regex used above.

  # Find the last index of an unescaped word delimiter.
  delimiters = RbReadline::HISTORY_WORD_DELIMITERS.chars.to_a.map { |d| Regexp.escape(d) }
  unless last_unescaped_delimiter = string =~ /(?:\\.|[^#{delimiters.join}])+? *$/
    last_unescaped_delimiter = 0
  end

  if last_unescaped_quote_char >= last_unescaped_delimiter
    quoted_arg = _extract_last_quote(string, string[last_unescaped_quote_char,1])
  end
  quoted_arg or string[last_unescaped_delimiter...string.length]
end

.history_baseObject

Returns the value of attribute history_base.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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.


6909
6910
6911
6912
6913
# File 'lib/rbreadline.rb', line 6909

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_stifledObject



8547
8548
8549
# File 'lib/rbreadline.rb', line 8547

def history_is_stifled()
  return (@history_stifled)
end

.history_lengthObject

Returns the value of attribute history_length.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def history_length
  @history_length
end

.history_listObject



7265
7266
7267
# File 'lib/rbreadline.rb', line 7265

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.


8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
# File 'lib/rbreadline.rb', line 8097

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.



8090
8091
8092
# File 'lib/rbreadline.rb', line 8090

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.


8081
8082
8083
8084
8085
8086
8087
# File 'lib/rbreadline.rb', line 8081

def history_set_pos(pos)
  if (pos > @history_length || pos < 0 || @the_history.nil?)
    return (0)
  end
  @history_offset = pos
  1
end

.ibuffer_spaceObject

Return the amount of space available in the buffer for stuffing

characters.


4593
4594
4595
4596
4597
4598
4599
# File 'lib/rbreadline.rb', line 4593

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.


2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
# File 'lib/rbreadline.rb', line 2631

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



6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
# File 'lib/rbreadline.rb', line 6389

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



6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
# File 'lib/rbreadline.rb', line 6461

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.



8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
# File 'lib/rbreadline.rb', line 8557

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



2703
2704
2705
# File 'lib/rbreadline.rb', line 2703

def inv_line(line)
  @invisible_line[@inv_lbreaks[line] .. -1]
end

.inv_llen(l) ⇒ Object



2687
2688
2689
# File 'lib/rbreadline.rb', line 2687

def inv_llen(l)
  (@inv_lbreaks[l+1] - @inv_lbreaks[l])
end

.isascii(c) ⇒ Object



8015
8016
8017
8018
# File 'lib/rbreadline.rb', line 8015

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



2671
2672
2673
# File 'lib/rbreadline.rb', line 2671

def isprint(c)
  c >= "\x20" && c < "\x7f"
end

.m_offset(margin, offset) ⇒ Object



2707
2708
2709
# File 'lib/rbreadline.rb', line 2707

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.


8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
# File 'lib/rbreadline.rb', line 8064

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



6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
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
# File 'lib/rbreadline.rb', line 6420

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



2663
2664
2665
# File 'lib/rbreadline.rb', line 2663

def meta_char(c)
  c > "\x7f" && c <= "\xff"
end

.next_historyObject

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.


5445
5446
5447
# File 'lib/rbreadline.rb', line 5445

def next_history()
  (@history_offset == @history_length) ? nil : @the_history[@history_offset+=1]
end

.no_terminal?Boolean

Returns:

  • (Boolean)


8914
8915
8916
8917
# File 'lib/rbreadline.rb', line 8914

def no_terminal?
  term = ENV["TERM"]
  term.nil? || (term == 'dumb') || (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.


8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
# File 'lib/rbreadline.rb', line 8138

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_clear_message()
    @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
  rl_clear_message()
  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 `:'.


8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
# File 'lib/rbreadline.rb', line 8025

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.


8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
# File 'lib/rbreadline.rb', line 8114

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.



2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
# File 'lib/rbreadline.rb', line 2191

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.


2208
2209
2210
2211
2212
2213
2214
2215
# File 'lib/rbreadline.rb', line 2208

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.


2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
# File 'lib/rbreadline.rb', line 2148

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



2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
# File 'lib/rbreadline.rb', line 2217

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



6555
6556
6557
# File 'lib/rbreadline.rb', line 6555

def path_isdir(filename)
  return File.directory?(filename)
end

.postprocess_matches(matchesp, matching_filenames) ⇒ Object



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 6353

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



6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
# File 'lib/rbreadline.rb', line 6999

def prepare_terminal_settings(meta_flag)
  retry_if_interrupted do
    @readline_echoing_p = (`stty -a`.scan(/-*echo\b/).first == 'echo')
  end

  # 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.
  retry_if_interrupted do
    if (`stty -a`.scan(/-parenb\b/).first == '-parenb')
      setting << " pass8"
    end
  end

  setting << " -ixoff"

  rl_bind_key(@_rl_tty_chars.t_start, :rl_restart_output) unless @_rl_tty_chars.t_start.nil?
  @_rl_eof_char = @_rl_tty_chars.t_eof

  #setting << " -isig"

  retry_if_interrupted do
    `stty #{setting}`
  end
end

.previous_historyObject

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.


5438
5439
5440
# File 'lib/rbreadline.rb', line 5438

def previous_history()
  @history_offset!=0 ? @the_history[@history_offset-=1] : nil
end

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.


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
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
# File 'lib/rbreadline.rb', line 6584

def print_filename(to_print, full_pathname)
  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.expand_path(dn)
      if (@rl_directory_completion_hook)
        send(@rl_directory_completion_hook,s)
      end

      slen = s.length
      new_full_pathname = s.dup
      if (s[-1,1] == '/' )
        slen-=1
      else
        new_full_pathname[slen,1] = '/'
      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.expand_path(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.


6492
6493
6494
6495
6496
6497
6498
6499
6500
# File 'lib/rbreadline.rb', line 6492

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_indexObject

  • _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.



2618
2619
2620
2621
2622
2623
2624
# File 'lib/rbreadline.rb', line 2618

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.


4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
# File 'lib/rbreadline.rb', line 4859

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_bindingsObject

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.


2073
2074
2075
2076
2077
# File 'lib/rbreadline.rb', line 2073

def readline_default_bindings()
  if @_rl_bind_stty_chars
    rl_tty_set_default_bindings(@_rl_keymap)
  end
end

.readline_initialize_everythingObject

Initialize the entire state of the world.



2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
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
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
# File 'lib/rbreadline.rb', line 2547

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 they 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 = ""

  # 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
    _rl_enable_meta_key()
  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_internalObject

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.


4851
4852
4853
4854
4855
# File 'lib/rbreadline.rb', line 4851

def readline_internal()
  readline_internal_setup()
  eof = readline_internal_charloop()
  readline_internal_teardown(eof)
end

.readline_internal_charloopObject



4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
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
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
# File 'lib/rbreadline.rb', line 4740

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_setupObject



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
# File 'lib/rbreadline.rb', line 3982

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



4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
# File 'lib/rbreadline.rb', line 4822

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.



8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
# File 'lib/rbreadline.rb', line 8836

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 =
    expand_prompt(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_sigintObject



6948
6949
6950
6951
6952
# File 'lib/rbreadline.rb', line 6948

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.


6343
6344
6345
6346
6347
6348
6349
6350
6351
# File 'lib/rbreadline.rb', line 6343

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.


6932
6933
6934
6935
6936
6937
6938
6939
6940
# File 'lib/rbreadline.rb', line 6932

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.


5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
# File 'lib/rbreadline.rb', line 5058

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.


5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
# File 'lib/rbreadline.rb', line 5412

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.timestamp = old_value.timestamp.dup
  @the_history[which] = temp
  old_value
end

.retry_if_interrupted(&block) ⇒ Object



6954
6955
6956
6957
6958
6959
6960
6961
6962
# File 'lib/rbreadline.rb', line 6954

def retry_if_interrupted(&block)
  tries = 0
  begin
    yield block
  rescue Errno::EINTR
    tries += 1
    retry if tries <= 10
  end
end

.rl_abort(count, key) ⇒ Object



4811
4812
4813
# File 'lib/rbreadline.rb', line 4811

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.



4942
4943
4944
4945
4946
# File 'lib/rbreadline.rb', line 4942

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



5210
5211
5212
5213
5214
5215
5216
5217
# File 'lib/rbreadline.rb', line 5210

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



5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
# File 'lib/rbreadline.rb', line 5541

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_functionObject

Returns the value of attribute rl_attempted_completion_function.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_attempted_completion_function
  @rl_attempted_completion_function
end

.rl_attempted_completion_function=(value) ⇒ Object

Sets the attribute rl_attempted_completion_function

Parameters:

  • value

    the value to set the attribute rl_attempted_completion_function to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_attempted_completion_function=(value)
  @rl_attempted_completion_function = value
end

.rl_attempted_completion_overObject

Returns the value of attribute rl_attempted_completion_over.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_attempted_completion_over
  @rl_attempted_completion_over
end

.rl_attempted_completion_over=(value) ⇒ Object

Sets the attribute rl_attempted_completion_over

Parameters:

  • value

    the value to set the attribute rl_attempted_completion_over to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_attempted_completion_over=(value)
  @rl_attempted_completion_over = value
end

.rl_backward(count, key) ⇒ Object

Backwards compatibility.



5187
5188
5189
# File 'lib/rbreadline.rb', line 5187

def rl_backward(count, key)
  rl_backward_char(count, key)
end

.rl_backward_byte(count, key) ⇒ Object

Move backward COUNT bytes.



5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
# File 'lib/rbreadline.rb', line 5142

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.



5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
# File 'lib/rbreadline.rb', line 5162

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



7781
7782
7783
# File 'lib/rbreadline.rb', line 7781

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.


7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
# File 'lib/rbreadline.rb', line 7156

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.



7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
# File 'lib/rbreadline.rb', line 7750

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.



5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
# File 'lib/rbreadline.rb', line 5279

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_charactersObject

Returns the value of attribute rl_basic_quote_characters.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_basic_quote_characters
  @rl_basic_quote_characters
end

.rl_basic_quote_characters=(value) ⇒ Object

Sets the attribute rl_basic_quote_characters

Parameters:

  • value

    the value to set the attribute rl_basic_quote_characters to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_basic_quote_characters=(value)
  @rl_basic_quote_characters = value
end

.rl_basic_word_break_charactersObject

Returns the value of attribute rl_basic_word_break_characters.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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

Parameters:

  • value

    the value to set the attribute rl_basic_word_break_characters to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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.



5192
5193
5194
5195
# File 'lib/rbreadline.rb', line 5192

def rl_beg_of_line(count, key)
  @rl_point = 0
  0
end

.rl_begin_undo_groupObject

Begin a group. Subsequent undos are undone as an atomic operation.



5009
5010
5011
5012
5013
# File 'lib/rbreadline.rb', line 5009

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.



7916
7917
7918
# File 'lib/rbreadline.rb', line 7916

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.



2441
2442
2443
2444
2445
# File 'lib/rbreadline.rb', line 2441

def rl_bind_key(key, function)
  @_rl_keymap[rl_translate_keyseq(key)] = function
  @rl_binding_keymap = @_rl_keymap
  0
end

.rl_bind_keyseq_if_unbound(keyseq, default_func) ⇒ Object



1948
1949
1950
# File 'lib/rbreadline.rb', line 1948

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.


1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
# File 'lib/rbreadline.rb', line 1936

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.


1928
1929
1930
# File 'lib/rbreadline.rb', line 1928

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.



7939
7940
7941
# File 'lib/rbreadline.rb', line 7939

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.


7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
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
8007
8008
8009
8010
8011
8012
8013
# File 'lib/rbreadline.rb', line 7964

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.
  rl_modifying(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



7651
7652
7653
# File 'lib/rbreadline.rb', line 7651

def rl_char_search(count, key)
  _rl_char_search(count, FFIND, BFIND)
end

.rl_character_len(c, pos) ⇒ Object



5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
# File 'lib/rbreadline.rb', line 5793

def rl_character_len(c, pos)
  if (meta_char(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_signalObject

Clean up the terminal and readline state after catching a signal, before

resending it to the calling application.


1509
1510
1511
1512
1513
1514
1515
1516
# File 'lib/rbreadline.rb', line 1509

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_messageObject

How to clear things from the “echo-area”.



4301
4302
4303
4304
4305
4306
4307
4308
4309
# File 'lib/rbreadline.rb', line 4301

def rl_clear_message()
  @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_inputObject

Clear any pending input pushed with rl_execute_next()



1648
1649
1650
1651
1652
# File 'lib/rbreadline.rb', line 1648

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.


5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
# File 'lib/rbreadline.rb', line 5365

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_signalsObject



1658
1659
1660
1661
1662
# File 'lib/rbreadline.rb', line 1658

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.


6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
# File 'lib/rbreadline.rb', line 6893

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.


6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
# File 'lib/rbreadline.rb', line 6790

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_charactersObject

Returns the value of attribute rl_completer_quote_characters.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_completer_quote_characters
  @rl_completer_quote_characters
end

.rl_completer_quote_characters=(value) ⇒ Object

Sets the attribute rl_completer_quote_characters

Parameters:

  • value

    the value to set the attribute rl_completer_quote_characters to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_completer_quote_characters=(value)
  @rl_completer_quote_characters = value
end

.rl_completer_word_break_charactersObject

Returns the value of attribute rl_completer_word_break_characters.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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

Parameters:

  • value

    the value to set the attribute rl_completer_word_break_characters to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_completer_word_break_characters=(value)
  @rl_completer_word_break_characters = value
end

.rl_completion_append_characterObject

Returns the value of attribute rl_completion_append_character.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_completion_append_character
  @rl_completion_append_character
end

.rl_completion_append_character=(value) ⇒ Object

Sets the attribute rl_completion_append_character

Parameters:

  • value

    the value to set the attribute rl_completion_append_character to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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.


1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
# File 'lib/rbreadline.rb', line 1293

def rl_completion_matches(text, entry_function)
  matches = 0
  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



4983
4984
4985
# File 'lib/rbreadline.rb', line 4983

def rl_copy_text(from, to)
  return @rl_line_buffer[from...to]
end

.rl_crlfObject

Move to the start of the next line.



4691
4692
4693
4694
4695
4696
4697
# File 'lib/rbreadline.rb', line 4691

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.


5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
# File 'lib/rbreadline.rb', line 5903

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.



6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
# File 'lib/rbreadline.rb', line 6075

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.


6103
6104
6105
6106
6107
6108
6109
# File 'lib/rbreadline.rb', line 6103

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.


4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
# File 'lib/rbreadline.rb', line 4951

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,1] = 0.chr
  return (diff)
end

.rl_deprep_term_functionObject

Returns the value of attribute rl_deprep_term_function.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_deprep_term_function
  @rl_deprep_term_function
end

.rl_deprep_term_function=(value) ⇒ Object

Sets the attribute rl_deprep_term_function

Parameters:

  • value

    the value to set the attribute rl_deprep_term_function to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_deprep_term_function=(value)
  @rl_deprep_term_function = value
end

.rl_deprep_terminalObject

Restore the terminal’s normal settings and modes.



7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
# File 'lib/rbreadline.rb', line 7099

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
  retry_if_interrupted do
    `stty #{@otio}`
  end

  @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



7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
# File 'lib/rbreadline.rb', line 7896

def rl_digit_argument(ignore, key)
  _rl_arg_init()
  if (rl_isstate(RL_STATE_CALLBACK))
    _rl_arg_dispatch(@_rl_argcxt, key)
    rl_message("(arg: #{@rl_arg_sign * @rl_numeric_arg}) ")
    return 0
  else
    rl_execute_next(key)
    return (rl_digit_loop())
  end
end

.rl_digit_loopObject

Handle C-u style numeric args, as well as M–, and M-digits.



7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
# File 'lib/rbreadline.rb', line 7880

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_dingObject

Ring the terminal bell.



4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
# File 'lib/rbreadline.rb', line 4024

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.


8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
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
8456
# File 'lib/rbreadline.rb', line 8383

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.


7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
# File 'lib/rbreadline.rb', line 7380

def rl_display_search(search_string, reverse_p, where)
  message = '('
  if (reverse_p)
    message << "reverse-"
  end
  message << "i-search)`"

  if (search_string)
    message << search_string
  end
  message << "': "

  rl_message(message)
  message = 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.


5789
5790
5791
# File 'lib/rbreadline.rb', line 5789

def rl_do_lowercase_version(ignore1, ignore2)
  0
end

.rl_do_undoObject



7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
# File 'lib/rbreadline.rb', line 7661

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.



7934
7935
7936
# File 'lib/rbreadline.rb', line 7934

def rl_downcase_word(count, key)
  rl_change_case(count, DownCase)
end

.rl_emacs_editing_mode(count, key) ⇒ Object



1441
1442
1443
1444
1445
1446
# File 'lib/rbreadline.rb', line 1441

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).



7921
7922
7923
7924
7925
7926
# File 'lib/rbreadline.rb', line 7921

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.



5198
5199
5200
5201
# File 'lib/rbreadline.rb', line 5198

def rl_end_of_line(count, key)
  @rl_point = @rl_end
  0
end

.rl_end_undo_groupObject

End an undo group started with rl_begin_undo_group ().



5016
5017
5018
5019
5020
# File 'lib/rbreadline.rb', line 5016

def rl_end_undo_group()
  rl_add_undo(UNDO_END, 0, 0, nil)
  @_rl_undo_group_level-=1
  0
end

.rl_event_hookObject

Returns the value of attribute rl_event_hook.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_event_hook
  @rl_event_hook
end

.rl_event_hook=(value) ⇒ Object

Sets the attribute rl_event_hook

Parameters:

  • value

    the value to set the attribute rl_event_hook to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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.



8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
# File 'lib/rbreadline.rb', line 8366

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.



7909
7910
7911
7912
7913
# File 'lib/rbreadline.rb', line 7909

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.

*



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
# File 'lib/rbreadline.rb', line 1771

def rl_expand_prompt(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 = expand_prompt(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_invis_chars_first_line,@prompt_physical_chars = expand_prompt(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,_,_, = expand_prompt(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.


4887
4888
4889
4890
4891
4892
# File 'lib/rbreadline.rb', line 4887

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.



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
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'lib/rbreadline.rb', line 1119

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)
    if text.length == 0
      @dirname = "."
      @filename = ""
    elsif text.rindex(File::SEPARATOR) == text.length-1
      @dirname = text
      @filename = ""
    else
      @dirname, @filename = File.split(text)

      # This preserves the "./" when the user types "./dirname<tab>".
      if @dirname == "." && text[0,2] == ".#{File::SEPARATOR}"
        @dirname += File::SEPARATOR
      end
    end

    # 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,1] == '~')
      @dirname = File.expand_path(@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
      @dirname = @users_dirname.dup
    end

    begin
      @directory = Dir.new(@dirname)
    rescue Errno::ENOENT, Errno::ENOTDIR, Errno::EACCES
    end

    # 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)
      next if (!@_rl_match_hidden_files && d_name[0,1] == '.')
      break if (d_name != '.' && d_name != '..')
    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,1] == "~")
        temp = @dirname
        if(temp[-1,1] != File::SEPARATOR)
          temp += File::SEPARATOR
        end
      else
        temp = @users_dirname
        if(temp[-1,1] != File::SEPARATOR)
          temp += File::SEPARATOR
        end
      end
      temp += entry
    else
      temp = entry.dup
    end
    return (temp)
  end
end

.rl_filename_quote_charactersObject

Returns the value of attribute rl_filename_quote_characters.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_filename_quote_characters
  @rl_filename_quote_characters
end

.rl_filename_quote_characters=(value) ⇒ Object

Sets the attribute rl_filename_quote_characters

Parameters:

  • value

    the value to set the attribute rl_filename_quote_characters to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_filename_quote_characters=(value)
  @rl_filename_quote_characters = value
end

.rl_forced_update_displayObject

Actually update the display, period.



5336
5337
5338
5339
5340
5341
5342
5343
5344
# File 'lib/rbreadline.rb', line 5336

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.



5137
5138
5139
# File 'lib/rbreadline.rb', line 5137

def rl_forward(count, key)
  rl_forward_char(count, key)
end

.rl_forward_byte(count, key) ⇒ Object

Move forward COUNT bytes.



5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
# File 'lib/rbreadline.rb', line 5091

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.



5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
# File 'lib/rbreadline.rb', line 5113

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.


7194
7195
7196
# File 'lib/rbreadline.rb', line 7194

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.



5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
# File 'lib/rbreadline.rb', line 5224

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_listObject



5022
5023
5024
5025
# File 'lib/rbreadline.rb', line 5022

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).


1910
1911
1912
1913
# File 'lib/rbreadline.rb', line 1910

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.


1920
1921
1922
1923
# File 'lib/rbreadline.rb', line 1920

def rl_generic_bind(type, keyseq, data, map)
  map[keyseq] = data
  0
end

.rl_get_charObject

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.


4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
# File 'lib/rbreadline.rb', line 4604

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_modeObject



2492
2493
2494
2495
2496
2497
2498
2499
2500
# File 'lib/rbreadline.rb', line 2492

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.



5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
# File 'lib/rbreadline.rb', line 5510

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.


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
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
# File 'lib/rbreadline.rb', line 5451

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_initializeObject

Initialize readline (and terminal if not already).



3844
3845
3846
3847
3848
3849
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
# File 'lib/rbreadline.rb', line 3844

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



5651
5652
5653
5654
# File 'lib/rbreadline.rb', line 5651

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.


6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
# File 'lib/rbreadline.rb', line 6113

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



7785
7786
7787
# File 'lib/rbreadline.rb', line 7785

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.


4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
# File 'lib/rbreadline.rb', line 4897

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_instreamObject

Returns the value of attribute rl_instream.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_instream
  @rl_instream
end

.rl_instream=(value) ⇒ Object

Sets the attribute rl_instream

Parameters:

  • value

    the value to set the attribute rl_instream to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_instream=(value)
  @rl_instream = value
end

.rl_isstate(x) ⇒ Object



1643
1644
1645
# File 'lib/rbreadline.rb', line 1643

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.



7177
7178
7179
7180
7181
7182
7183
7184
# File 'lib/rbreadline.rb', line 7177

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.


7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
# File 'lib/rbreadline.rb', line 7137

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.


5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
# File 'lib/rbreadline.rb', line 5983

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.



7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
# File 'lib/rbreadline.rb', line 7730

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_versionObject

Returns the value of attribute rl_library_version.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_library_version
  @rl_library_version
end

.rl_library_version=(value) ⇒ Object

Sets the attribute rl_library_version

Parameters:

  • value

    the value to set the attribute rl_library_version to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_library_version=(value)
  @rl_library_version = value
end

.rl_line_bufferObject



3813
3814
3815
# File 'lib/rbreadline.rb', line 3813

def rl_line_buffer
  @rl_line_buffer.tr(0.chr, '')
end

.rl_maybe_replace_lineObject

Perhaps put back the current line if it has changed.



5426
5427
5428
5429
5430
5431
5432
5433
# File 'lib/rbreadline.rb', line 5426

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_lineObject

Save the current line in _rl_saved_line_for_history.



5393
5394
5395
5396
5397
5398
5399
5400
5401
# File 'lib/rbreadline.rb', line 5393

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.timestamp = nil
    @_rl_saved_line_for_history.data = @rl_undo_list
  end
  0
end

.rl_maybe_unsave_lineObject

Restore the _rl_saved_line_for_history if there is one.



5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
# File 'lib/rbreadline.rb', line 5378

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



7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
# File 'lib/rbreadline.rb', line 7361

def rl_message(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 =
    expand_prompt(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.



7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
# File 'lib/rbreadline.rb', line 7944

def rl_modifying(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



2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
# File 'lib/rbreadline.rb', line 2344

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 "next-history"
    return :rl_get_next_history
  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 "previous-history"
    return :rl_get_previous_history
  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]+$/
      method = ('rl_' + name.gsub('-', '_')).to_sym
      return method if respond_to?(method)
    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.


5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
# File 'lib/rbreadline.rb', line 5760

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 `?'.


8051
8052
8053
# File 'lib/rbreadline.rb', line 8051

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 `/'.


8057
8058
8059
# File 'lib/rbreadline.rb', line 8057

def rl_noninc_reverse_search(count, key)
  noninc_search(-1, (key == '/') ? '/' : nil)
end

.rl_on_new_lineObject

Tell the update routines that we have moved onto a new (empty) line.



3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
# File 'lib/rbreadline.rb', line 3818

def rl_on_new_line()
  if (@visible_line)
    @visible_line[0,1] = 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_promptObject

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.


3927
3928
3929
3930
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
# File 'lib/rbreadline.rb', line 3927

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_outstreamObject

Returns the value of attribute rl_outstream.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_outstream
  @rl_outstream
end

.rl_outstream=(value) ⇒ Object

Sets the attribute rl_outstream

Parameters:

  • value

    the value to set the attribute rl_outstream to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

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.


1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'lib/rbreadline.rb', line 1455

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.


2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
# File 'lib/rbreadline.rb', line 2451

def rl_parse_and_bind(string)

  # If this is a parser directive, act on it.
  if (string[0,1] == "$")
    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

  if string =~ /"(.*)"\s*:\s*(.*)$/
    key, funname = $1, $2
    func = rl_named_function(funname)
    rl_bind_key(key, func) if func
  end

  0
end

.rl_pointObject

Returns the value of attribute rl_point.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_point
  @rl_point
end

.rl_possible_completions(ignore, invoking_key) ⇒ Object

List the possible completions. See description of rl_complete ().



6096
6097
6098
# File 'lib/rbreadline.rb', line 6096

def rl_possible_completions(ignore, invoking_key)
  rl_complete_internal('?')
end

.rl_prep_terminal(meta_flag) ⇒ Object



7051
7052
7053
7054
7055
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
7091
7092
7093
7094
7095
7096
# File 'lib/rbreadline.rb', line 7051

def rl_prep_terminal(meta_flag)
  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(meta_flag)

  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



5670
5671
5672
# File 'lib/rbreadline.rb', line 5670

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.



8359
8360
8361
8362
8363
# File 'lib/rbreadline.rb', line 8359

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.


2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
# File 'lib/rbreadline.rb', line 2092

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_keyObject

Read a key, including pending input.



4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
# File 'lib/rbreadline.rb', line 4558

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?
        c = send(@rl_getc_function,@rl_instream)
      end
    end
  end

  return (c)
end

.rl_readline_nameObject

Returns the value of attribute rl_readline_name.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_readline_name
  @rl_readline_name
end

.rl_readline_name=(value) ⇒ Object

Sets the attribute rl_readline_name

Parameters:

  • value

    the value to set the attribute rl_readline_name to.



1106
1107
1108
# File 'lib/rbreadline.rb', line 1106

def rl_readline_name=(value)
  @rl_readline_name = value
end

.rl_redisplayObject

Basic redisplay algorithm.



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
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
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
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
# File 'lib/rbreadline.rb', line 3172

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,1] = '*'
    out += 1
    line[out,1] = 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,1] != @invisible_line[0,1])
    @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,1] = 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,1] != "\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,1] = 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 (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 && meta_char(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,1] = 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,1] = ' '
          out += 1
        end

      else

        while (out < newout)
          line[out,1] = ' '
          out += 1
        end
        lpos += temp
      end

    elsif (c == "\n" && !@_rl_horizontal_scroll_mode && @_rl_term_up)
      line[out,1] = 0.chr # XXX - sentinel
      out += 1
      @inv_lbreaks[newlines+=1] = out
      lpos = 0
    elsif (ctrl_char(c) || c == RUBOUT)
      line[out,1] = '^'
      out += 1
      lpos+=1
      if (lpos >= @_rl_screenwidth)
        @inv_lbreaks[newlines+=1] = out
        @_rl_wrapped_line[newlines] = _rl_wrapped_multicolumn
        lpos = 0
      end
      # NOTE: c[0].ord works identically on both 1.8 and 1.9
      line[out,1] = 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,1] = ' '
            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,1] = 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,1] = 0.chr

  if (@cpos_buffer_position < 0)
    @cpos_buffer_position = out
    lb_linenum = newlines
  end

  inv_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.
      linenum = 0
      while linenum <= 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

        linenum += 1
      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 tx >= 0 && @_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,1] = '<'
    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,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.



5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
# File 'lib/rbreadline.rb', line 5348

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



6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
# File 'lib/rbreadline.rb', line 6915

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.


5041
5042
5043
5044
5045
5046
5047
5048
5049
# File 'lib/rbreadline.rb', line 5041

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_stateObject



3831
3832
3833
3834
3835
3836
3837
# File 'lib/rbreadline.rb', line 3831

def rl_reset_line_state()
  rl_on_new_line()

  @rl_display_prompt = @rl_prompt ? @rl_prompt : ""
  @forced_display = true
  0
end

.rl_resize_terminalObject



8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
# File 'lib/rbreadline.rb', line 8882

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



1654
1655
1656
# File 'lib/rbreadline.rb', line 1654

def rl_restart_output(count, key)
  0
end

.rl_restore_promptObject



7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
# File 'lib/rbreadline.rb', line 7341

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.


7188
7189
7190
# File 'lib/rbreadline.rb', line 7188

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.



7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
# File 'lib/rbreadline.rb', line 7767

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.



5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
# File 'lib/rbreadline.rb', line 5845

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.


6066
6067
6068
6069
6070
6071
6072
# File 'lib/rbreadline.rb', line 6066

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_promptObject



7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
# File 'lib/rbreadline.rb', line 7325

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.


7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
# File 'lib/rbreadline.rb', line 7202

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)
    _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_modeObject



2484
2485
2486
2487
2488
2489
2490
# File 'lib/rbreadline.rb', line 2484

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.



7131
7132
7133
# File 'lib/rbreadline.rb', line 7131

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 ().


1806
1807
1808
1809
1810
1811
# File 'lib/rbreadline.rb', line 1806

def rl_set_prompt(prompt)
  @rl_prompt = prompt ? prompt.dup : nil
  @rl_display_prompt = @rl_prompt ? @rl_prompt : ""
  @rl_visible_prompt_length = rl_expand_prompt(@rl_prompt)
  0
end

.rl_set_signalsObject



1664
1665
1666
1667
1668
# File 'lib/rbreadline.rb', line 1664

def rl_set_signals()
  if Signal.list['WINCH']
    @def_proc = trap "WINCH",Proc.new{rl_sigwinch_handler(0)}
  end
end

.rl_setstate(x) ⇒ Object



1635
1636
1637
# File 'lib/rbreadline.rb', line 1635

def rl_setstate(x)
  (@rl_readline_state |= (x))
end

.rl_sigwinch_handler(sig) ⇒ Object



8893
8894
8895
8896
8897
# File 'lib/rbreadline.rb', line 8893

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.


4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
# File 'lib/rbreadline.rb', line 4400

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.



5675
5676
5677
# File 'lib/rbreadline.rb', line 5675

def rl_tab_insert(count, key)
  _rl_insert_char(count, "\t")
end

.rl_tilde_expand(ignore, key) ⇒ Object

A function for simple tilde expansion.



1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
# File 'lib/rbreadline.rb', line 1468

def rl_tilde_expand(ignore, key)
  _end = @rl_point
  start = _end - 1

  if (@rl_point == @rl_end && @rl_line_buffer[@rl_point,1] == '~' )
    homedir = File.expand_path("~")
    _rl_replace_text(homedir, start, _end)
    return (0)
  elsif (@rl_line_buffer[start,1] != '~')
    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,1] == '~')

    len = _end - start + 1
    temp = @rl_line_buffer[start,len]
    homedir = File.expand_path(temp)
    temp = nil

    _rl_replace_text(homedir, start, _end)
  end
  0
end

.rl_translate_keyseq(seq) ⇒ Object



2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
# File 'lib/rbreadline.rb', line 2395

def rl_translate_keyseq(seq)
  require 'strscan'

  ss = StringScanner.new(seq)
  new_seq = ''

  until ss.eos?
    char = ss.getch
    next new_seq << char unless char == '\\'

    char = ss.getch
    new_seq << case char
               when 'a'
                 "\007"
               when 'b'
                 "\b"
               when 'd'
                 RUBOUT
               when 'e'
                 ESC
               when 'f'
                 "\f"
               when 'n'
                 NEWLINE
               when 'r'
                 RETURN
               when 't'
                 TAB
               when 'v'
                 0x0B
               when '\\'
                 '\\'
               when 'x'
                 ss.scan(/\d\d/).to_i(16).chr
               when '0'..'7'
                 ss.pos -= 1
                 ss.scan(/\d\d\d/).to_i(8).chr
               else
                 char
               end
  end

  new_seq
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.


7399
7400
7401
7402
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
7429
7430
7431
7432
7433
7434
7435
7436
# File 'lib/rbreadline.rb', line 7399

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.


8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
# File 'lib/rbreadline.rb', line 8306

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.


2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
# File 'lib/rbreadline.rb', line 2058

def rl_tty_set_default_bindings(kmap)
  h = {}
  retry_if_interrupted do
    h = Hash[*`stty -a`.scan(/(\w+) = ([^;]+);/).flatten]
  end
  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.


7041
7042
7043
7044
7045
7046
7047
7048
7049
# File 'lib/rbreadline.rb', line 7041

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.



7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
# File 'lib/rbreadline.rb', line 7714

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.


6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
# File 'lib/rbreadline.rb', line 6030

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.



7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
# File 'lib/rbreadline.rb', line 7444

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.


6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
# File 'lib/rbreadline.rb', line 6000

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



1639
1640
1641
# File 'lib/rbreadline.rb', line 1639

def rl_unsetstate(x)
  (@rl_readline_state &= ~(x))
end

.rl_upcase_word(count, key) ⇒ Object

Uppercase the word at point.



7929
7930
7931
# File 'lib/rbreadline.rb', line 7929

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 `~').


1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'lib/rbreadline.rb', line 1243

def rl_username_completion_function(text, state)
  return nil if RUBY_PLATFORM =~ /mswin|mingw/

    if (state == 0)
      first_char = text[0,1]
      first_char_loc = (first_char == '~' ? 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



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
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
# File 'lib/rbreadline.rb', line 2259

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"
      # This is a NOOP until the rest of Vi-mode is working.
    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"
      # This is a NOOP until the rest of Vi-mode is working.
    when "vi-insert"
      # This is a NOOP until the rest of Vi-mode is working.
    end
  end
end

.rl_vi_checkObject



4815
4816
4817
4818
4819
4820
# File 'lib/rbreadline.rb', line 4815

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

This is a NOOP until the rest of Vi-mode is working.



1429
1430
1431
# File 'lib/rbreadline.rb', line 1429

def rl_vi_editing_mode(count, key)
  0
end

.rl_vi_insertion_mode(count, key) ⇒ Object

Switching from one mode to the other really just involves

switching keymaps.


1435
1436
1437
1438
1439
# File 'lib/rbreadline.rb', line 1435

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.



7458
7459
7460
7461
7462
7463
7464
7465
7466
# File 'lib/rbreadline.rb', line 7458

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



7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
# File 'lib/rbreadline.rb', line 7548

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.



7535
7536
7537
# File 'lib/rbreadline.rb', line 7535

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'.


7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
# File 'lib/rbreadline.rb', line 7498

def rl_yank_nth_arg_internal(count, ignore, history_skip)
  pos = where_history()
  if (history_skip>0)
    history_skip.times { 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.


7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
# File 'lib/rbreadline.rb', line 7472

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_charsObject



6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
# File 'lib/rbreadline.rb', line 6964

def save_tty_chars()
  @_rl_last_tty_chars = @_rl_tty_chars
  h = {}
  retry_if_interrupted do
    h = Hash[*`stty -a`.scan(/(\w+) = ([^;]+);/).flatten]
  end
  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
  retry_if_interrupted do
    @otio = `stty -g`
  end
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.


6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
# File 'lib/rbreadline.rb', line 6179

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.


1850
1851
1852
1853
# File 'lib/rbreadline.rb', line 1850

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,


4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
# File 'lib/rbreadline.rb', line 4659

def space_to_eol(count)
  if @hConsoleHandle
    csbi = Fiddle::Pointer.malloc(24)
    @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
    cursor_pos = csbi[4,4].unpack('L').first
    written = Fiddle::Pointer.malloc(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


6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
# File 'lib/rbreadline.rb', line 6567

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.



8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
# File 'lib/rbreadline.rb', line 8523

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



1901
1902
1903
# File 'lib/rbreadline.rb', line 1901

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.


7657
7658
7659
# File 'lib/rbreadline.rb', line 7657

def trans(i)
  ((i) == -1 ? @rl_point : ((i) == -2 ? @rl_end : (i)))
end

.unstifle_historyObject

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.


8538
8539
8540
8541
8542
8543
8544
8545
# File 'lib/rbreadline.rb', line 8538

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


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
3055
3056
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
# File 'lib/rbreadline.rb', line 2728

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,1] != 0.chr
        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,1] != 0.chr
          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,1] != 0.chr && new[0,1] != 0.chr)
          old[ostart,1] = new[0,1]
        end
      end

    else
      if (new[0,1] != 0.chr)
        @rl_outstream.write(new[0,1])
      else
        @rl_outstream.write(' ')
      end
      @_rl_last_c_pos = 1
      @_rl_last_v_pos+=1
      if (old[ostart,1] != 0.chr && new[0,1] != 0.chr)
        old[ostart,1] = new[0,1]
      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.
    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,1] != 0.chr &&
              _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,1] != 0.chr && old[ostart+ofd,1] == new[nfd,1])
      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,1] == " ")
        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,1] == new[nls,1])
      if (old[ostart+ols,1] != " ")
        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,1] != 0.chr)         # 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,1] != 0.chr )
      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

  o_cpos = @_rl_last_c_pos

  # 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)

  # We need to indicate that the cursor position is correct in the presence
  # of invisible characters in the prompt string.  Let's see if setting this
  # when we make sure we're at the end of the drawn prompt string works.
  if (current_line == 0 && !@rl_byte_oriented &&
      (@_rl_last_c_pos > 0 || o_cpos > 0) &&
      @_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

    # If col_lendiff is > 0, implying that the new string takes up more
    # screen real estate than the old, but lendiff is < 0, meaning that it
    # takes fewer bytes, we need to just output the characters starting from
    # the first difference.  These will overwrite what is on the display, so
    # there's no reason to do a smart update.  This can really only happen in
    # a multibyte environment.
    if lendiff < 0
      _rl_output_some_chars(new, nfd, temp)
      @_rl_last_c_pos += _rl_col_width(new, nfd, nfd+temp)

      # If nfd begins before any invisible characters in the prompt, adjust
      # _rl_last_c_pos to account for wrap_offset and set cpos_adjusted to
      # let the caller know.
      if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
        @_rl_last_c_pos -= @wrap_offset
        @cpos_adjusted = true
      end
      return
    # 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.
    elsif (@_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,1] != 0.chr && (!@_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,1] == 0.chr && 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
        _rl_output_some_chars(new,nfd, temp)
        @_rl_last_c_pos += col_temp
        # If nfd begins before any invisible characters in the prompt, adjust
        # _rl_last_c_pos to account for wrap_offset and set cpos_adjusted to
        # let the caller know.
        if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
          @_rl_last_c_pos -= @wrap_offset
          @cpos_adjusted = true
        end
        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)
        # If nfd begins at the prompt, or before the invisible characters in
        # the prompt, we need to adjust _rl_last_c_pos in a multibyte locale
        # to account for the wrap offset and set cpos_adjusted accordingly.
        _rl_output_some_chars(new,nfd, temp)
        if !@rl_byte_oriented
          @_rl_last_c_pos += _rl_col_width(new,nfd,nfd+temp)
          if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
            @_rl_last_c_pos -= @wrap_offset
            @cpos_adjusted = true
          end
        else
          @_rl_last_c_pos += temp
        end
      end

      # Otherwise, print over the existing material.
    else
      if (temp > 0)
        # If nfd begins at the prompt, or before the invisible characters in
        # the prompt, we need to adjust _rl_last_c_pos in a multibyte locale
        # to account for the wrap offset and set cpos_adjusted accordingly.
        _rl_output_some_chars(new,nfd, temp)
        @_rl_last_c_pos += col_temp      # XXX
        if !@rl_byte_oriented
          if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
            @_rl_last_c_pos -= @wrap_offset
            @cpos_adjusted = true
          end
        end
      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_historyObject



6173
6174
6175
# File 'lib/rbreadline.rb', line 6173

def using_history()
  @history_offset = @history_length
end

.vis_chars(line) ⇒ Object



2691
2692
2693
# File 'lib/rbreadline.rb', line 2691

def vis_chars(line)
  @visible_line[@vis_lbreaks[line] .. -1]
end

.vis_line(line) ⇒ Object



2699
2700
2701
# File 'lib/rbreadline.rb', line 2699

def vis_line(line)
  ((line) > @_rl_vis_botlin) ? "" : vis_chars(line)
end

.vis_llen(l) ⇒ Object



2683
2684
2685
# File 'lib/rbreadline.rb', line 2683

def vis_llen(l)
  ((l) > @_rl_vis_botlin ? 0 : (@vis_lbreaks[l+1] - @vis_lbreaks[l]))
end

.vis_pos(line) ⇒ Object



2695
2696
2697
# File 'lib/rbreadline.rb', line 2695

def vis_pos(line)
  @vis_lbreaks[line] || 0
end

.w_offset(line, offset) ⇒ Object



2679
2680
2681
# File 'lib/rbreadline.rb', line 2679

def w_offset(line, offset)
  ((line) == 0 ? offset : 0)
end

.where_historyObject

Returns the magic number which says what history element we are

looking at now.  In this implementation, it returns history_offset.


5405
5406
5407
# File 'lib/rbreadline.rb', line 5405

def where_history()
  @history_offset
end

.whitespace(c) ⇒ Object



2675
2676
2677
# File 'lib/rbreadline.rb', line 2675

def whitespace(c)
  (c == ' ' || c == "\t")
end