Module: AskTTY::Internal::ANSIStyle

Defined in:
lib/asktty/internal/ansi_style.rb

Class Method Summary collapse

Class Method Details

.blurred_button(text) ⇒ Object



42
43
44
# File 'lib/asktty/internal/ansi_style.rb', line 42

def blurred_button(text)
  style("  #{text}  ", foreground: 7, background: 0)
end

.cursor(text = " ") ⇒ Object



46
47
48
# File 'lib/asktty/internal/ansi_style.rb', line 46

def cursor(text = " ")
  style(text, foreground: 7, background: 2)
end

.error(text) ⇒ Object



50
51
52
# File 'lib/asktty/internal/ansi_style.rb', line 50

def error(text)
  style(text, foreground: 9)
end

.focused_button(text) ⇒ Object



38
39
40
# File 'lib/asktty/internal/ansi_style.rb', line 38

def focused_button(text)
  style("  #{text}  ", foreground: 0, background: 2)
end

.muted(text) ⇒ Object



22
23
24
# File 'lib/asktty/internal/ansi_style.rb', line 22

def muted(text)
  style(text, foreground: 8)
end

.prompt(text) ⇒ Object



26
27
28
# File 'lib/asktty/internal/ansi_style.rb', line 26

def prompt(text)
  style(text, foreground: 3)
end

.selected(text) ⇒ Object



34
35
36
# File 'lib/asktty/internal/ansi_style.rb', line 34

def selected(text)
  style(text, foreground: 2)
end

.style(text, foreground: nil, background: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/asktty/internal/ansi_style.rb', line 8

def style(text, foreground: nil, background: nil)
  codes = []
  codes << "38;5;#{foreground}" if foreground
  codes << "48;5;#{background}" if background

  return text.to_s if codes.empty?

  "\e[#{codes.join(';')}m#{text}\e[0m"
end

.text(text) ⇒ Object



30
31
32
# File 'lib/asktty/internal/ansi_style.rb', line 30

def text(text)
  style(text, foreground: 7)
end

.title(text) ⇒ Object



18
19
20
# File 'lib/asktty/internal/ansi_style.rb', line 18

def title(text)
  style(text, foreground: 6)
end