summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMari Imaizumi <[email protected]>2024-08-31 12:26:47 +0900
committergit <[email protected]>2024-08-31 03:26:50 +0000
commita2b3cb65ea4d8b9f2d57f027531875bcaab812bf (patch)
treedaff24a9d40b5451e6c2436dffce07e9cb082e5c
parentf1a7966187886e5b62e22126bd7e83fb005973a2 (diff)
[ruby/reline] Implement re-read-init-file
(https://github.com/ruby/reline/pull/740) https://github.com/ruby/reline/commit/59e4ade807
-rw-r--r--lib/reline/config.rb24
-rw-r--r--lib/reline/line_editor.rb4
-rw-r--r--test/reline/test_config.rb15
3 files changed, 36 insertions, 7 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 16ed7eee05..12b2d22237 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -29,6 +29,17 @@ class Reline::Config
attr_accessor :autocompletion
def initialize
+ reset_variables
+ end
+
+ def reset
+ if editing_mode_is?(:vi_command)
+ @editing_mode_label = :vi_insert
+ end
+ @oneshot_key_bindings.clear
+ end
+
+ def reset_variables
@additional_key_bindings = { # from inputrc
emacs: Reline::KeyActor::Base.new,
vi_insert: Reline::KeyActor::Base.new,
@@ -54,13 +65,7 @@ class Reline::Config
@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
- @oneshot_key_bindings.clear
+ @show_mode_in_prompt = false
end
def editing_mode
@@ -360,6 +365,11 @@ class Reline::Config
ret
end
+ def reload
+ reset_variables
+ read
+ end
+
private def seven_bit_encoding?(encoding)
encoding == Encoding::US_ASCII
end
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 9c97415050..5f7f00c979 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2554,4 +2554,8 @@ class Reline::LineEditor
private def set_next_action_state(type, value)
@next_action_state = [type, value]
end
+
+ private def re_read_init_file(_key)
+ @config.reload
+ end
end
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index c14069d117..172c965fde 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -13,6 +13,7 @@ class Reline::Config::Test < Reline::TestCase
Dir.chdir(@tmpdir)
Reline.test_mode
@config = Reline::Config.new
+ @inputrc_backup = ENV['INPUTRC']
end
def teardown
@@ -20,6 +21,7 @@ class Reline::Config::Test < Reline::TestCase
FileUtils.rm_rf(@tmpdir)
Reline.test_reset
@config.reset
+ ENV['INPUTRC'] = @inputrc_backup
end
def additional_key_bindings(keymap_label)
@@ -562,4 +564,17 @@ class Reline::Config::Test < Reline::TestCase
ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
ENV['HOME'] = home_backup
end
+
+ def test_reload
+ inputrc = "#{@tmpdir}/inputrc"
+ ENV['INPUTRC'] = inputrc
+
+ File.write(inputrc, "set emacs-mode-string !")
+ @config.read
+ assert_equal '!', @config.emacs_mode_string
+
+ File.write(inputrc, "set emacs-mode-string ?")
+ @config.reload
+ assert_equal '?', @config.emacs_mode_string
+ end
end