class Ppl::Command::Shell

Attributes

format[W]

Public Instance Methods

execute(input, output) click to toggle source
# File lib/ppl/command/shell.rb, line 14
def execute(input, output)
  begin
    shell(input, output)
  rescue SystemExit, Interrupt
    terminate_gracefully(input, output)
    false
  end
end
options(parser, options) click to toggle source
# File lib/ppl/command/shell.rb, line 10
def options(parser, options)
  parser.banner = "usage: ppl shell"
end

Private Instance Methods

determine_prompt(io) click to toggle source
# File lib/ppl/command/shell.rb, line 52
def determine_prompt(io)
  if io.tty?
    "ppl> "
  else
    ""
  end
end
process_line(line) click to toggle source
# File lib/ppl/command/shell.rb, line 47
def process_line(line)
  command = "#{$0} #{line}"
  Kernel.system(command)
end
read_line(input) click to toggle source
# File lib/ppl/command/shell.rb, line 42
def read_line(input)
  prompt = determine_prompt(input.stdin)
  line   = Readline.readline(prompt, true)
end
shell(input, output) click to toggle source
# File lib/ppl/command/shell.rb, line 26
def shell(input, output)
  welcome_user(input, output)
  while line = read_line(input)
    break if ["exit", false].include?(line)
    process_line(line)
  end
  terminate_gracefully(input, output)
  true
end
terminate_gracefully(input, output) click to toggle source
# File lib/ppl/command/shell.rb, line 60
def terminate_gracefully(input, output)
  if input.stdin.tty?
    output.line("")
  end
end
welcome_user(input, output) click to toggle source
# File lib/ppl/command/shell.rb, line 36
def welcome_user(input, output)
  if input.stdin.tty?
    output.line("ppl #{Ppl::Version} (type \"exit\" to leave)")
  end
end