class CLI::UI::Glyph

Constants

BUG
CHECK
CHEVRON
HOURGLASS
INFO
MAP

Mapping of glyphs to terminal output

QUESTION
STAR
WARNING
X

Attributes

codepoint[R]
color[R]
fmt[R]
handle[R]
to_s[R]

Public Class Methods

available() click to toggle source

All available glyphs by name

# File lib/cli/ui/glyph.rb, line 79
def self.available
  MAP.keys
end
lookup(name) click to toggle source

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

# File lib/cli/ui/glyph.rb, line 71
def self.lookup(name)
  MAP.fetch(name.to_s)
rescue KeyError
  raise InvalidGlyphHandle, name
end
new(handle, codepoint, plain, color) click to toggle source

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)

  • plain - A fallback plain string to be used in case glyphs are disabled

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

# 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

Public Instance Methods

char() click to toggle source

Fetches the actual character(s) to be displayed for a glyph, based on the current OS support

Returns

Returns the glyph string

# File lib/cli/ui/glyph.rb, line 46
def char
  CLI::UI::OS.current.supports_emoji? ? @char : @plain
end