Class: Brut::CLI::TerminalTheme
- Inherits:
-
Object
- Object
- Brut::CLI::TerminalTheme
- Defined in:
- lib/brut/cli/terminal_theme.rb
Instance Method Summary collapse
-
#bullet(n) ⇒ Object
-
#code ⇒ Object
-
#error ⇒ Object
-
#exception ⇒ Object
-
#header ⇒ Object
-
#initialize(terminal:) ⇒ TerminalTheme
constructor
A new instance of TerminalTheme.
-
#none ⇒ Object
-
#subheader ⇒ Object
-
#success ⇒ Object
-
#title ⇒ Object
-
#url ⇒ Object
-
#warning ⇒ Object
-
#weak ⇒ Object
-
#wrap(text, first_indent: true, indent:, max_width: nil, newline: "\n") ⇒ Object
Constructor Details
#initialize(terminal:) ⇒ TerminalTheme
Returns a new instance of TerminalTheme.
3 4 5 |
# File 'lib/brut/cli/terminal_theme.rb', line 3 def initialize(terminal:) @terminal = terminal end |
Instance Method Details
#bullet(n) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/brut/cli/terminal_theme.rb', line 25 def bullet(n) @bullets ||= [ Lipgloss::Style.new.foreground(yellow_strong).margin_right(1).margin_left(2), Lipgloss::Style.new.foreground(purple_strong).margin_right(1), Lipgloss::Style.new.foreground(yellow_weak).margin_right(1), Lipgloss::Style.new.foreground(purple_weak).margin_right(1), ] @bullets[n] || none end |
#code ⇒ Object
22 23 24 |
# File 'lib/brut/cli/terminal_theme.rb', line 22 def code @code ||= Lipgloss::Style.new.foreground(cyan_strong).bold(true) end |
#error ⇒ Object
47 48 49 |
# File 'lib/brut/cli/terminal_theme.rb', line 47 def error @error ||= Lipgloss::Style.new.foreground(red_strong).bold(true) end |
#exception ⇒ Object
43 44 45 |
# File 'lib/brut/cli/terminal_theme.rb', line 43 def exception @exception ||= Lipgloss::Style.new.foreground(red_weak) end |
#header ⇒ Object
10 11 12 |
# File 'lib/brut/cli/terminal_theme.rb', line 10 def header @header ||= Lipgloss::Style.new.foreground(blue_strong).bold(true) end |
#none ⇒ Object
35 36 37 |
# File 'lib/brut/cli/terminal_theme.rb', line 35 def none @none ||= Lipgloss::Style.new end |
#subheader ⇒ Object
13 14 15 |
# File 'lib/brut/cli/terminal_theme.rb', line 13 def subheader @subheader ||= Lipgloss::Style.new.foreground(cyan_strong).italic(true) end |
#success ⇒ Object
39 40 41 |
# File 'lib/brut/cli/terminal_theme.rb', line 39 def success @success ||= Lipgloss::Style.new.foreground(green_weak).bold(true) end |
#title ⇒ Object
7 8 9 |
# File 'lib/brut/cli/terminal_theme.rb', line 7 def title @title ||= Lipgloss::Style.new.bold(true).foreground(white_strong) end |
#url ⇒ Object
19 20 21 |
# File 'lib/brut/cli/terminal_theme.rb', line 19 def url @url ||= Lipgloss::Style.new.underline(true).bold(true) end |
#warning ⇒ Object
51 52 53 |
# File 'lib/brut/cli/terminal_theme.rb', line 51 def warning @warning ||= Lipgloss::Style.new.foreground(yellow_strong).bold(true) end |
#weak ⇒ Object
16 17 18 |
# File 'lib/brut/cli/terminal_theme.rb', line 16 def weak @weak ||= Lipgloss::Style.new.faint(true) end |
#wrap(text, first_indent: true, indent:, max_width: nil, newline: "\n") ⇒ 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 |
# File 'lib/brut/cli/terminal_theme.rb', line 55 def wrap(text, first_indent: true, indent:, max_width: nil, newline: "\n") max_width ||= @terminal.cols text_width = [ max_width, @terminal.cols ].min - newline.length lines = [] text.split(/\s+/).each do |word| current_line = lines.last if current_line.nil? lines << [] current_line = lines.last end if (current_line.join(" ").length + word.length + 1) > (text_width - indent) lines << [ word ] else current_line << word end end prefix = " " * indent lines.map.with_index { |line,index| if index == 0 && !first_indent line.join(" ") else prefix + line.join(" ") end }.join(newline) end |