mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] Add the ability to handle context between dialogs
https://github.com/ruby/reline/commit/063d9c70d9
This commit is contained in:
parent
8d4370b066
commit
4cd344c958
2 changed files with 12 additions and 7 deletions
|
@ -132,10 +132,10 @@ module Reline
|
|||
@dig_perfect_match_proc = p
|
||||
end
|
||||
|
||||
def add_dialog_proc(name_sym, p)
|
||||
def add_dialog_proc(name_sym, p, context = nil)
|
||||
raise ArgumentError unless p.respond_to?(:call) or p.nil?
|
||||
raise ArgumentError unless name_sym.instance_of?(Symbol)
|
||||
@dialog_proc_list << [name_sym, p]
|
||||
@dialog_proc_list << [name_sym, p, context]
|
||||
end
|
||||
|
||||
def input=(val)
|
||||
|
@ -273,8 +273,8 @@ module Reline
|
|||
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
|
||||
line_editor.pre_input_hook = pre_input_hook
|
||||
@dialog_proc_list.each do |d|
|
||||
name_sym, dialog_proc = d
|
||||
line_editor.add_dialog_proc(name_sym, dialog_proc)
|
||||
name_sym, dialog_proc, context = d
|
||||
line_editor.add_dialog_proc(name_sym, dialog_proc, context)
|
||||
end
|
||||
|
||||
unless config.test_mode
|
||||
|
|
|
@ -478,12 +478,17 @@ class Reline::LineEditor
|
|||
end
|
||||
|
||||
class DialogProcScope
|
||||
def initialize(line_editor, proc_to_exec)
|
||||
def initialize(line_editor, proc_to_exec, context)
|
||||
@line_editor = line_editor
|
||||
@proc_to_exec = proc_to_exec
|
||||
@context = context
|
||||
@cursor_pos = Reline::CursorPos.new
|
||||
end
|
||||
|
||||
def context
|
||||
@context
|
||||
end
|
||||
|
||||
def retrieve_completion_block(set_completion_quote_character = false)
|
||||
@line_editor.retrieve_completion_block(set_completion_quote_character)
|
||||
end
|
||||
|
@ -536,9 +541,9 @@ class Reline::LineEditor
|
|||
end
|
||||
end
|
||||
|
||||
def add_dialog_proc(name, p)
|
||||
def add_dialog_proc(name, p, context = nil)
|
||||
return if @dialogs.any? { |d| d.name == name }
|
||||
@dialogs << Dialog.new(name, DialogProcScope.new(self, p))
|
||||
@dialogs << Dialog.new(name, DialogProcScope.new(self, p, context))
|
||||
end
|
||||
|
||||
DIALOG_HEIGHT = 20
|
||||
|
|
Loading…
Reference in a new issue