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.



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

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

Instance Method Details

#inspectObject



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

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

#last_line_lengthObject



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

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



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

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

#text=(value) ⇒ Object



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

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

#to_sObject



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

def to_s
  @text
end