Class: CLI::UI::Glyph

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/cli/ui/glyph.rb

Defined Under Namespace

Classes: InvalidGlyphHandle

Constant Summary collapse

MAP =

Mapping of glyphs to terminal output

{}
STAR =

YELLOW SMALL STAR (⭑)

new('*', 0x2b51,           '*', Color::YELLOW)
INFO =

BLUE MATHEMATICAL SCRIPT SMALL i (𝒾)

new('i', 0x1d4be,          'i', Color::BLUE)
QUESTION =

BLUE QUESTION MARK (?)

new('?', 0x003f,           '?', Color::BLUE)
CHECK =

GREEN CHECK MARK (✓)

new('v', 0x2713,           '', Color::GREEN)
X =

RED BALLOT X (✗)

new('x', 0x2717,           'X', Color::RED)
BUG =

Bug emoji (🐛)

new('b', 0x1f41b,          '!', Color::WHITE)
CHEVRON =

RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (»)

new('>', 0xbb,             '»', Color::YELLOW)
HOURGLASS =

HOURGLASS (⧖)

new('H', 0x29d6,           'H', Color::ORANGE)
WARNING =

WARNING SIGN + VARIATION SELECTOR 16 (⚠️ )

new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from T::Sig

sig

Constructor Details

#initialize(handle, codepoint, plain, color) ⇒ Glyph

Returns a new instance of Glyph.



47
48
49
50
51
52
53
54
55
56
# File 'lib/cli/ui/glyph.rb', line 47

def initialize(handle, codepoint, plain, color)
  @handle    = handle
  @codepoint = codepoint
  @color     = color
  @char      = CLI::UI::OS.current.use_emoji? ? Array(codepoint).pack('U*') : plain
  @to_s      = color.code + @char + Color::RESET.code
  @fmt       = "{{#{color.name}:#{@char}}}"

  MAP[handle] = self
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



29
30
31
# File 'lib/cli/ui/glyph.rb', line 29

def char
  @char
end

#codepointObject (readonly)

Returns the value of attribute codepoint.



32
33
34
# File 'lib/cli/ui/glyph.rb', line 32

def codepoint
  @codepoint
end

#colorObject (readonly)

Returns the value of attribute color.



35
36
37
# File 'lib/cli/ui/glyph.rb', line 35

def color
  @color
end

#fmtObject (readonly)

Returns the value of attribute fmt.



29
30
31
# File 'lib/cli/ui/glyph.rb', line 29

def fmt
  @fmt
end

#handleObject (readonly)

Returns the value of attribute handle.



29
30
31
# File 'lib/cli/ui/glyph.rb', line 29

def handle
  @handle
end

#to_sObject (readonly)

Returns the value of attribute to_s.



29
30
31
# File 'lib/cli/ui/glyph.rb', line 29

def to_s
  @to_s
end

Class Method Details

.availableObject



92
93
94
# File 'lib/cli/ui/glyph.rb', line 92

def available
  MAP.keys
end

.lookup(name) ⇒ Object



83
84
85
86
87
# File 'lib/cli/ui/glyph.rb', line 83

def lookup(name)
  MAP.fetch(name.to_s)
rescue KeyError
  raise InvalidGlyphHandle, name
end