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



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

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.



14
15
16
# File 'lib/tty/command/printers/abstract.rb', line 14

def err_data
  @err_data
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#out_dataObject

Returns the value of attribute out_data.



14
15
16
# File 'lib/tty/command/printers/abstract.rb', line 14

def out_data
  @out_data
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details



40
41
42
# File 'lib/tty/command/printers/abstract.rb', line 40

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


44
45
46
# File 'lib/tty/command/printers/abstract.rb', line 44

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


36
37
38
# File 'lib/tty/command/printers/abstract.rb', line 36

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


32
33
34
# File 'lib/tty/command/printers/abstract.rb', line 32

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

#write(cmd, message) ⇒ Object

Raises:

  • (NotImplemented)


48
49
50
# File 'lib/tty/command/printers/abstract.rb', line 48

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