From c462e07a5c9cf80227926de40c00917445f5b53e Mon Sep 17 00:00:00 2001 From: aycabta Date: Mon, 20 Dec 2021 14:34:15 +0900 Subject: [PATCH] [ruby/reline] Add Reline.dialog_proc(name_sym) https://github.com/ruby/reline/commit/7e5dbe4750 --- lib/reline.rb | 7 +++++++ test/reline/test_reline.rb | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/reline.rb b/lib/reline.rb index b872fe6945..b92004c1ab 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -161,6 +161,12 @@ module Reline @dialog_proc_list << [name_sym, p, context] end + def dialog_proc(name_sym) + dialog = @dialog_proc_list.find { |d| d[0] == name_sym } + dialog.nil? ? nil : dialog[1] + #@dialog_proc_list[name_sym] + end + def input=(val) raise TypeError unless val.respond_to?(:getc) or val.nil? if val.respond_to?(:getc) @@ -516,6 +522,7 @@ module Reline def_single_delegators :core, :last_incremental_search def_single_delegators :core, :last_incremental_search= def_single_delegators :core, :add_dialog_proc + def_single_delegators :core, :dialog_proc def_single_delegators :core, :autocompletion, :autocompletion= def_single_delegators :core, :readmultiline diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index 679de42b97..4c909de4fb 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -313,9 +313,13 @@ class Reline::Test < Reline::TestCase def test_add_dialog_proc p = proc {} Reline.add_dialog_proc(:test_proc, p) + assert_equal(p, Reline.dialog_proc(:test_proc)) l = lambda {} Reline.add_dialog_proc(:test_lambda, l) + assert_equal(l, Reline.dialog_proc(:test_lambda)) + + assert_equal(nil, Reline.dialog_proc(:test_nothing)) assert_raise(ArgumentError) { Reline.add_dialog_proc(:error, 42) } assert_raise(ArgumentError) { Reline.add_dialog_proc(:error, 'hoge') } @@ -323,6 +327,7 @@ class Reline::Test < Reline::TestCase dummy = DummyCallbackObject.new Reline.add_dialog_proc(:dummy, dummy) + assert_equal(dummy, Reline.dialog_proc(:dummy)) end def test_readmultiline