Class: CLI::UI::Glyph
- Inherits:
-
Object
- Object
- CLI::UI::Glyph
- 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 + VARIATION SELECTOR 15 (โ๏ธ)
new('H', [0x231b, 0xfe0e], 'H', Color::BLUE)
- WARNING =
WARNING SIGN + VARIATION SELECTOR 16 (โ ๏ธ )
new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW)
Instance Attribute Summary collapse
-
#codepoint ⇒ Object
readonly
Returns the value of attribute codepoint.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#fmt ⇒ Object
readonly
Returns the value of attribute fmt.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#to_s ⇒ Object
readonly
Returns the value of attribute to_s.
Class Method Summary collapse
-
.available ⇒ Object
All available glyphs by name.
-
.lookup(name) ⇒ Object
Looks up a glyph by name.
Instance Method Summary collapse
-
#char ⇒ Object
Fetches the actual character(s) to be displayed for a glyph, based on the current OS support.
-
#initialize(handle, codepoint, plain, color) ⇒ Glyph
constructor
Creates a new glyph.
Constructor Details
#initialize(handle, codepoint, plain, color) ⇒ Glyph
Creates a new glyph
Attributes
-
handle
- The handle in theMAP
constant -
codepoint
- The codepoint used to create the glyph (e.g.0x2717
for a ballot X) -
plain
- A fallback plain string to be used in case glyphs are disabled -
color
- What color to output the glyph. CheckCLI::UI::Color
for options.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cli/ui/glyph.rb', line 30 def initialize(handle, codepoint, plain, color) @handle = handle @codepoint = codepoint @color = color @plain = plain @char = Array(codepoint).pack('U*') @to_s = color.code + char + Color::RESET.code @fmt = "{{#{color.name}:#{char}}}" MAP[handle] = self end |
Instance Attribute Details
#codepoint ⇒ Object (readonly)
Returns the value of attribute codepoint.
19 20 21 |
# File 'lib/cli/ui/glyph.rb', line 19 def codepoint @codepoint end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
19 20 21 |
# File 'lib/cli/ui/glyph.rb', line 19 def color @color end |
#fmt ⇒ Object (readonly)
Returns the value of attribute fmt.
19 20 21 |
# File 'lib/cli/ui/glyph.rb', line 19 def fmt @fmt end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
19 20 21 |
# File 'lib/cli/ui/glyph.rb', line 19 def handle @handle end |
#to_s ⇒ Object (readonly)
Returns the value of attribute to_s.
19 20 21 |
# File 'lib/cli/ui/glyph.rb', line 19 def to_s @to_s end |
Class Method Details
.available ⇒ Object
All available glyphs by name
79 80 81 |
# File 'lib/cli/ui/glyph.rb', line 79 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
71 72 73 74 75 |
# File 'lib/cli/ui/glyph.rb', line 71 def self.lookup(name) MAP.fetch(name.to_s) rescue KeyError raise InvalidGlyphHandle, name end |