Module: AIGit::UI
- Defined in:
- lib/ai_git/ui.rb
Constant Summary collapse
- CODES =
{ bold: 1, dim: 2, red: 31, green: 32, yellow: 33, blue: 34, cyan: 36, gray: 90 }.freeze
Class Method Summary collapse
- .bold(text) ⇒ Object
- .color? ⇒ Boolean
- .dim(text) ⇒ Object
- .error(text) ⇒ Object
- .heading(text) ⇒ Object
- .info(text) ⇒ Object
- .kv(key, value) ⇒ Object
- .no_color? ⇒ Boolean
- .paint(text, *styles) ⇒ Object
- .success(text) ⇒ Object
- .warning(text) ⇒ Object
Class Method Details
.bold(text) ⇒ Object
47 48 49 |
# File 'lib/ai_git/ui.rb', line 47 def bold(text) paint(text, :bold) end |
.color? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/ai_git/ui.rb', line 26 def color? return false if no_color? $stdout.tty? end |
.dim(text) ⇒ Object
51 52 53 |
# File 'lib/ai_git/ui.rb', line 51 def dim(text) paint(text, :dim) end |
.error(text) ⇒ Object
75 76 77 |
# File 'lib/ai_git/ui.rb', line 75 def error(text) $stderr.puts paint(text, :red) # rubocop:disable Style/StderrPuts end |
.heading(text) ⇒ Object
59 60 61 |
# File 'lib/ai_git/ui.rb', line 59 def heading(text) puts paint(text, :bold, :cyan) end |
.info(text) ⇒ Object
63 64 65 |
# File 'lib/ai_git/ui.rb', line 63 def info(text) puts text end |
.kv(key, value) ⇒ Object
55 56 57 |
# File 'lib/ai_git/ui.rb', line 55 def kv(key, value) puts "#{paint("#{key}:", :bold)} #{value}" end |
.no_color? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/ai_git/ui.rb', line 32 def no_color? AIGit::Config.no_color? rescue StandardError true end |
.paint(text, *styles) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/ai_git/ui.rb', line 38 def paint(text, *styles) return text.to_s unless color? codes = styles.map { |style| CODES[style] }.compact return text.to_s if codes.empty? "\e[#{codes.join(';')}m#{text}\e[0m" end |
.success(text) ⇒ Object
67 68 69 |
# File 'lib/ai_git/ui.rb', line 67 def success(text) puts paint(text, :green) end |
.warning(text) ⇒ Object
71 72 73 |
# File 'lib/ai_git/ui.rb', line 71 def warning(text) warn paint(text, :yellow) end |