Class: Twterm::Tweetbox
- Inherits:
-
Object
- Object
- Twterm::Tweetbox
- Includes:
- Curses, Readline, Singleton
- Defined in:
- lib/twterm/tweetbox.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #compose(in_reply_to = nil) ⇒ Object
-
#initialize ⇒ Tweetbox
constructor
A new instance of Tweetbox.
- #length ⇒ Object
- #post ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize ⇒ Tweetbox
Returns a new instance of Tweetbox.
7 8 9 |
# File 'lib/twterm/tweetbox.rb', line 7 def initialize @status = '' end |
Instance Method Details
#clear ⇒ Object
93 94 95 |
# File 'lib/twterm/tweetbox.rb', line 93 def clear @status = '' end |
#compose(in_reply_to = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/twterm/tweetbox.rb', line 11 def compose(in_reply_to = nil) if in_reply_to.is_a? Status @in_reply_to = in_reply_to else @in_reply_to = nil end resetter = proc do reset_prog_mode sleep 0.1 Screen.instance.refresh end thread = Thread.new do close_screen if @in_reply_to.nil? puts "\nCompose new tweet:" else puts "\nReply to @#{@in_reply_to.user.screen_name}'s tweet: \"#{@in_reply_to.text}\"" end CompletionManager.instance.set_default_mode! loop do loop do msg = @in_reply_to.nil? || !@status.empty? ? '> ' : "> @#{in_reply_to.user.screen_name} " line = (readline(msg, true) || '').strip break if line.empty? if line.end_with?('\\') @status << line.chop.lstrip + "\n" else @status << line break end end puts "\n" case validate when :too_long puts "Status is too long (#{length} / 140 characters)" when :invalid_characters puts 'Status contains invalid characters' else break end puts "\n" clear end resetter.call post end App.instance.register_interruption_handler do thread.kill clear puts "\ncanceled" resetter.call end thread.join end |
#length ⇒ Object
89 90 91 |
# File 'lib/twterm/tweetbox.rb', line 89 def length Twitter::Validation.tweet_length(@status) end |
#post ⇒ Object
78 79 80 81 82 83 |
# File 'lib/twterm/tweetbox.rb', line 78 def post return if validate Client.current.post(@status, @in_reply_to) clear end |
#validate ⇒ Object
85 86 87 |
# File 'lib/twterm/tweetbox.rb', line 85 def validate Twitter::Validation.tweet_invalid?(@status) end |