Class: Termtter::CommandLine
- Inherits:
-
Object
- Object
- Termtter::CommandLine
- Includes:
- Singleton
- Defined in:
- lib/plugins/another_prompt.rb,
lib/plugins/defaults/command_line.rb
Constant Summary collapse
- STTY_ORIGIN =
`stty -g`.chomp
Class Method Summary collapse
Instance Method Summary collapse
- #call(command_text) ⇒ Object
- #call_prompt(command) ⇒ Object
- #prompt ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wait_keypress ⇒ Object
Class Method Details
.start ⇒ Object
9 10 11 |
# File 'lib/plugins/defaults/command_line.rb', line 9 def start instance.start end |
.stop ⇒ Object
13 14 15 |
# File 'lib/plugins/defaults/command_line.rb', line 13 def stop instance.stop end |
Instance Method Details
#call(command_text) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/plugins/defaults/command_line.rb', line 26 def call(command_text) # Example: # t.register_hook(:post_all, :point => :prepare_command) do |s| # "update #{s}" # end Client.get_hooks('prepare_command').each {|hook| command_text = hook.call(command_text) } Client.execute(command_text) rescue CommandNotFound => e hooks = Client.get_hooks('command_not_found') raise e if hooks.empty? hooks.each {|hook| hook.call(command_text) } rescue TimeoutError puts TermColor.parse("<red>Time out :(</red>") end |
#call_prompt(command) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/plugins/another_prompt.rb', line 95 def call_prompt(command) Client.execute("curry #{command}") if buf = Readline.readline(ERB.new(prompt).result(Termtter::API.twitter.__send__(:binding)), true) Readline::HISTORY.pop if buf.empty? begin call(buf) rescue Exception => e Client.handle_error(e) end else puts end ensure Client.execute('uncurry') end |
#prompt ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/plugins/defaults/command_line.rb', line 45 def prompt prompt_text = config.prompt Client.get_hooks('prepare_prompt').each {|hook| prompt_text = hook.call(prompt_text) } prompt_text end |
#start ⇒ Object
18 19 20 |
# File 'lib/plugins/defaults/command_line.rb', line 18 def start start_input_thread end |
#stop ⇒ Object
22 23 24 |
# File 'lib/plugins/defaults/command_line.rb', line 22 def stop @input_thread.kill if @input_thread end |
#wait_keypress ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/plugins/another_prompt.rb', line 111 def wait_keypress system('stty', '-echo', '-icanon') c = STDIN.getc return [c].pack('c') ensure system('stty', STTY_ORIGIN) end |