summaryrefslogtreecommitdiff
path: root/lib/reline/config.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/reline/config.rb')
-rw-r--r--lib/reline/config.rb109
1 files changed, 49 insertions, 60 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 4b2655d8eb..d44c2675ab 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -8,31 +8,12 @@ class Reline::Config
end
VARIABLE_NAMES = %w{
- bind-tty-special-chars
- blink-matching-paren
- byte-oriented
completion-ignore-case
convert-meta
disable-completion
- enable-keypad
- expand-tilde
- history-preserve-point
history-size
- horizontal-scroll-mode
- input-meta
keyseq-timeout
- mark-directories
- mark-modified-lines
- mark-symlinked-directories
- match-hidden-files
- meta-flag
- output-meta
- page-completions
- prefer-visible-bell
- print-completions-horizontally
show-all-if-ambiguous
- show-all-if-unmodified
- visible-stats
show-mode-in-prompt
vi-cmd-mode-string
vi-ins-mode-string
@@ -45,16 +26,17 @@ class Reline::Config
attr_accessor v
end
+ attr_accessor :autocompletion
+
def initialize
@additional_key_bindings = {} # from inputrc
@additional_key_bindings[:emacs] = {}
@additional_key_bindings[:vi_insert] = {}
@additional_key_bindings[:vi_command] = {}
@oneshot_key_bindings = {}
- @skip_section = nil
- @if_stack = nil
@editing_mode_label = :emacs
@keymap_label = :emacs
+ @keymap_prefix = []
@key_actors = {}
@key_actors[:emacs] = Reline::KeyActor::Emacs.new
@key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
@@ -67,17 +49,16 @@ class Reline::Config
@keyseq_timeout = 500
@test_mode = false
@autocompletion = false
+ @convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
+ @loaded = false
+ @enable_bracketed_paste = true
end
def reset
if editing_mode_is?(:vi_command)
@editing_mode_label = :vi_insert
end
- @additional_key_bindings.keys.each do |key|
- @additional_key_bindings[key].clear
- end
@oneshot_key_bindings.clear
- reset_default_key_bindings
end
def editing_mode
@@ -89,21 +70,17 @@ class Reline::Config
end
def editing_mode_is?(*val)
- (val.respond_to?(:any?) ? val : [val]).any?(@editing_mode_label)
- end
-
- def autocompletion=(val)
- @autocompletion = val
- end
-
- def autocompletion
- @autocompletion
+ val.any?(@editing_mode_label)
end
def keymap
@key_actors[@keymap_label]
end
+ def loaded?
+ @loaded
+ end
+
def inputrc_path
case ENV['INPUTRC']
when nil, ''
@@ -135,6 +112,7 @@ class Reline::Config
end
def read(file = nil)
+ @loaded = true
file ||= default_inputrc_path
begin
if file.respond_to?(:readlines)
@@ -177,12 +155,6 @@ class Reline::Config
@key_actors[@keymap_label].default_key_bindings[keystroke] = target
end
- def reset_default_key_bindings
- @key_actors.values.each do |ka|
- ka.reset_default_key_bindings
- end
- end
-
def read_lines(lines, file = nil)
if not lines.empty? and lines.first.encoding != Reline.encoding_system_needs
begin
@@ -194,9 +166,7 @@ class Reline::Config
end
end
end
- conditions = [@skip_section, @if_stack]
- @skip_section = nil
- @if_stack = []
+ if_stack = []
lines.each_with_index do |line, no|
next if line.match(/\A\s*#/)
@@ -205,11 +175,11 @@ class Reline::Config
line = line.chomp.lstrip
if line.start_with?('$')
- handle_directive(line[1..-1], file, no)
+ handle_directive(line[1..-1], file, no, if_stack)
next
end
- next if @skip_section
+ next if if_stack.any? { |_no, skip| skip }
case line
when /^set +([^ ]+) +([^ ]+)/i
@@ -218,45 +188,49 @@ class Reline::Config
next
when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
key, func_name = $1, $2
+ func_name = func_name.split.first
keystroke, func = bind_key(key, func_name)
next unless keystroke
- @additional_key_bindings[@keymap_label][keystroke] = func
+ @additional_key_bindings[@keymap_label][@keymap_prefix + keystroke] = func
end
end
- unless @if_stack.empty?
- raise InvalidInputrc, "#{file}:#{@if_stack.last[1]}: unclosed if"
+ unless if_stack.empty?
+ raise InvalidInputrc, "#{file}:#{if_stack.last[0]}: unclosed if"
end
- ensure
- @skip_section, @if_stack = conditions
end
- def handle_directive(directive, file, no)
+ def handle_directive(directive, file, no, if_stack)
directive, args = directive.split(' ')
case directive
when 'if'
condition = false
case args
- when 'mode'
+ when /^mode=(vi|emacs)$/i
+ mode = $1.downcase
+ # NOTE: mode=vi means vi-insert mode
+ mode = 'vi_insert' if mode == 'vi'
+ if @editing_mode_label == mode.to_sym
+ condition = true
+ end
when 'term'
when 'version'
else # application name
condition = true if args == 'Ruby'
condition = true if args == 'Reline'
end
- @if_stack << [file, no, @skip_section]
- @skip_section = !condition
+ if_stack << [no, !condition]
when 'else'
- if @if_stack.empty?
+ if if_stack.empty?
raise InvalidInputrc, "#{file}:#{no}: unmatched else"
end
- @skip_section = !@skip_section
+ if_stack.last[1] = !if_stack.last[1]
when 'endif'
- if @if_stack.empty?
+ if if_stack.empty?
raise InvalidInputrc, "#{file}:#{no}: unmatched endif"
end
- @skip_section = @if_stack.pop
+ if_stack.pop
when 'include'
- read(args)
+ read(File.expand_path(args))
end
end
@@ -291,18 +265,29 @@ class Reline::Config
when 'emacs'
@editing_mode_label = :emacs
@keymap_label = :emacs
+ @keymap_prefix = []
when 'vi'
@editing_mode_label = :vi_insert
@keymap_label = :vi_insert
+ @keymap_prefix = []
end
when 'keymap'
case value
- when 'emacs', 'emacs-standard', 'emacs-meta', 'emacs-ctlx'
+ when 'emacs', 'emacs-standard'
@keymap_label = :emacs
+ @keymap_prefix = []
+ when 'emacs-ctlx'
+ @keymap_label = :emacs
+ @keymap_prefix = [?\C-x.ord]
+ when 'emacs-meta'
+ @keymap_label = :emacs
+ @keymap_prefix = [?\e.ord]
when 'vi', 'vi-move', 'vi-command'
@keymap_label = :vi_command
+ @keymap_prefix = []
when 'vi-insert'
@keymap_label = :vi_insert
+ @keymap_prefix = []
end
when 'keyseq-timeout'
@keyseq_timeout = value.to_i
@@ -387,4 +372,8 @@ class Reline::Config
end
ret
end
+
+ private def seven_bit_encoding?(encoding)
+ encoding == Encoding::US_ASCII
+ end
end