Class: DialogTui::Dialog
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from UserAction
read_char, show_single_key, user_action
Constructor Details
#initialize(&block) ⇒ Dialog
Returns a new instance of Dialog.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/dialog_tui.rb', line 39
def initialize &block
@options = []
if block.arity == 0
instance_eval &block
else
block.call self
end
raise unless @options.count > 0
@current = @options.first
@neighbors = Neighbors.new @options
end
|
Class Method Details
.run(&block) ⇒ Object
34
35
36
|
# File 'lib/dialog_tui.rb', line 34
def self.run &block
new(&block).run
end
|
Instance Method Details
#chosen?(option) ⇒ Boolean
84
85
86
|
# File 'lib/dialog_tui.rb', line 84
def chosen? option
@current == option end
|
#run ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/dialog_tui.rb', line 55
def run
begin
print_options
done = false
user_action { |key|
key.up do
@current = prev
end
key.down do
@current = nexxt
end
key.enter do
done = true
end
}
end until done
@current.call
end
|