hobostove 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/hobostove CHANGED
@@ -2,5 +2,23 @@
2
2
  $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
3
 
4
4
  require 'hobostove'
5
+ require 'gli'
5
6
 
6
- Hobostove.new.connect
7
+ include GLI::App
8
+
9
+ program_desc "A command line Campfire client"
10
+
11
+ desc "Start hobostove"
12
+ command :start do |c|
13
+ c.action do
14
+ if Hobostove::Setup.run_setup?
15
+ Hobostove::Setup.new($stdin, $stdout).run
16
+ end
17
+
18
+ Hobostove::Window.new.connect
19
+ end
20
+ end
21
+
22
+ default_command :start
23
+
24
+ exit run(ARGV)
@@ -0,0 +1,20 @@
1
+ require 'etc'
2
+
3
+ module Hobostove
4
+ class Configuration
5
+ class << self
6
+ def method_missing(method)
7
+ config[method.to_s]
8
+ end
9
+
10
+ def config
11
+ @config ||= YAML.load(File.open(config_file))
12
+ end
13
+
14
+ def config_file
15
+ user = Etc.getlogin
16
+ File.join(Dir.home(user), ".hobostove.yml")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Hobostove
2
+ class InputPanel < Panel
3
+ def <<(string)
4
+ @strings = []
5
+
6
+ super
7
+ end
8
+
9
+ def message
10
+ @strings.first
11
+ end
12
+
13
+ def update_cursor
14
+ Ncurses.move(Ncurses.LINES - 2, message.size + 2)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ module Hobostove
2
+ class Panel < Struct.new(:height, :width, :starty, :startx, :options)
3
+ def initialize(*args)
4
+ super
5
+ @win = Ncurses.newwin(height, width, starty, startx)
6
+ Ncurses.box(@win, 0, 0)
7
+ @panel = Ncurses::Panel.new_panel(@win)
8
+ @strings = []
9
+ end
10
+
11
+ def options
12
+ super || {}
13
+ end
14
+
15
+ def wrap_lines?
16
+ !options[:nowrap]
17
+ end
18
+
19
+ def <<(string)
20
+ if wrap_lines?
21
+ @strings << string.first(width - 4)
22
+ else
23
+ @strings << string
24
+ end
25
+
26
+ Ncurses.werase(@win)
27
+
28
+ @strings.last(height - 2).each_with_index do |string, i|
29
+ @win.mvaddstr(i + 1, 2, string)
30
+ end
31
+
32
+ Ncurses.box(@win, 0, 0)
33
+
34
+ Ncurses::Panel.update_panels
35
+ Ncurses.doupdate
36
+ Ncurses.refresh
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module Hobostove
2
+ class Setup
3
+ def self.run_setup?
4
+ !File.exists?(Hobostove::Configuration.config_file)
5
+ end
6
+
7
+ def initialize(stdin, stdout)
8
+ @stdin = stdin
9
+ @stdout = stdout
10
+ @settings = {}
11
+ end
12
+
13
+ def run
14
+ File.open(Hobostove::Configuration.config_file, "w") do |file|
15
+ @stdout.puts "~/.hobostove.yml not found. Running setup"
16
+ @stdout.puts "Subdomain?"
17
+ @settings["subdomain"] = @stdin.gets.chomp
18
+
19
+ @stdout.puts "Token?"
20
+ @settings["token"] = @stdin.gets.chomp
21
+
22
+ @stdout.puts "Room (full name)?"
23
+ @settings["room"] = @stdin.gets.chomp
24
+
25
+ file.write @settings.to_yaml
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,111 @@
1
+ module Hobostove
2
+ class Window
3
+ attr_reader :messages
4
+
5
+ def connect
6
+ @current_message = ""
7
+ @running = true
8
+ @users = []
9
+ @messages = []
10
+
11
+ start_ncurses
12
+
13
+ load_users
14
+
15
+ stream
16
+
17
+ main
18
+
19
+ stop_ncurses
20
+ end
21
+
22
+ def main
23
+ while @running && (ch = Ncurses.getch)
24
+ case ch
25
+ when 10 # enter
26
+ speak
27
+ when 127 # backspace
28
+ @current_message = @current_message.first(@current_message.size - 1)
29
+ when 9 # tab
30
+ @current_message = "#{@users.find { |user| user =~ /^#@current_message/ }}: "
31
+ else
32
+ @current_message << ch.chr
33
+ end
34
+
35
+ @message_panel << @current_message
36
+ @message_panel.update_cursor
37
+ end
38
+ end
39
+
40
+ def speak
41
+ if @current_message == "/quit"
42
+ @running = false
43
+ return
44
+ end
45
+
46
+ room.speak @current_message
47
+ @current_message = ""
48
+ end
49
+
50
+ def stream
51
+ Thread.new do
52
+ while true do
53
+ transcript = room.transcript(Date.today)
54
+ transcript.each do |message|
55
+ next unless message[:message]
56
+ next if messages.include?(message[:id])
57
+ messages << message[:id]
58
+ message = "#{user(message[:user_id])[:name]}: #{message[:message]}"
59
+ @messages_panel << message
60
+ end
61
+
62
+ sleep 3
63
+ end
64
+ end
65
+ end
66
+
67
+ def room
68
+ @room ||= campfire.find_room_by_name(Configuration.room)
69
+ end
70
+
71
+ private
72
+
73
+ def start_ncurses
74
+ Ncurses.initscr
75
+ Ncurses.cbreak
76
+ Ncurses.noecho
77
+
78
+ @users_panel = Panel.new(Ncurses.LINES, 20, 0, Ncurses.COLS - 20)
79
+ @messages_panel = Panel.new(Ncurses.LINES - 3, Ncurses.COLS - 20, 0, 0, :nowrap => true)
80
+ @message_panel = InputPanel.new(3, Ncurses.COLS - 20, Ncurses.LINES - 3, 0)
81
+
82
+ Ncurses::Panel.update_panels
83
+
84
+ Ncurses.move(Ncurses.LINES - 2, 2)
85
+
86
+ Ncurses.doupdate
87
+ Ncurses.refresh
88
+ end
89
+
90
+ def stop_ncurses
91
+ Ncurses.echo
92
+ Ncurses.endwin
93
+ end
94
+
95
+ def load_users
96
+ room.users.each do |user|
97
+ @users << user["name"]
98
+ @users_panel << user["name"]
99
+ end
100
+ end
101
+
102
+ def user(user_id)
103
+ @users ||= {}
104
+ @users[user_id] ||= room.user(user_id)
105
+ end
106
+
107
+ def campfire
108
+ @campfire ||= Tinder::Campfire.new Configuration.subdomain, :token => Configuration.token
109
+ end
110
+ end
111
+ end
data/lib/hobostove.rb CHANGED
@@ -4,190 +4,9 @@ require 'tinder'
4
4
  require 'active_support/core_ext'
