Class: Tui::SegmentWriter::EmojiSegment
- Inherits:
-
Object
- Object
- Tui::SegmentWriter::EmojiSegment
- Defined in:
- lib/tui.rb
Overview
Emoji with precomputed width - triggers has_wide flag
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#char_count ⇒ Object
How many characters this counts as in string.length.
-
#initialize(char) ⇒ EmojiSegment
constructor
A new instance of EmojiSegment.
- #to_s ⇒ Object
-
#width_delta ⇒ Object
Extra width beyond char_count (for width calculation).
Constructor Details
#initialize(char) ⇒ EmojiSegment
Returns a new instance of EmojiSegment.
708 709 710 711 712 713 714 715 716 717 718 |
# File 'lib/tui.rb', line 708 def initialize(char) @char = char.to_s # Precompute: emoji = 2, variation selectors = 0 @width = 0 @char_count = 0 @char.each_codepoint do |code| w = Metrics.char_width(code) @width += w @char_count += 1 if w > 0 # Don't count zero-width chars end end |
Instance Attribute Details
#char ⇒ Object (readonly)
Returns the value of attribute char.
706 707 708 |
# File 'lib/tui.rb', line 706 def char @char end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
706 707 708 |
# File 'lib/tui.rb', line 706 def width @width end |
Instance Method Details
#char_count ⇒ Object
How many characters this counts as in string.length
725 726 727 |
# File 'lib/tui.rb', line 725 def char_count @char.length end |
#to_s ⇒ Object
720 721 722 |
# File 'lib/tui.rb', line 720 def to_s @char end |
#width_delta ⇒ Object
Extra width beyond char_count (for width calculation)
730 731 732 |
# File 'lib/tui.rb', line 730 def width_delta @width - char_count end |