Class: Twterm::Tweetbox

Inherits:
Object
  • Object
show all
Includes:
Curses, Readline, Singleton
Defined in:
lib/twterm/tweetbox.rb

Instance Method Summary collapse

Constructor Details

#initializeTweetbox

Returns a new instance of Tweetbox.



7
8
9
# File 'lib/twterm/tweetbox.rb', line 7

def initialize
  @status = ''
end

Instance Method Details

#clearObject



49
50
51
# File 'lib/twterm/tweetbox.rb', line 49

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
# 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
    puts "\ncompose new tweet:"
    @status = readline(@in_reply_to.nil? ? '> ' : " @#{in_reply_to.user.screen_name} ", true)
    resetter.call
    post
  end

  App.instance.register_interruption_handler do
    thread.kill
    clear
    puts "\ncanceled"
    resetter.call
  end

  thread.join
end

#postObject



42
43
44
45
46
47
# File 'lib/twterm/tweetbox.rb', line 42

def post
  return if @status.nil?

  Client.current.post(@status, @in_reply_to)
  clear
end