Class: BruteCLI::Terminal::Buffer

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

Overview

Passthrough buffer — for now every write goes straight to the IO. This is the ONLY object allowed to touch $stdout / $stderr.

When no explicit IO is provided, delegates to $stdout / $stderr at call time (not construction time) so test IO swaps work correctly.

Instance Method Summary collapse

Constructor Details

#initialize(out: nil, err: nil) ⇒ Buffer

Returns a new instance of Buffer.



37
38
39
40
# File 'lib/brute_cli/terminal.rb', line 37

def initialize(out: nil, err: nil)
  @out = out
  @err = err
end

Instance Method Details

#<<(text) ⇒ Object

Primary output — appends text with a trailing newline (like puts).



43
44
45
46
# File 'lib/brute_cli/terminal.rb', line 43

def <<(text)
  out.puts(text)
  self
end

#flushObject



60
61
62
63
# File 'lib/brute_cli/terminal.rb', line 60

def flush
  out.flush
  self
end

#ioObject

Expose the underlying IO so TTY::Spinner and StreamFormatter can use it as their output target.



67
68
69
# File 'lib/brute_cli/terminal.rb', line 67

def io
  out
end

Raw output — no trailing newline (for escape sequences, etc.).



49
50
51
52
# File 'lib/brute_cli/terminal.rb', line 49

def print(text)
  out.print(text)
  self
end

#warn(text) ⇒ Object

Stderr output.



55
56
57
58
# File 'lib/brute_cli/terminal.rb', line 55

def warn(text)
  err.puts(text)
  self
end