Class: YouPlot::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/youplot/command.rb,
lib/youplot/command/parser.rb,
lib/youplot/command/options.rb,
lib/youplot/command/plot_params.rb

Defined Under Namespace

Classes: Options, Parser, PlotParams

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Command

Returns a new instance of Command.



16
17
18
19
20
21
22
23
# File 'lib/youplot/command.rb', line 16

def initialize(argv = ARGV)
  @argv    = argv
  @parser  = Parser.new
  @command = nil
  @params  = nil
  @options = nil
  @backend = YouPlot::Backends::UnicodePlotBackend
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



13
14
15
# File 'lib/youplot/command.rb', line 13

def command
  @command
end

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/youplot/command.rb', line 14

def data
  @data
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/youplot/command.rb', line 13

def options
  @options
end

#paramsObject

Returns the value of attribute params.



13
14
15
# File 'lib/youplot/command.rb', line 13

def params
  @params
end

#parserObject (readonly)

Returns the value of attribute parser.



14
15
16
# File 'lib/youplot/command.rb', line 14

def parser
  @parser
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/youplot/command.rb', line 30

def run
  parser.parse_options(@argv)
  @command ||= parser.command
  @options ||= parser.options
  @params  ||= parser.params

  if i[colors color colours colour].include? @command
    plot = create_plot
    output_plot(plot)
  elsif options[:progressive]
    stop = false
    Signal.trap(:INT) { stop = true }
    options[:output].print "\e[?25l" # make cursor invisible
    while (input = Kernel.gets)
      n = main_progressive(input)
      break if stop

      options[:output].print "\e[#{n}F"
    end
    options[:output].print "\e[0J"
    options[:output].print "\e[?25h" # make cursor visible
  else
    # Sometimes the input file does not end with a newline code.
    while (input = Kernel.gets(nil))
      main(input)
    end
  end
end

#run_as_executableObject



25
26
27
28
# File 'lib/youplot/command.rb', line 25

def run_as_executable
  YouPlot.run_as_executable = true
  run
end