Class: TTY::Font
- Inherits:
-
Object
- Object
- TTY::Font
- Defined in:
- lib/tty/font.rb,
lib/tty/font/version.rb
Constant Summary collapse
- FONTS_PATH =
Pathname.new(File.join(__dir__, 'font'))
- VERSION =
"0.1.0"
Instance Method Summary collapse
-
#initialize(font = :standard, **options) ⇒ Font
constructor
A new instance of Font.
-
#inspect ⇒ Object
(also: #to_s)
Inspect font attributes.
-
#write(text, **options) ⇒ Object
Write text in a font format.
Constructor Details
#initialize(font = :standard, **options) ⇒ Font
Returns a new instance of Font.
12 13 14 15 16 |
# File 'lib/tty/font.rb', line 12 def initialize(font = :standard, **) @font = font @data = load_font(FONTS_PATH.join("#{font}.yml")) @space = .fetch(:letter_spacing) { 0 } end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
Inspect font attributes
40 41 42 43 44 45 46 47 |
# File 'lib/tty/font.rb', line 40 def inspect vars = [ "name=#{@font.inspect}", "letter_spacing=#{@space}", "char_height=#{@data['char_height']}" ] '#<%s:0x%x %s>' % [self.class, (object_id << 1), vars.join(', ')] end |
#write(text, **options) ⇒ Object
Write text in a font format
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tty/font.rb', line 24 def write(text, **) output = [] chars = text.chars space = .fetch(:letter_spacing) { @space } indexes = words_boundary_indexes(text) @data['char_height'].times do |line| output << add_line(chars, indexes, line, space) end output.join("\n") end |