Class: Cli::Display
- Inherits:
-
Object
- Object
- Cli::Display
- Defined in:
- lib/cli/display.rb
Class Method Summary collapse
- .confirmation(title) ⇒ Object
- .dispaly_diff(original_content, new_content) ⇒ Object
- .error_message(message) ⇒ Object
- .get_input(input) ⇒ Object
- .info_message(message) ⇒ Object
- .message(role, content) ⇒ Object
- .select(title, options) ⇒ Object
- .spinner(title = "running") ⇒ Object
- .success_message(message) ⇒ Object
- .table(rows, headers) ⇒ Object
Class Method Details
.confirmation(title) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cli/display.rb', line 32 def self.confirmation(title) while true do puts(title.colorize(mode: :bold)) print("y/N: ".colorize(mode: :bold)) response = STDIN.gets.chomp.downcase if response.empty? puts("Response required".colorize(:red)) elsif response == "y" return true elsif response == "n" return false else puts("Invalid response. Must be one letter, case insenstive".colorize(:red)) end end end |
.dispaly_diff(original_content, new_content) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cli/display.rb', line 71 def self.dispaly_diff(original_content, new_content) Diffy::Diff.new(original_content, new_content, source: 'strings').each do |line| if line.start_with?("+") puts line.colorize(:green) elsif line.start_with?("-") puts line.colorize(:red) else puts line end end end |
.error_message(message) ⇒ Object
59 60 61 |
# File 'lib/cli/display.rb', line 59 def self.() puts(.colorize(:red)) end |
.get_input(input) ⇒ Object
50 51 52 53 |
# File 'lib/cli/display.rb', line 50 def self.get_input(input) print(input.colorize(mode: :bold)) STDIN.gets&.chomp || '' end |
.info_message(message) ⇒ Object
63 64 65 |
# File 'lib/cli/display.rb', line 63 def self.() puts(.colorize(color: :light_black)) end |
.message(role, content) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/cli/display.rb', line 9 def self.(role, content) if role == "user" puts("you".colorize(background: :green) + ": " + content) else puts("assistant".colorize(background: :yellow) + ": " + content) end end |
.select(title, options) ⇒ Object
27 28 29 30 |
# File 'lib/cli/display.rb', line 27 def self.select(title, ) prompt = TTY::Prompt.new prompt.select(title.colorize(mode: :bold), , per_page: 100, columnize: 2) end |
.spinner(title = "running") ⇒ Object
67 68 69 |
# File 'lib/cli/display.rb', line 67 def self.spinner(title="running") TTY::Spinner.new("[:spinner] #{title}", format: :spin_2) end |
.success_message(message) ⇒ Object
55 56 57 |
# File 'lib/cli/display.rb', line 55 def self.() puts(.colorize(:green)) end |
.table(rows, headers) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/cli/display.rb', line 17 def self.table(rows, headers) rows = rows.map(&:values) table = Terminal::Table.new( headings: headers, rows: rows ) puts table end |