Class: CLI::UI::Glyph

Inherits:
Object
  • Object
show all
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, 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,  Color::RED)
BUG =

Bug emoji (๐Ÿ›)

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

RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (ยป)

new('>', 0xbb,    Color::YELLOW)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle, codepoint, color) ⇒ Glyph

Creates a new glyph

Attributes

  • handle - The handle in the MAP constant

  • codepoint - The codepoint used to create the glyph (e.g. 0x2717 for a ballot X)

  • color - What color to output the glyph. Check CLI::UI::Color for options.



28
29
30
31
32
33
34
35
36
37
# File 'lib/cli/ui/glyph.rb', line 28

def initialize(handle, codepoint, color)
  @handle    = handle
  @codepoint = codepoint
  @color     = color
  @char      = [codepoint].pack('U')
  @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.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def char
  @char
end

#codepointObject (readonly)

Returns the value of attribute codepoint.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def codepoint
  @codepoint
end

#colorObject (readonly)

Returns the value of attribute color.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def color
  @color
end

#fmtObject (readonly)

Returns the value of attribute fmt.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def fmt
  @fmt
end

#handleObject (readonly)

Returns the value of attribute handle.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def handle
  @handle
end

#to_sObject (readonly)

Returns the value of attribute to_s.



18
19
20
# File 'lib/cli/ui/glyph.rb', line 18

def to_s
  @to_s
end

Class Method Details

.availableObject

All available glyphs by name



73
74
75
# File 'lib/cli/ui/glyph.rb', line 73

def self.available
  MAP.keys
end

.lookup(name) ⇒ Object

Looks up a glyph by name

Raises

Raises a InvalidGlyphHandle if the glyph is not available You likely need to create it with .new or you made a typo

Returns

Returns a terminal output-capable string



65
66
67
68
69
# File 'lib/cli/ui/glyph.rb', line 65

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