mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Implement Reline::HISTORY as an expanded Array
This commit is contained in:
parent
c48778d642
commit
caef2ddaaf
2 changed files with 38 additions and 1 deletions
|
@ -9,7 +9,6 @@ module Reline
|
|||
extend self
|
||||
FILENAME_COMPLETION_PROC = nil
|
||||
USERNAME_COMPLETION_PROC = nil
|
||||
HISTORY = Array.new
|
||||
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
IS_WINDOWS = true
|
||||
|
@ -33,6 +32,42 @@ module Reline
|
|||
@@line_editor = Reline::LineEditor.new(@@config)
|
||||
@@ambiguous_width = nil
|
||||
|
||||
HISTORY = Class.new(Array) {
|
||||
def to_s
|
||||
'HISTORY'
|
||||
end
|
||||
|
||||
def delete_at(index)
|
||||
index = check_index(index)
|
||||
super(index)
|
||||
end
|
||||
|
||||
def [](index)
|
||||
index = check_index(index)
|
||||
super(index)
|
||||
end
|
||||
|
||||
def []=(index, val)
|
||||
index = check_index(index)
|
||||
super(index, String.new(val, encoding: Encoding::default_external))
|
||||
end
|
||||
|
||||
def push(*val)
|
||||
super(*(val.map{ |v| String.new(v, encoding: Encoding::default_external) }))
|
||||
end
|
||||
|
||||
def <<(val)
|
||||
super(String.new(val, encoding: Encoding::default_external))
|
||||
end
|
||||
|
||||
private def check_index(index)
|
||||
index += size if index < 0
|
||||
raise RangeError.new("index=<#{index}>") if index < -@@config.history_size or @@config.history_size < index
|
||||
raise IndexError.new("index=<#{index}>") if index < 0 or size <= index
|
||||
index
|
||||
end
|
||||
}.new
|
||||
|
||||
@basic_quote_characters = '"\''
|
||||
# TODO implement below
|
||||
#@completer_quote_characters
|
||||
|
|
|
@ -13,6 +13,7 @@ class Reline::Config
|
|||
enable-keypad
|
||||
expand-tilde
|
||||
history-preserve-point
|
||||
history-size
|
||||
horizontal-scroll-mode
|
||||
input-meta
|
||||
mark-directories
|
||||
|
@ -42,6 +43,7 @@ class Reline::Config
|
|||
@key_actors[:emacs] = Reline::KeyActor::Emacs.new
|
||||
@key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
|
||||
@key_actors[:vi_command] = Reline::KeyActor::ViCommand.new
|
||||
@history_size = 500
|
||||
end
|
||||
|
||||
def reset
|
||||
|
|
Loading…
Add table
Reference in a new issue