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 (⧖)
new('H', 0x29d6, 'H', Color::ORANGE)
- WARNING =
WARNING SIGN + VARIATION SELECTOR 16 (⚠️ )
new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW)
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
: String.
-
#codepoint ⇒ Object
readonly
: (Integer | Array).
-
#color ⇒ Object
readonly
: Color.
-
#fmt ⇒ Object
readonly
: String.
-
#handle ⇒ Object
readonly
: String.
-
#to_s ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.available ⇒ Object
All available glyphs by name.
-
.lookup(name) ⇒ Object
Looks up a glyph by name.
Instance Method Summary collapse
-
#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 theMAPconstant -
codepoint- The codepoint used to create the glyph (e.g.0x2717for 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::Colorfor options.
: (String handle, (Integer | Array) codepoint, String plain, Color color) -> void
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cli/ui/glyph.rb', line 41 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
#char ⇒ Object (readonly)
: String
23 24 25 |
# File 'lib/cli/ui/glyph.rb', line 23 def char @char end |
#codepoint ⇒ Object (readonly)
: (Integer | Array)
26 27 28 |
# File 'lib/cli/ui/glyph.rb', line 26 def codepoint @codepoint end |
#color ⇒ Object (readonly)
: Color
29 30 31 |
# File 'lib/cli/ui/glyph.rb', line 29 def color @color end |
#fmt ⇒ Object (readonly)
: String
23 24 25 |
# File 'lib/cli/ui/glyph.rb', line 23 def fmt @fmt end |
#handle ⇒ Object (readonly)
: String
23 24 25 |
# File 'lib/cli/ui/glyph.rb', line 23 def handle @handle end |
#to_s ⇒ Object (readonly)
: String
23 24 25 |
# File 'lib/cli/ui/glyph.rb', line 23 def to_s @to_s end |
Class Method Details
.available ⇒ Object
All available glyphs by name
: -> Array
84 85 86 |
# File 'lib/cli/ui/glyph.rb', line 84 def 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
: (String name) -> Glyph
75 76 77 78 79 |
# File 'lib/cli/ui/glyph.rb', line 75 def lookup(name) MAP.fetch(name.to_s) rescue KeyError raise InvalidGlyphHandle, name end |