Class: Warg::Console::Content
- Inherits:
-
Object
- Object
- Warg::Console::Content
- Defined in:
- lib/warg.rb
Instance Method Summary collapse
-
#initialize(text, console) ⇒ Content
constructor
A new instance of Content.
- #inspect ⇒ Object
- #last_line_length ⇒ Object
- #newline_count ⇒ Object
- #text=(value) ⇒ Object
- #to_s ⇒ Object
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
#inspect ⇒ Object
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_length ⇒ Object
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_count ⇒ Object
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_s ⇒ Object
415 416 417 |
# File 'lib/warg.rb', line 415 def to_s @text end |