File: abstract.rb

package info (click to toggle)
ruby-tty-command 0.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 1,990; makefile: 4; sh: 4
file content (52 lines) | stat: -rw-r--r-- 1,201 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require "pastel"

module TTY
  class Command
    module Printers
      class Abstract
        extend Forwardable

        def_delegators :@color, :decorate

        attr_reader :output, :options
        attr_accessor :out_data, :err_data

        # Initialize a Printer object
        #
        # @param [IO] output
        #   the printer output
        #
        # @api public
        def initialize(output, options = {})
          @output  = output
          @options = options
          @enabled = options.fetch(:color, true)
          @color   = ::Pastel.new(enabled: @enabled)

          @out_data = ""
          @err_data = ""
        end

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

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

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

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

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