Class: Mayl::Repl
Overview
Public: The class responsible for reading user input, interpreting it and executing associated commands.
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(path) ⇒ Repl
constructor
Public: Initializes a new REPL from a given path.
-
#start ⇒ Object
Public: Fires up the REPL that parses and executes given commands.
Methods included from Colors
Constructor Details
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
8 9 10 |
# File 'lib/mayl/repl.rb', line 8 def parser @parser end |
Instance Method Details
#start ⇒ Object
Public: Fires up the REPL that parses and executes given commands.
Returns nothing.
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 |
# File 'lib/mayl/repl.rb', line 22 def start locales = @env.locales.map(&:name) stty_save = `stty -g`.chomp prompt = color(:red, "> ") puts color(:green, "Detected locales: #{locales.join(', ')}") env = @env Readline.completion_proc = proc { |s| Commands.autocomplete(s, env) } Readline.completion_append_character = '' begin while input = Readline.readline(prompt, true) begin value = @parser.parse(input.chomp).execute @env.last_value = value @env.commit prompt = color(:red, [@env.namespace, '> '].reject(&:empty?).join(' ')) rescue => e print "Error: #{e.}" ensure print "\n" end end rescue Interrupt system("stty", stty_save) exit end end |