Class: BruteCLI::Terminal

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

Overview

Single owner of all terminal output. Every object that needs to write to the terminal receives a Terminal instance and writes through its buffer — nothing calls puts/print/$stdout directly.

terminal = Terminal.new
terminal.buffer << "hello"          # prints with newline
terminal.buffer.print "\e7"         # raw print, no newline
terminal.buffer.warn "uh oh"        # prints to stderr

Defined Under Namespace

Classes: Buffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTerminal

Returns a new instance of Terminal.



19
20
21
# File 'lib/brute_cli/terminal.rb', line 19

def initialize
  @buffer = Buffer.new
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



17
18
19
# File 'lib/brute_cli/terminal.rb', line 17

def buffer
  @buffer
end

Instance Method Details

#separator(thick: false) ⇒ Object



27
28
29
# File 'lib/brute_cli/terminal.rb', line 27

def separator(thick: false)
  BufferOutput::Separator.new(width: width, thick: thick)
end

#widthObject



23
24
25
# File 'lib/brute_cli/terminal.rb', line 23

def width
  TTY::Screen.width
end