Class: Charming::Presentation::UI::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/ui/style.rb

Constant Summary collapse

ATTRIBUTES =
{
  bold: 1,
  faint: 2,
  italic: 3,
  underline: 4,
  reverse: 7,
  strikethrough: 9
}.freeze
COLORS =
{
  black: 30,
  red: 31,
  green: 32,
  yellow: 33,
  blue: 34,
  magenta: 35,
  cyan: 36,
  white: 37,
  bright_black: 90,
  bright_red: 91,
  bright_green: 92,
  bright_yellow: 93,
  bright_blue: 94,
  bright_magenta: 95,
  bright_cyan: 96,
  bright_white: 97
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Style

Returns a new instance of Style.



35
36
37
38
39
40
41
# File 'lib/charming/presentation/ui/style.rb', line 35

def initialize(options = {})
  @options = {
    attributes: [],
    padding: [0, 0, 0, 0],
    align: :left
  }.merge(options)
end

Instance Method Details

#align(value) ⇒ Object



75
76
77
# File 'lib/charming/presentation/ui/style.rb', line 75

def align(value)
  with(align: value)
end

#background(color) ⇒ Object Also known as: bg



48
49
50
# File 'lib/charming/presentation/ui/style.rb', line 48

def background(color)
  with(background: color)
end

#border(style = :normal, sides: nil, foreground: nil) ⇒ Object



63
64
65
# File 'lib/charming/presentation/ui/style.rb', line 63

def border(style = :normal, sides: nil, foreground: nil)
  with(border: style, border_sides: sides, border_foreground: foreground)
end

#foreground(color) ⇒ Object Also known as: fg



43
44
45
# File 'lib/charming/presentation/ui/style.rb', line 43

def foreground(color)
  with(foreground: color)
end

#height(value) ⇒ Object



71
72
73
# File 'lib/charming/presentation/ui/style.rb', line 71

def height(value)
  with(height: value)
end

#padding(*values) ⇒ Object



59
60
61
# File 'lib/charming/presentation/ui/style.rb', line 59

def padding(*values)
  with(padding: expand_box_values(values))
end

#render(value) ⇒ Object



79
80
81
82
83
84
# File 'lib/charming/presentation/ui/style.rb', line 79

def render(value)
  lines = apply_dimensions(value.to_s.lines(chomp: true))
  lines = apply_padding(lines)
  lines = apply_border(lines)
  apply_ansi(lines.join("\n"))
end

#width(value) ⇒ Object



67
68
69
# File 'lib/charming/presentation/ui/style.rb', line 67

def width(value)
  with(width: value)
end