Class: TTY::Font
- Inherits:
-
Object
- Object
- TTY::Font
- Defined in:
- lib/tty/font.rb,
lib/tty/font/result.rb,
lib/tty/font/version.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- FONTS_PATH =
::Pathname.new(::File.join(__dir__, "fonts"))
- VERSION =
"0.5.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.
13 14 15 16 17 |
# File 'lib/tty/font.rb', line 13 def initialize(font = :standard, **) @font = font @data = load_font(FONTS_PATH.join("#{font}.yml")) @space = .fetch(:letter_spacing) { @data['char_space'] } end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
Inspect font attributes
41 42 43 44 45 46 47 48 |
# File 'lib/tty/font.rb', line 41 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
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tty/font.rb', line 25 def write(text, **) result = Result.new chars = text.chars space = .fetch(:letter_spacing) { @space } indexes = words_boundary_indexes(text) @data['char_height'].times do |line_no| result << create_line(chars, indexes, line_no, space) end result.to_s end |