twat 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,8 @@ require 'yaml'
6
6
  require 'optparse'
7
7
  require 'oauth'
8
8
 
9
+ require 'readline-ng'
10
+
9
11
  %w[config exceptions argparse actions migration options endpoint].each do |filename|
10
12
  require "twat/#{filename}"
11
13
  end
@@ -48,8 +50,8 @@ end
48
50
 
49
51
  module Twat
50
52
  VERSION_MAJOR = 0
51
- VERSION_MINOR = 5
52
- VERSION_PATCH = 4
53
+ VERSION_MINOR = 6
54
+ VERSION_PATCH = 0
53
55
 
54
56
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
55
57
  class Twat
@@ -22,17 +22,17 @@ module Twat
22
22
  idx = pad(idx) if idx
23
23
  text = deentitize(twt.text)
24
24
  if config.colors?
25
- print "#{idx.cyan}:" if idx
25
+ buf = idx ? "#{idx.cyan}:" : ""
26
26
  if twt.user.screen_name == config.account_name.to_s
27
- puts "#{twt.user.screen_name.bold.blue}: #{text}"
27
+ buf += "#{twt.user.screen_name.bold.blue}: #{text}"
28
28
  elsif text.mentions?(config.account_name)
29
- puts "#{twt.user.screen_name.bold.red}: #{text}"
29
+ buf += "#{twt.user.screen_name.bold.red}: #{text}"
30
30
  else
31
- puts "#{twt.user.screen_name.bold.cyan}: #{text}"
31
+ buf += "#{twt.user.screen_name.bold.cyan}: #{text}"
32
32
  end
33
33
  else
34
- print "#{idx}:" if idx
35
- puts "#{twt.user.screen_name}: #{text}"
34
+ buf = idx ? "#{idx}: " : ""
35
+ buf += "#{twt.user.screen_name}: #{text}"
36
36
  end
37
37
  end
38
38
 
@@ -1,4 +1,5 @@
1
1
  module Twat
2
+ POLLING_RESOLUTION = 20
2
3
 
3
4
  class NoSuchTweet < Exception; end
4
5
 
@@ -42,10 +43,24 @@ module Twat
42
43
 
43
44
  class Actions
44
45
 
46
+ def initialize
47
+ @reader = ReadlineNG::Reader.new
48
+
49
+ def @reader.filter
50
+ case @buf.length
51
+ when 140
52
+ _print ""
53
+ when 139
54
+ _print ""
55
+ end
56
+ end
57
+ end
58
+
45
59
  def follow
46
- # I can't see any way to poll the server for updates, so in the meantime
47
- # we will have to retrieve a few tweets from the timeline, and then poll
48
- # occasionally :/
60
+ # Probably belongs to readline-ng
61
+ $stty_saved = `stty -g`
62
+ `stty -echo raw`
63
+
49
64
  twitter_auth
50
65
  failcount = 0
51
66
  @tweetstack = TweetStack.new
@@ -55,30 +70,29 @@ module Twat
55
70
  while true do
56
71
  begin
57
72
  last_id = process_followed(tweets) if tweets.any?
58
- config.polling_interval.times do
73
+ (config.polling_interval * POLLING_RESOLUTION).times do
59
74
  begin
60
- handle_input(STDIN.read_nonblock(128).chop)
61
- rescue Errno::EAGAIN
62
- nil
75
+ @reader.tick
76
+ @reader.each_line { |inp| handle_input(inp) }
63
77
  rescue TweetTooLong
64
78
  puts "Too long".red
65
79
  end
66
- sleep 1
80
+ sleep 1.0/POLLING_RESOLUTION
67
81
  end
68
82
  tweets = Twitter.home_timeline(:since_id => last_id)
69
83
  failcount = 0
70
84
  rescue Interrupt
71
85
  break
72
- rescue Twitter::ServiceUnavailable
73
- if failcount > 2
74
- puts "3 consecutive failures, giving up"
75
- else
76
- sleeptime = 60 * (failcount + 1)
77
- print "(__-){".red
78
- puts ": the fail whale has been rolled out, sleeping for #{sleeptime} seconds"
79
- sleep sleeptime
80
- failcount += 1
81
- end
86
+ # rescue Twitter::ServiceUnavailable
87
+ # if failcount > 2
88
+ # puts "3 consecutive failures, giving up"
89
+ # else
90
+ # sleeptime = 60 * (failcount + 1)
91
+ # print "(__-){".red
92
+ # puts ": the fail whale has been rolled out, sleeping for #{sleeptime} seconds"
93
+ # sleep sleeptime
94
+ # failcount += 1
95
+ # end
82
96
  rescue Errno::ECONNRESET
83
97
  rescue Errno::ETIMEDOUT
84
98
  if failcount > 2
@@ -88,6 +102,8 @@ module Twat
88
102
  end
89
103
  end
90
104
  end
105
+ ensure
106
+ `stty #{$stty_saved}`
91
107
  end
92
108
 
93
109
  private
@@ -102,7 +118,7 @@ module Twat
102
118
  tweets.reverse.each do |tweet|
103
119
  id = @tweetstack << tweet
104
120
  beep if config.beep? && tweet.text.mentions?(config.account_name)
105
- format(tweet, @tweetstack.last)
121
+ @reader.puts_above format(tweet, @tweetstack.last)
106
122
  last_id = tweet.id
107
123
  end
108
124
 
@@ -115,8 +131,12 @@ module Twat
115
131
  begin
116
132
  retweet($1.to_i)
117
133
  rescue NoSuchTweet
118
- puts "No such tweet".red
134
+ print "No such tweet\n".red
119
135
  end
136
+ when /follow (.*)/
137
+ follow_user($1)
138
+ when /test/
139
+ @reader.puts_above "Testline!"
120
140
  else
121
141
  # Assume they want to tweet something
122
142
  raise TweetTooLong if inp.length > 140
@@ -1,10 +1,10 @@
1
1
  module Twat
2
2
  class Actions
3
3
 
4
- def follow_user
4
+ def follow_user(user = nil)
5
5
  twitter_auth
6
6
 
7
- Twitter.follow(opts[:user])
7
+ Twitter.follow(user || opts[:user])
8
8
  end
9
9
 
10
10
  end
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.add_dependency "twitter"
15
15
  s.add_dependency "oauth"
16
+ s.add_dependency "readline-ng"
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-11 00:00:00.000000000Z
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twitter
16
- requirement: &13247260 !ruby/object:Gem::Requirement
16
+ requirement: &10151740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13247260
24
+ version_requirements: *10151740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth
27
- requirement: &13246620 !ruby/object:Gem::Requirement
27
+ requirement: &10150460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *13246620
35
+ version_requirements: *10150460
36
+ - !ruby/object:Gem::Dependency
37
+ name: readline-ng
38
+ requirement: &10149800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *10149800
36
47
  description: Command line tool for tweeting and whatnot
37
48
  email:
38
49
  - richo@psych0tik.net
@@ -91,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
102
  version: '0'
92
103
  requirements: []
93
104
  rubyforge_project:
94
- rubygems_version: 1.8.6
105
+ rubygems_version: 1.8.10
95
106
  signing_key:
96
107
  specification_version: 3
97
108
  summary: Command line tool for tweeting and whatnot