Class: Pressy::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/pressy/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout, error: $stderr) ⇒ Console

Returns a new instance of Console



6
7
8
9
10
# File 'lib/pressy/console.rb', line 6

def initialize(input: $stdin, output: $stdout, error: $stderr)
  @input = input
  @output = output
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error



4
5
6
# File 'lib/pressy/console.rb', line 4

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input



4
5
6
# File 'lib/pressy/console.rb', line 4

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output



4
5
6
# File 'lib/pressy/console.rb', line 4

def output
  @output
end

Instance Method Details

#prompt(label, echo: true) ⇒ Object



12
13
14
15
16
# File 'lib/pressy/console.rb', line 12

def prompt(label, echo: true)
  error.print "#{label} "
  value = echo ? input.gets : input.noecho(&:gets)
  value.chomp
end

#run(*cmd) ⇒ Object



18
19
20
21
# File 'lib/pressy/console.rb', line 18

def run(*cmd)
  system(*cmd)
  $?
end