Class: Twterm::DirectMessageComposer

Inherits:
Object
  • Object
show all
Includes:
Curses, Readline, Publisher, Utils
Defined in:
lib/twterm/direct_message_composer.rb

Instance Method Summary collapse

Methods included from Utils

check_type

Methods included from Publisher

#publish

Constructor Details

#initialize(app, client) ⇒ DirectMessageComposer

Returns a new instance of DirectMessageComposer.



13
14
15
# File 'lib/twterm/direct_message_composer.rb', line 13

def initialize(app, client)
  @app, @client = app, client
end

Instance Method Details

#compose(recipient) ⇒ Object



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
# File 'lib/twterm/direct_message_composer.rb', line 17

def compose(recipient)
  check_type User, recipient

  clear

  resetter = proc do
    reset_prog_mode
    sleep 0.1
    publish(Event::Screen::Refresh.new)
  end

  thread = Thread.new do
    close_screen

    puts "\nCompose new message to @%s:" % recipient.screen_name

    app.completion_manager.set_default_mode!

    loop do
      line = (readline('> ', true) || '').strip
      break if line.empty?

      if line.end_with?('\\')
        @text << line.chop.rstrip + "\n"
      else
        @text << line
        break
      end
    end

    puts "\n"

    resetter.call
    send(recipient) unless text.empty?
  end

  app.register_interruption_handler do
    thread.kill
    clear
    puts "\nCanceled"
    resetter.call
  end

  thread.join
end