Class: DevSystem::InputShell
- Inherits:
-
Shell
show all
- Defined in:
- lib/dev_system/subsystems/command/shells/input_shell.rb
Instance Attribute Summary
#menv
Class Method Summary
collapse
Methods inherited from Shell
all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?
#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token
Methods inherited from Liza::Unit
_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff
Class Method Details
.ask ⇒ Object
3
4
5
6
7
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 3
def self.ask(...)
prompt.ask(...)
rescue Exception => e
rescue_input_interrupt e
end
|
.multi_select(title, choices, selected: :all) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 65
def self.multi_select title, choices, selected: :all
raise ArgumentError, "choices must be a hash", caller unless choices.is_a? Hash
return choices if choices.empty?
default = 1..choices.count if selected == :all
default = [] if selected == :none
default = selected.map { choices.values.index(_1) + 1 } if selected.is_a? Array
options = {
enum: ")",
per_page: 30,
help: "(space to select, enter to finish)",
show_help: :always,
default: default
}
prompt.multi_select title, choices, options
rescue Exception => e
rescue_input_interrupt e
end
|
.pick_color(title = "Pick a color", string: nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 27
def self.pick_color title = "Pick a color", string: nil
options = ColorShell.colors.map { [(stick _2, "#{string} # #{_1}", :b), _1] }.to_h
prompt.select \
title,
options,
filter: true, show_help: :always, per_page: 28
rescue Exception => e
rescue_input_interrupt e
end
|
.pick_domains(domains, default, title) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 57
def self.pick_domains(domains, default, title)
choices = domains.map do
color = _2.color rescue :white
[(stick color, _2.to_s).to_s, _1]
end.to_h
multi_select title, choices, selected: default
end
|
.pick_log_level(title = "Which log level?", default:) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 38
def self.pick_log_level(title = "Which log level?", default: )
choices = {
"lowest" => 1,
"lower" => 2,
"low" => 3,
"normal" => 4,
"high" => 5,
"higher" => 6,
"highest" => 7,
}
answer = pick_one title, choices.keys, default: default
choices[answer]
end
|
.pick_one(title, options = ["Yes", "No"], default: nil) ⇒ Object
21
22
23
24
25
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 21
def self.pick_one title, options = ["Yes", "No"], default: nil
prompt.select title, options, filter: true, show_help: :always, per_page: 20, default: default
rescue Exception => e
rescue_input_interrupt e
end
|
.pick_writeable_domains(title) ⇒ Object
52
53
54
55
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 52
def self.pick_writeable_domains(title)
domains = AppShell.get_writable_domains
pick_domains title, domains: domains
end
|
.prompt ⇒ Object
91
92
93
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 91
def self.prompt
TtyPromptGemShell.prompt
end
|
.select ⇒ Object
9
10
11
12
13
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 9
def self.select(...)
prompt.select(...)
rescue Exception => e
rescue_input_interrupt e
end
|
.yes? ⇒ Boolean
15
16
17
18
19
|
# File 'lib/dev_system/subsystems/command/shells/input_shell.rb', line 15
def self.yes?(...)
prompt.yes?(...)
rescue Exception => e
rescue_input_interrupt e
end
|