Parent

Included Modules

Termtter::CommandLine

Public Class Methods

start() click to toggle source
# File lib/plugins/defaults/command_line.rb, line 8
def start
  instance.start
end
stop() click to toggle source
# File lib/plugins/defaults/command_line.rb, line 12
def stop
  instance.stop
end

Public Instance Methods

call(command_text) click to toggle source
# File lib/plugins/defaults/command_line.rb, line 25
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) click to toggle source
# File lib/plugins/another_prompt.rb, line 94
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() click to toggle source
# File lib/plugins/defaults/command_line.rb, line 44
def prompt
  prompt_text = config.prompt
  Client.get_hooks('prepare_prompt').each {|hook|
    prompt_text = hook.call(prompt_text)
  }
  prompt_text
end
start() click to toggle source
# File lib/plugins/defaults/command_line.rb, line 17
def start
  start_input_thread
end
start_input_thread() click to toggle source
# File lib/plugins/another_prompt.rb, line 72
def start_input_thread
  setup_readline()
  trap_setting()
  @input_thread = Thread.new do
    loop do
      begin
        value = config.plugins.another_prompt.shortcut_setting[wait_keypress]
        Client.pause
        case value
        when String
          call_prompt(value)
        when Proc
          value.call
        end
      ensure
        Client.resume
      end
    end
  end
  @input_thread.join
end
stop() click to toggle source
# File lib/plugins/defaults/command_line.rb, line 21
def stop
  @input_thread.kill if @input_thread
end
trap_setting() click to toggle source
# File lib/plugins/another_prompt.rb, line 118
def trap_setting()
  begin
    trap("INT") do
      begin
        system "stty", STTY_ORIGIN
      ensure
        Client.execute('exit')
      end
    end
  rescue ArgumentError
  rescue Errno::ENOENT
  end
end
wait_keypress() click to toggle source
# File lib/plugins/another_prompt.rb, line 110
def wait_keypress
  system('stty', '-echo', '-icanon')
  c = STDIN.getc
  return [c].pack('c')
ensure
  system('stty', STTY_ORIGIN)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.