hobostove 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hobostove.rb +180 -0
- metadata +95 -0
data/lib/hobostove.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'tinder'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'ncurses'
|
6
|
+
|
7
|
+
class Configuration
|
8
|
+
class << self
|
9
|
+
def method_missing(method)
|
10
|
+
config[method.to_s]
|
11
|
+
end
|
12
|
+
|
13
|
+
def config
|
14
|
+
@config ||= YAML.load(File.open("config.yml"))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Panel < Struct.new(:height, :width, :starty, :startx, :options)
|
20
|
+
def initialize(*args)
|
21
|
+
super
|
22
|
+
@win = Ncurses.newwin(height, width, starty, startx)
|
23
|
+
Ncurses.box(@win, 0, 0)
|
24
|
+
@panel = Ncurses::Panel.new_panel(@win)
|
25
|
+
@strings = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def options
|
29
|
+
super || {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def wrap_lines?
|
33
|
+
!options[:nowrap]
|
34
|
+
end
|
35
|
+
|
36
|
+
def <<(string)
|
37
|
+
if wrap_lines?
|
38
|
+
@strings << string.first(width - 4)
|
39
|
+
else
|
40
|
+
@strings << string
|
41
|
+
end
|
42
|
+
|
43
|
+
Ncurses.werase(@win)
|
44
|
+
|
45
|
+
@strings.each_with_index do |string, i|
|
46
|
+
@win.mvaddstr(i + 1, 2, string)
|
47
|
+
end
|
48
|
+
|
49
|
+
Ncurses.box(@win, 0, 0)
|
50
|
+
|
51
|
+
Ncurses::Panel.update_panels
|
52
|
+
Ncurses.doupdate
|
53
|
+
Ncurses.refresh
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class InputPanel < Panel
|
58
|
+
def <<(string)
|
59
|
+
@strings = []
|
60
|
+
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
def message
|
65
|
+
@strings.first
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_cursor
|
69
|
+
@win.wmove(1, message.size)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Hobostove
|
74
|
+
attr_reader :messages
|
75
|
+
|
76
|
+
def connect
|
77
|
+
@current_message = ""
|
78
|
+
@running = true
|
79
|
+
|
80
|
+
start_ncurses
|
81
|
+
|
82
|
+
load_users
|
83
|
+
transcript
|
84
|
+
|
85
|
+
stream
|
86
|
+
|
87
|
+
main
|
88
|
+
|
89
|
+
stop_ncurses
|
90
|
+
end
|
91
|
+
|
92
|
+
def main
|
93
|
+
while @running && (ch = Ncurses.getch)
|
94
|
+
case ch
|
95
|
+
when 10 # enter
|
96
|
+
speak
|
97
|
+
when 127 # backspace
|
98
|
+
@current_message = @current_message.first(@current_message.size - 1)
|
99
|
+
else
|
100
|
+
@current_message << ch.chr
|
101
|
+
end
|
102
|
+
|
103
|
+
@message_panel << @current_message
|
104
|
+
@message_panel.update_cursor
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def speak
|
109
|
+
if @current_message == "/quit"
|
110
|
+
@running = false
|
111
|
+
return
|
112
|
+
end
|
113
|
+
|
114
|
+
room.speak @current_message
|
115
|
+
@current_message = ""
|
116
|
+
end
|
117
|
+
|
118
|
+
def stream
|
119
|
+
Thread.new do
|
120
|
+
room.listen do |message|
|
121
|
+
if message[:type] = "TextMessage"
|
122
|
+
@messages_panel << "#{message.user.name}: #{message[:body]}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def room
|
129
|
+
@room ||= campfire.find_room_by_name(Configuration.room)
|
130
|
+
end
|
131
|
+
|
132
|
+
def transcript
|
133
|
+
transcript = room.transcript(Date.today)
|
134
|
+
transcript.each do |message|
|
135
|
+
next unless (7.hours.ago..Time.now).cover?(message[:timestamp])
|
136
|
+
if message[:message]
|
137
|
+
@messages_panel << "#{user(message[:user_id])[:name]}: #{message[:message]}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def start_ncurses
|
145
|
+
Ncurses.initscr
|
146
|
+
Ncurses.cbreak
|
147
|
+
Ncurses.noecho
|
148
|
+
|
149
|
+
@users_panel = Panel.new(Ncurses.LINES, 20, 0, Ncurses.COLS - 20)
|
150
|
+
@messages_panel = Panel.new(Ncurses.LINES - 3, Ncurses.COLS - 20, 0, 0, :nowrap => true)
|
151
|
+
@message_panel = InputPanel.new(3, Ncurses.COLS - 20, Ncurses.LINES - 3, 0)
|
152
|
+
|
153
|
+
Ncurses::Panel.update_panels
|
154
|
+
|
155
|
+
Ncurses.move(Ncurses.LINES - 2, 2)
|
156
|
+
|
157
|
+
Ncurses.doupdate
|
158
|
+
Ncurses.refresh
|
159
|
+
end
|
160
|
+
|
161
|
+
def stop_ncurses
|
162
|
+
Ncurses.echo
|
163
|
+
Ncurses.endwin
|
164
|
+
end
|
165
|
+
|
166
|
+
def load_users
|
167
|
+
room.users.each do |user|
|
168
|
+
@users_panel << user["name"]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def user(user_id)
|
173
|
+
@users ||= {}
|
174
|
+
@users[user_id] ||= room.user(user_id)
|
175
|
+
end
|
176
|
+
|
177
|
+
def campfire
|
178
|
+
@campfire ||= Tinder::Campfire.new Configuration.subdomain, :token => Configuration.token
|
179
|
+
end
|
180
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobostove
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Oestrich
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tinder
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ncurses-ruby
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Command line client for campfire
|
63
|
+
email:
|
64
|
+
- eric@oestrich.org
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/hobostove.rb
|
70
|
+
homepage: http://github.com/oestrich/hobostove
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.3.6
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.23
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Command line client for campfire
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|