Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:jugyo/termtter
Browse files Browse the repository at this point in the history
  • Loading branch information
koichiro committed Jan 8, 2009
2 parents 1f94ca7 + aa41be3 commit 48f8614
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/termtter.rb
Expand Up @@ -343,8 +343,9 @@ def resume

def exit
call_hooks([], :exit, nil)
@@update_thread.exit!
@@input_thread.exit!
@@main_thread.kill
@@update_thread.kill
@@input_thread.kill
end

def run
Expand All @@ -354,6 +355,7 @@ def run
tw = Termtter::Twitter.new(configatron.user_name, configatron.password)
call_hooks([], :initialize, tw)

@@input_thread = nil
@@update_thread = Thread.new do
since_id = nil
loop do
Expand All @@ -364,9 +366,10 @@ def run
unless statuses.empty?
since_id = statuses[0].id
end
# TODO: erase prompt
call_hooks(statuses, :update_friends_timeline, tw)
initialized = true

@@input_thread.kill if @@input_thread && !statuses.empty?
rescue OpenURI::HTTPError => e
if e.message == '401 Unauthorized'
puts 'Could not login'
Expand All @@ -389,7 +392,23 @@ def run
Readline.__send__("#{vi_or_emacs}_editing_mode")
end

@@input_thread = Thread.new do
begin
stty_save = `stty -g`.chomp
trap("INT") { system "stty", stty_save; exit }
rescue Errno::ENOENT
end

@@main_thread = Thread.new do
loop do
@@input_thread = create_input_thread(tw)
@@input_thread.join
end
end
@@main_thread.join
end

def create_input_thread(tw)
Thread.new do
erb = ERB.new(configatron.prompt)
while buf = Readline.readline(erb.result(tw.__send__(:binding)), true)
begin
Expand All @@ -403,14 +422,6 @@ def run
end
end
end

begin
stty_save = `stty -g`.chomp
trap("INT") { system "stty", stty_save; exit }
rescue Errno::ENOENT
end

@@input_thread.join
end
end
end
Expand Down

0 comments on commit 48f8614

Please sign in to comment.