Class: TTY::Command::Printers::Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tty/command/printers/abstract.rb

Direct Known Subclasses

Null, Pretty, Progress, Quiet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ Abstract

Initialize a Printer object

Parameters:

  • output (IO)

    the printer output



20
21
22
23
24
25
26
27
28
# File 'lib/tty/command/printers/abstract.rb', line 20

def initialize(output, options = {})
  @output  = output
  @options = options
  @enabled = options.fetch(:color, true)
  @color   = ::Pastel.new(enabled: @enabled)

  @out_data = ""
  @err_data = ""
end

Instance Attribute Details

#err_dataObject

Returns the value of attribute err_data.



12
13
14
# File 'lib/tty/command/printers/abstract.rb', line 12

def err_data
  @err_data
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/tty/command/printers/abstract.rb', line 11

def options
  @options
end

#out_dataObject

Returns the value of attribute out_data.



12
13
14
# File 'lib/tty/command/printers/abstract.rb', line 12

def out_data
  @out_data
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/tty/command/printers/abstract.rb', line 11

def output
  @output
end

Instance Method Details



38
39
40
# File 'lib/tty/command/printers/abstract.rb', line 38

def print_command_err_data(cmd, *args)
  write(args.join(" "))
end


42
43
44
# File 'lib/tty/command/printers/abstract.rb', line 42

def print_command_exit(cmd, *args)
  write(args.join(" "))
end


34
35
36
# File 'lib/tty/command/printers/abstract.rb', line 34

def print_command_out_data(cmd, *args)
  write(args.join(" "))
end


30
31
32
# File 'lib/tty/command/printers/abstract.rb', line 30

def print_command_start(cmd, *args)
  write(cmd.to_command + "#{args.join}")
end

#write(cmd, message) ⇒ Object

Raises:

  • (NotImplemented)


46
47
48
# File 'lib/tty/command/printers/abstract.rb', line 46

def write(cmd, message)
  raise NotImplemented, "Abstract printer cannot be used"
end