5
5
  require 'ncurses'
6
6
  require 'notify'
7
- require 'etc'
8
7
 
9
- class Configuration
10
- class << self
11
- def method_missing(method)
12
- config[method.to_s]
13
- end
14
-
15
- def config
16
- @config ||= YAML.load(File.open(config_file))
17
- end
18
-
19
- def config_file
20
- user = Etc.getlogin
21
- config_file = File.join(Dir.home(user), ".hobostove.yml")
22
- end
23
- end
24
- end
25
-
26
- class Panel < Struct.new(:height, :width, :starty, :startx, :options)
27
- def initialize(*args)
28
- super
29
- @win = Ncurses.newwin(height, width, starty, startx)
30
- Ncurses.box(@win, 0, 0)
31
- @panel = Ncurses::Panel.new_panel(@win)
32
- @strings = []
33
- end
34
-
35
- def options
36
- super || {}
37
- end
38
-
39
- def wrap_lines?
40
- !options[:nowrap]
41
- end
42
-
43
- def <<(string)
44
- if wrap_lines?
45
- @strings << string.first(width - 4)
46
- else
47
- @strings << string
48
- end
49
-
50
- Ncurses.werase(@win)
51
-
52
- @strings.last(height - 2).each_with_index do |string, i|
53
- @win.mvaddstr(i + 1, 2, string)
54
- end
55
-
56
- Ncurses.box(@win, 0, 0)
57
-
58
- Ncurses::Panel.update_panels
59
- Ncurses.doupdate
60
- Ncurses.refresh
61
- end
62
- end
63
-
64
- class InputPanel < Panel
65
- def <<(string)
66
- @strings = []
67
-
68
- super
69
- end
70
-
71
- def message
72
- @strings.first
73
- end
74
-
75
- def update_cursor
76
- @win.wmove(1, message.size)
77
- end
78
- end
79
-
80
- class Hobostove
81
- attr_reader :messages
82
-
83
- def connect
84
- @current_message = ""
85
- @running = true
86
- @users = []
87
-
88
- start_ncurses
89
-
90
- load_users
91
- transcript
92
-
93
- stream
94
-
95
- main
96
-
97
- stop_ncurses
98
- end
99
-
100
- def main
101
- while @running && (ch = Ncurses.getch)
102
- case ch
103
- when 10 # enter
104
- speak
105
- when 127 # backspace
106
- @current_message = @current_message.first(@current_message.size - 1)
107
- when 9 # tab
108
- @current_message = "#{@users.find { |user| user =~ /^#@current_message/ }}: "
109
- else
110
- @current_message << ch.chr
111
- end
112
-
113
- @message_panel << @current_message
114
- @message_panel.update_cursor
115
- end
116
- end
117
-
118
- def speak
119
- if @current_message == "/quit"
120
- @running = false
121
- return
122
- end
123
-
124
- room.speak @current_message
125
- @current_message = ""
126
- end
127
-
128
- def stream
129
- Thread.new do
130
- room.listen do |message|
131
- if message[:type] = "TextMessage"
132
- message = "#{message.user.name}: #{message[:body]}"
133
- @messages_panel << message
134
- Notify.notify Configuration.room, message
135
- end
136
- end
137
- end
138
- end
139
-
140
- def room
141
- @room ||= campfire.find_room_by_name(Configuration.room)
142
- end
143
-
144
- def transcript
145
- transcript = room.transcript(Date.today)
146
- transcript.each do |message|
147
- next unless (7.hours.ago..Time.now).cover?(message[:timestamp])
148
- if message[:message]
149
- @messages_panel << "#{user(message[:user_id])[:name]}: #{message[:message]}"
150
- end
151
- end
152
- end
153
-
154
- private
155
-
156
- def start_ncurses
157
- Ncurses.initscr
158
- Ncurses.cbreak
159
- Ncurses.noecho
160
-
161
- @users_panel = Panel.new(Ncurses.LINES, 20, 0, Ncurses.COLS - 20)
162
- @messages_panel = Panel.new(Ncurses.LINES - 3, Ncurses.COLS - 20, 0, 0, :nowrap => true)
163
- @message_panel = InputPanel.new(3, Ncurses.COLS - 20, Ncurses.LINES - 3, 0)
164
-
165
- Ncurses::Panel.update_panels
166
-
167
- Ncurses.move(Ncurses.LINES - 2, 2)
168
-
169
- Ncurses.doupdate
170
- Ncurses.refresh
171
- end
172
-
173
- def stop_ncurses
174
- Ncurses.echo
175
- Ncurses.endwin
176
- end
177
-
178
- def load_users
179
- room.users.each do |user|
180
- @users << user["name"]
181
- @users_panel << user["name"]
182
- end
183
- end
184
-
185
- def user(user_id)
186
- @users ||= {}
187
- @users[user_id] ||= room.user(user_id)
188
- end
189
-
190
- def campfire
191
- @campfire ||= Tinder::Campfire.new Configuration.subdomain, :token => Configuration.token
192
- end
193
- end
8
+ require 'hobostove/configuration'
9
+ require 'hobostove/panel'
10
+ require 'hobostove/input_panel'
11
+ require 'hobostove/window'
12
+ require 'hobostove/setup'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobostove
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tinder
@@ -75,6 +75,54 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gli
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: fakefs
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
78
126
  description: Command line client for campfire
79
127
  email:
80
128
  - eric@oestrich.org
@@ -83,6 +131,11 @@ executables:
83
131
  extensions: []
84
132
  extra_rdoc_files: []
85
133
  files:
134
+ - lib/hobostove/configuration.rb
135
+ - lib/hobostove/input_panel.rb
136
+ - lib/hobostove/panel.rb
137
+ - lib/hobostove/setup.rb
138
+ - lib/hobostove/window.rb
86
139
  - lib/hobostove.rb
87
140
  - bin/hobostove
88
141
  homepage: http://github.com/oestrich/hobostove