Class: BBFlow::Printer
- Inherits:
-
Object
- Object
- BBFlow::Printer
- Defined in:
- lib/bb_flow/printer.rb
Class Method Summary collapse
-
.ask(question) ⇒ String
Answer.
- .auxiliary(message) ⇒ void
- .error(message) ⇒ void
- .note(message) ⇒ void
- .panic(message) ⇒ void
- .select_item(items, title, formatter: :name.to_proc) ⇒ #name
- .select_items(items, title, formatter: :name.to_proc, preselected: []) ⇒ Array<#name>
-
.simple_question(question) ⇒ Boolean
Positive answer.
- .success(message) ⇒ void
Class Method Details
.ask(question) ⇒ String
Returns answer.
7 8 9 10 11 12 |
# File 'lib/bb_flow/printer.rb', line 7 def ask(question) puts note(question) print('> ') gets.strip end |
.auxiliary(message) ⇒ void
This method returns an undefined value.
56 57 58 |
# File 'lib/bb_flow/printer.rb', line 56 def auxiliary() puts(.colorize(:light_black)) end |
.error(message) ⇒ void
This method returns an undefined value.
35 36 37 |
# File 'lib/bb_flow/printer.rb', line 35 def error() puts("[ERROR] #{message}".colorize(:red)) end |
.note(message) ⇒ void
This method returns an undefined value.
49 50 51 |
# File 'lib/bb_flow/printer.rb', line 49 def note() puts(.colorize(:yellow)) end |
.panic(message) ⇒ void
This method returns an undefined value.
27 28 29 30 |
# File 'lib/bb_flow/printer.rb', line 27 def panic() error() abort end |
.select_item(items, title, formatter: :name.to_proc) ⇒ #name
64 65 66 67 68 69 |
# File 'lib/bb_flow/printer.rb', line 64 def select_item(items, title, formatter: :name.to_proc) puts note(title) auxiliary('Move: arrows, j/k, or Ctrl-N/P Finish: return') Ansi::Selector.select(items, formatter: formatter) end |
.select_items(items, title, formatter: :name.to_proc, preselected: []) ⇒ Array<#name>
75 76 77 78 79 80 81 |
# File 'lib/bb_flow/printer.rb', line 75 def select_items(items, title, formatter: :name.to_proc, preselected: []) puts note(title) # TODO: Remove after implementing it in ansi-select. auxiliary('Move: arrows or j/k Toggle: space Finish: return') Ansi::Selector.multi_select(items, formatter: formatter, preselected: preselected) end |
.simple_question(question) ⇒ Boolean
Returns positive answer.
17 18 19 20 21 22 |
# File 'lib/bb_flow/printer.rb', line 17 def simple_question(question) yes = 'Yes, please' no = 'No, thank you' select_item([yes, no], question, formatter: :to_s.to_proc) == yes end |
.success(message) ⇒ void
This method returns an undefined value.
42 43 44 |
# File 'lib/bb_flow/printer.rb', line 42 def success() puts(.colorize(:green)) end |