Module: LokkaSh::Prompt
- Defined in:
- lib/lokka-sh/prompt.rb
Class Method Summary collapse
Class Method Details
.execute(line) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lokka-sh/prompt.rb', line 32 def execute(line) if command = LokkaSh::Command.find(line) start = Time.now arg = line.split(/\s+/, 2)[1] rescue nil command.call(arg) LokkaSh::Color.with(:blue) { "#{Time.now - start}sec" } else LokkaSh::Color.with(:bg_red) { "Command not found" } end end |
.invoke ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lokka-sh/prompt.rb', line 5 def invoke setup_readline while buf = Readline.readline(prompt, true) line = buf.strip next if line.empty? begin execute(line) rescue SystemExit raise rescue Exception => e LokkaSh::Color.with(:bg_red) { "#{e.}\n#{e.backtrace.join("\n")}" } end end setup_readline end |
.prompt ⇒ Object
23 24 25 |
# File 'lib/lokka-sh/prompt.rb', line 23 def prompt "%s> " % "lokka-sh(#{File.basename(::Lokka.root)})" end |
.setup_readline ⇒ Object
27 28 29 30 |
# File 'lib/lokka-sh/prompt.rb', line 27 def setup_readline Readline.basic_word_break_characters = "" Readline.completion_proc = LokkaSh::Command.completion_proc end |