Class: Warg::Console::Content

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

Instance Method Summary collapse

Constructor Details

#initialize(text, console) ⇒ Content

Returns a new instance of Content.



389
390
391
392
# File 'lib/warg.rb', line 389

def initialize(text, console)
  @text = text.to_s.freeze
  @console = console
end

Instance Method Details

#inspectObject



418
419
420
# File 'lib/warg.rb', line 418

def inspect
  %{#<#{self.class.name} newline_count=#{newline_count} last_line_length=#{last_line_length} text=#{@text.inspect}>}
end

#last_line_lengthObject



404
405
406
407
408
409
410
411
412
# File 'lib/warg.rb', line 404

def last_line_length
  if @text.empty? || @text.end_with?("\n")
    0
  else
    # Remove CSI sequences so they don't count against the length of the line because
    # they are invisible in the terminal
    @text.lines.last.gsub(/\e\[\d+;\d+;\d+m/, "").length
  end
end

#newline_countObject



400
401
402
# File 'lib/warg.rb', line 400

def newline_count
  @text.count("\n")
end

#text=(value) ⇒ Object



394
395
396
397
398
# File 'lib/warg.rb', line 394

def text=(value)
  @text = value.to_s.freeze
  @console.reprint_content(self)
  value
end

#to_sObject



414
415
416
# File 'lib/warg.rb', line 414

def to_s
  @text
end