Class: Tui::SegmentWriter::EmojiSegment

Inherits:
Object
  • Object
show all
Defined in:
lib/tui.rb

Overview

Emoji with precomputed width - triggers has_wide flag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ EmojiSegment

Returns a new instance of EmojiSegment.



659
660
661
662
663
664
665
666
667
668
669
# File 'lib/tui.rb', line 659

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

#charObject (readonly)

Returns the value of attribute char.



657
658
659
# File 'lib/tui.rb', line 657

def char
  @char
end

#widthObject (readonly)

Returns the value of attribute width.



657
658
659
# File 'lib/tui.rb', line 657

def width
  @width
end

Instance Method Details

#char_countObject

How many characters this counts as in string.length



676
677
678
# File 'lib/tui.rb', line 676

def char_count
  @char.length
end

#to_sObject



671
672
673
# File 'lib/tui.rb', line 671

def to_s
  @char
end

#width_deltaObject

Extra width beyond char_count (for width calculation)



681
682
683
# File 'lib/tui.rb', line 681

def width_delta
  @width - char_count
end