Implement Reline::HISTORY as an expanded Array

This commit is contained in:
aycabta 2019-05-13 03:26:10 +09:00
Родитель c48778d642
Коммит caef2ddaaf
2 изменённых файлов: 38 добавлений и 1 удалений

Просмотреть файл

@ -9,7 +9,6 @@ module Reline
extend self extend self
FILENAME_COMPLETION_PROC = nil FILENAME_COMPLETION_PROC = nil
USERNAME_COMPLETION_PROC = nil USERNAME_COMPLETION_PROC = nil
HISTORY = Array.new
if RUBY_PLATFORM =~ /mswin|mingw/ if RUBY_PLATFORM =~ /mswin|mingw/
IS_WINDOWS = true IS_WINDOWS = true
@ -33,6 +32,42 @@ module Reline
@@line_editor = Reline::LineEditor.new(@@config) @@line_editor = Reline::LineEditor.new(@@config)
@@ambiguous_width = nil @@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 = '"\'' @basic_quote_characters = '"\''
# TODO implement below # TODO implement below
#@completer_quote_characters #@completer_quote_characters

Просмотреть файл

@ -13,6 +13,7 @@ class Reline::Config
enable-keypad enable-keypad
expand-tilde expand-tilde
history-preserve-point history-preserve-point
history-size
horizontal-scroll-mode horizontal-scroll-mode
input-meta input-meta
mark-directories mark-directories
@ -42,6 +43,7 @@ class Reline::Config
@key_actors[:emacs] = Reline::KeyActor::Emacs.new @key_actors[:emacs] = Reline::KeyActor::Emacs.new
@key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new @key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
@key_actors[:vi_command] = Reline::KeyActor::ViCommand.new @key_actors[:vi_command] = Reline::KeyActor::ViCommand.new
@history_size = 500
end end
def reset def reset