lib/reline/config.rb in reline-0.1.4 vs lib/reline/config.rb in reline-0.1.5

- old
+ new

@@ -1,7 +1,5 @@ -require 'pathname' - class Reline::Config attr_reader :test_mode KEYSEQ_PATTERN = /\\(?:C|Control)-[A-Za-z_]|\\(?:M|Meta)-[0-9A-Za-z_]|\\(?:C|Control)-(?:M|Meta)-[A-Za-z_]|\\(?:M|Meta)-(?:C|Control)-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./ @@ -33,10 +31,14 @@ prefer-visible-bell print-completions-horizontally show-all-if-ambiguous show-all-if-unmodified visible-stats + show-mode-in-prompt + vi-cmd-mode-icon + vi-ins-mode-icon + emacs-mode-string } VARIABLE_NAME_SYMBOLS = VARIABLE_NAMES.map { |v| :"#{v.tr(?-, ?_)}" } VARIABLE_NAME_SYMBOLS.each do |v| attr_accessor v end @@ -50,10 +52,14 @@ @keymap_label = :emacs @key_actors = {} @key_actors[:emacs] = Reline::KeyActor::Emacs.new @key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new @key_actors[:vi_command] = Reline::KeyActor::ViCommand.new + @vi_cmd_mode_icon = '(cmd)' + @vi_ins_mode_icon = '(ins)' + @emacs_mode_string = '@' + # https://tiswww.case.edu/php/chet/readline/readline.html#IDX25 @history_size = -1 # unlimited @keyseq_timeout = 500 @test_mode = false end @@ -157,11 +163,11 @@ next if @skip_section case line when /^set +([^ ]+) +([^ ]+)/i - var, value = $1.downcase, $2.downcase + var, value = $1.downcase, $2 bind_variable(var, value) next when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o key, func_name = $1, $2 keystroke, func = bind_key(key, func_name) @@ -207,11 +213,15 @@ end def bind_variable(name, value) case name when 'history-size' - @history_size = value.to_i + begin + @history_size = Integer(value) + rescue ArgumentError + @history_size = 500 + end when 'bell-style' @bell_style = case value when 'none', 'off' :none @@ -246,12 +256,35 @@ when 'vi-insert' @keymap_label = :vi_insert end when 'keyseq-timeout' @keyseq_timeout = value.to_i + when 'show-mode-in-prompt' + case value + when 'off' + @show_mode_in_prompt = false + when 'on' + @show_mode_in_prompt = true + else + @show_mode_in_prompt = false + end + when 'vi-cmd-mode-string' + @vi_cmd_mode_icon = retrieve_string(value) + when 'vi-ins-mode-string' + @vi_ins_mode_icon = retrieve_string(value) + when 'emacs-mode-string' + @emacs_mode_string = retrieve_string(value) when *VARIABLE_NAMES then variable_name = :"@#{name.tr(?-, ?_)}" instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on') + end + end + + def retrieve_string(str) + if str =~ /\A"(.*)"\z/ + parse_keyseq($1).map(&:chr).join + else + parse_keyseq(str).map(&:chr).join end end def bind_key(key, func_name) if key =~ /\A"(.*)"\z/