Class: Hobostove::Window
- Inherits:
-
Object
- Object
- Hobostove::Window
- Defined in:
- lib/hobostove/window.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
3 4 5 |
# File 'lib/hobostove/window.rb', line 3 def @messages end |
Instance Method Details
#connect ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hobostove/window.rb', line 5 def connect @current_message = "" @running = true @messages = [] begin start_curses load_users stream main rescue => e Hobostove.logger.error(e.inspect) ensure Hobostove.logger.debug("terminated") stop_curses end end |
#handle_message(message) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hobostove/window.rb', line 84 def () Hobostove.logger.debug(.inspect) case .type when "TextMessage" Notify.notify .username, .body when "EnterMessage" @users_panel.add_user(.user) when "LeaveMessage" @users_panel.remove_user(.user) when "UploadMessage" Notify.notify .username, .body end .render_lines().each do |line| @messages_panel.<<(line, false) end rescue => e Hobostove.logger.fatal(e.inspect) end |
#main ⇒ Object
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 |
# File 'lib/hobostove/window.rb', line 23 def main campfire.join while @running && (ch = Curses.getch) Hobostove.logger.debug("#{ch} - #{ch.chr.inspect} pressed") case ch when 14 # C+n @messages_panel.scroll_down when 16 # C+p @messages_panel.scroll_up when 10 # enter speak when 21 # C-u @current_message = "" when 127 # backspace @current_message = @current_message.first(@current_message.size - 1) when 9 # tab @current_message = "#{@users_panel.user_names.find { |user| user =~ /^#@current_message/ }}: " else @current_message << ch.chr end @message_panel << @current_message @message_panel.update_cursor end campfire.leave end |
#speak ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/hobostove/window.rb', line 53 def speak if @current_message == "/quit" @running = false return end campfire. @current_message @current_message = "" end |
#stream ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hobostove/window.rb', line 63 def stream Thread.new do loop do begin recent = campfire. recent.each do || next if .include?(.id) << .id () end @messages_panel.refresh sleep 1 rescue => e Hobostove.logger.error(e.inspect) end end end end |