talks 0.2.0 → 0.3.0

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.
@@ -0,0 +1 @@
1
+ coverage/
@@ -8,4 +8,4 @@ rvm:
8
8
  - rbx-18mode
9
9
  - rbx-19mode
10
10
  # uncomment this line if your project needs to run something other than `rake`:
11
- # script: bundle exec rspec spec
11
+ script: rake
data/README.md CHANGED
@@ -1,21 +1,33 @@
1
1
  # Talks gem — now your ruby and command-line tools can talk with you
2
2
 
3
- ### This is beta now.
4
-
5
3
  ### Build Status ![http://travis-ci.org/ruby-talks/talks](https://secure.travis-ci.org/ruby-talks/talks.png)
6
4
 
7
5
  If you want to HEAR some response from your code or command-line tools, just use this gem.
8
6
 
9
- You can use this gem on MacOS X and on other linux/unix systems with installed [espeak](http://espeak.sourceforge.net).
7
+ You can use this gem on MacOS X and on other linux/unix systems with [espeak](http://espeak.sourceforge.net) installed.
8
+
9
+ Now with support for notifiers through [notifier](https://github.com/fnando/notifier) gem!
10
+ Check the notifier's
11
+ [README](https://github.com/fnando/notifier/blob/master/README.rdoc) and
12
+ find what notifier you want to use - there is support for every OS!
13
+
14
+ I added in all sections of this readme notes about usage notifier
15
+ functionality.
10
16
 
11
17
  Sponsored by Evil Martians <http://evilmartians.com>
12
18
 
13
19
  ## Why?
14
20
 
15
- For example - some really long task and you just get some coffee, read book or surf internet
16
- and you want to know when this task will ends, but don't want to check your mac or terminal each minute -
17
- you can just add small hook in the end of your code and when it will ends - you will hear it with voice that you
18
- choose from MacOS X `say` function collection or from `espeak` collection.
21
+ ### Example
22
+
23
+ You're running some really long task and you leave the desk to drink some coffee, read a book or surf the internet
24
+ and you want to be notified that the task has finished its execution. You don't want to check your machine each minute. With this gem
25
+ you can just add a little hook at the end of your code and when the execution ends - you will hear it in voice
26
+ that you have chosen from MacOS X `say` function collection or from `espeak` collection.
27
+
28
+ Now if you forgot power on you sound on machine you can always see
29
+ notifications by notifiers like Growl, Kdialog, Knotify, etc. Full list of notifiers is
30
+ [here](https://github.com/fnando/notifier/blob/master/README.rdoc).
19
31
 
20
32
  You can find some examples of `talks` usage in organization [ruby-talks](https://github.com/ruby-talks):
21
33
 
@@ -25,10 +37,12 @@ You can find some examples of `talks` usage in organization [ruby-talks](https:/
25
37
 
26
38
  ## How?
27
39
 
28
- On MacOS X this gem just using native MacOS X `say` command line tool.
29
- On linix/unix this gem using espeak speech synthesis.
40
+ On MacOS X this gem is just using the native MacOS X `say` command line tool.
41
+ On linix/unix this gem is using espeak speech synthesis.
42
+
43
+ For notifications this gem uses [notifier](https://github.com/fnando/notifier/blob/master/README.rdoc) gem.
30
44
 
31
- ### In all examples below I used MacOS X voice types. For espeak you can read section [Using talks with espeak](https://github.com/ruby-talks/talks#using-talks-with-espeak)
45
+ ### In all examples below I've used MacOS X voice types. For espeak you can read section [Using talks with espeak](https://github.com/ruby-talks/talks#using-talks-with-espeak)
32
46
 
33
47
  ### Configuration
34
48
 
@@ -38,6 +52,7 @@ You can configure default voices and messages for `talks` with `~/.talksrc` file
38
52
  ```yml
39
53
  default_voice: 'whisper'
40
54
  engine: 'say'
55
+ notifier: 'off' # if this option passed - you will not receive notifications at all
41
56
  voices:
42
57
  info: 'pipe'
43
58
  messages:
@@ -45,8 +60,9 @@ messages:
45
60
  warn: 'WE GONNA DIE!!!'
46
61
  ```
47
62
 
48
- The same you can do in your code dynamicly through Talks.config instance.
49
- You can configure now only default voice for `say` method and voices and messages for 4 types of talks: `info, warn, success, error`
63
+ You can also do it in your code dynamically through Talks.config instance.
64
+
65
+ You can configure only the default voice for `say` method and voices and messages for 4 types of talks: `info, warn, success, error`
50
66
 
51
67
  For command-line commands you can configure default voices and hook messages:
52
68
 
@@ -56,6 +72,9 @@ bundle:
56
72
  voice: 'vicki'
57
73
  before_message: 'Bundler again will do all right'
58
74
  after_message: "Bundler's job is done here"
75
+ before_notify: 'This will go to notification before `before_message`'
76
+ after_notify: 'This will go to notification after `after_message`'
77
+ # notifier: 'off' # this option will turn off notifications for this command
59
78
  ```
60
79
 
61
80
  You can create your own default preferences for each command-line tool which you want to run with `talks` or `talking` command in front:
@@ -65,7 +84,10 @@ You can create your own default preferences for each command-line tool which you
65
84
  ls:
66
85
  voice: 'bad'
67
86
  before_message: 'Now we will see what in the directory'
68
- after_message: ''
87
+ after_message: '.'
88
+ before_notify: 'This will go to notification before `before_message`'
89
+ after_notify: 'This will go to notification after `after_message`'
90
+ # notifier: 'off' # this option will turn off notifications for this command
69
91
  cap:
70
92
  ...
71
93
  vim:
@@ -84,13 +106,20 @@ $ talking bundle install
84
106
  ```
85
107
 
86
108
  After that `talks` will wrap execution of this command with voice messages. By default messages will be like 'command_name task started/ended'.
87
- You can preconfigure messages in your `~/.talksrc` file or you can send options right in talking command:
109
+ You can preconfigure messages in your `~/.talksrc` file or you can send options right in the talking command:
88
110
 
89
111
  ```bash
90
112
  $ talking -v agnes -bm 'We gonna die!' -am 'Not sure if we can hear that' rm -rf ./
91
113
  # the same
92
114
  $ talking --voice agnes --before-message 'We...' --after-message 'Not...' rm -rf ./
93
115
  ```
116
+ The same with notifications:
117
+
118
+ ```bash
119
+ $ talking -v agnes -bn 'We gonna die!' -an 'Not sure if we can hear that' rm -rf ./
120
+ # the same
121
+ $ talking --voice agnes --before-notify 'We...' --after-notify 'Not...' rm -rf ./
122
+ ```
94
123
 
95
124
  ### Using talks in your code
96
125
 
@@ -110,16 +139,17 @@ Talks.info 'This is info'
110
139
  # Talks.warn 'Some text'
111
140
  # Talks.success 'Some text'
112
141
  # Talks.error 'Some text'
142
+ Talks.notify 'This will be shown to you by your notifier'
113
143
  ```
114
144
 
115
- `Talks.say` can be customized with type of message and voice by adding options to executing this method:
145
+ `Talks.say` can be customized with type of message and voice by adding options to this method parameters:
116
146
 
117
147
  ```ruby
118
148
  Talks.say 'Hello like pipe', voice: 'pipe'
119
149
  Talks.say 'Hello like error', type: :error # the same as using Talks.error
120
150
  ```
121
151
 
122
- All voices which I found in manual for `say`:
152
+ All voices which I've found in `say` manual:
123
153
  ```ruby
124
154
  VOICES = %w(
125
155
  agnes albert alex bad bahh bells boing bruce bubbles cellos
@@ -130,16 +160,16 @@ VOICES = %w(
130
160
 
131
161
  ### Using talks with espeak
132
162
 
133
- You can configure your `talks` usage even on MacOS X for using [espeak](http://espeak.sourceforge.net):
163
+ You can configure your `talks` engine even to tell MacOS X to use [espeak](http://espeak.sourceforge.net):
134
164
 
135
165
  `~/.talksrc`
136
166
  ```yml
137
167
  engine: 'espeak'
138
168
  ```
139
169
 
140
- Otherwise `talks` will set engine by default to `say` on MacOS X and to `espeak` on all other OS if command `which espeak` returns something than empty string.
170
+ Otherwise `talks` will set engine by default. It will be set to `say` on MacOS X and to `espeak` on all other OS-es if command `which espeak` returns non-empty string.
141
171
 
142
- For espeak you have different set of voices and many languages (which this gem not support yet). Voices for espeak:
172
+ You can even configure your language in espeak (this gem still doesn't support different languages). Voices for espeak:
143
173
 
144
174
  ```ruby
145
175
  Talks.voices[:espeak]
@@ -152,7 +182,7 @@ Talks.voices[:espeak]
152
182
 
153
183
  ## Who?
154
184
 
155
- I did it by myself
185
+ I did it myself.
156
186
 
157
187
  ### Contributors
158
188
 
@@ -160,11 +190,15 @@ I did it by myself
160
190
 
161
191
  ### A lot of thanks
162
192
 
163
- * @aderyabin - idea of extended customization of talks is his.
193
+ * @kossnocorp - for idea with notifiers.
194
+
195
+ * @shime - for grammar fixes in readme and better explanation of my idea.
196
+
197
+ * @aderyabin - extended customization of talks is his idea.
164
198
 
165
- * @brainopia - bro helps me with any my idea. He adviced me to do command line tool talks.
199
+ * @brainopia - bro helps me with any idea of mine. He advised me to do command line tool talks.
166
200
 
167
- You can help me with this fun gem and I'll gladly add you here, or above
201
+ You can help me with this fun gem and I'll gladly add you here, or above.
168
202
 
169
203
  ## License
170
204
 
@@ -7,4 +7,4 @@ require 'talks'
7
7
  command = (ARGV.first == 'talks' ? ARGV[1..-1] : ARGV)
8
8
  command_with_hooks = Talks.add_hooks command
9
9
 
10
- exec command_with_hooks
10
+ Talks.execute command_with_hooks
@@ -1,8 +1,9 @@
1
1
  require File.expand_path('../talks/configuration.rb', __FILE__)
2
2
  require File.expand_path('../talks/hooks.rb', __FILE__)
3
+ require 'notifier'
3
4
 
4
5
  module Talks
5
- class << self
6
+ extend self
6
7
 
7
8
  VOICES = {
8
9
  :say => %w(
@@ -35,10 +36,21 @@ module Talks
35
36
  when 'espeak'
36
37
  `espeak -v #{say_voice(type, options)} '#{message}'`
37
38
  else
38
- abort "Don't know that engine now: #{config.engine}"
39
+ abort "Undefined engine: #{config.engine}"
39
40
  end
40
41
  end
41
42
 
43
+ def notify(message, options = {})
44
+ Notifier.notify message: message, title: 'Talks', image: ''
45
+ end
46
+
47
+ def execute(command)
48
+ before_notify, command, after_notify = command
49
+ Talks.notify before_notify if before_notify
50
+ system command
51
+ Talks.notify after_notify if after_notify
52
+ end
53
+
42
54
  def add_hooks(command)
43
55
  Talks::Hooks.create command
44
56
  end
@@ -62,7 +74,6 @@ module Talks
62
74
  end
63
75
  end
64
76
 
65
- end
66
77
  end
67
78
 
68
79
  require File.expand_path('../talks/runner.rb', __FILE__)
@@ -11,10 +11,10 @@ module Talks
11
11
  :error => 'bad'
12
12
  },
13
13
  :espeak => {
14
- :info => 'english',
15
- :warn => 'english',
16
- :success => 'english',
17
- :error => 'english'
14
+ :info => 'en+f3',
15
+ :warn => 'en+m1',
16
+ :success => 'en+f3',
17
+ :error => 'en+m3'
18
18
  }
19
19
  }
20
20
 
@@ -25,7 +25,7 @@ module Talks
25
25
  :error => 'Error'
26
26
  }
27
27
 
28
- attr_accessor :voices, :messages, :default_voice, :options, :engine
28
+ attr_accessor :voices, :messages, :default_voice, :options, :engine, :notifier
29
29
 
30
30
  def initialize(opts)
31
31
  @options = symbolize_hash_keys(opts)
@@ -59,6 +59,19 @@ module Talks
59
59
  options[command][(position == :before ? :before_message : :after_message)]
60
60
  end
61
61
 
62
+ def notifier_for(command_name)
63
+ command = command_name.to_sym
64
+ (options[:notifier] != 'off') &&
65
+ options[command] &&
66
+ (options[command][:notifier] != 'off')
67
+ end
68
+
69
+ def notify_message_for(command_name, position = :after)
70
+ command = command_name.to_sym
71
+ options[command] &&
72
+ options[command][(position == :before ? :before_notify : :after_notify)]
73
+ end
74
+
62
75
  def voice_for(command_name)
63
76
  command = command_name.to_sym
64
77
  options[command] &&
@@ -84,7 +97,7 @@ module Talks
84
97
  elsif !(`which espeak`.empty?)
85
98
  'espeak'
86
99
  else
87
- abort 'Now talks can work only on MacOS X, you can help with support other OS'
100
+ abort 'Talks is supported on Mac OS X and linux only, but you can help with support for other OSes'
88
101
  end
89
102
  end
90
103
 
@@ -6,13 +6,14 @@ module Talks
6
6
  engine = Talks.config.engine
7
7
  options, args = shift_options(args.dup)
8
8
  command_name = command args
9
- voice, before_message, after_message = parse options, command_name
9
+ voice, before_message, after_message, before_notify, after_notify = \
10
+ parse options, command_name
10
11
 
11
12
  before_hook = hook(engine, voice, before_message)
12
13
  after_hook = hook(engine, voice, after_message)
13
14
  command = args.join(' ')
14
15
 
15
- [before_hook, command, after_hook].join('; ')
16
+ [before_notify, [before_hook, command, after_hook].join('; '), after_notify]
16
17
  end
17
18
 
18
19
  private
@@ -50,7 +51,21 @@ module Talks
50
51
  Talks.config.message_for(command_name, :after) ||
51
52
  Talks.config.default_message_for(command_name, :after)
52
53
 
53
- [voice, before_message, after_message]
54
+ before_notify = Talks.config.notifier_for(command_name) &&
55
+ (
56
+ options['-bn'] || options['--before-notify'] ||
57
+ Talks.config.notify_message_for(command_name, :before) ||
58
+ Talks.config.default_message_for(command_name, :before)
59
+ )
60
+
61
+ after_notify = Talks.config.notifier_for(command_name) &&
62
+ (
63
+ options['-an'] || options['--after-notify'] ||
64
+ Talks.config.notify_message_for(command_name, :after) ||
65
+ Talks.config.default_message_for(command_name, :after)
66
+ )
67
+
68
+ [voice, before_message, after_message, before_notify, after_notify]
54
69
  end
55
70
 
56
71
  def hook(engine, voice, message)
@@ -1,3 +1,3 @@
1
1
  module Talks
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,6 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  OPTS_INITFILE = 'spec/test_data/talksrc'
2
5
  require 'talks'
3
6
 
7
+ def talk_command
8
+ Talks.config.engine
9
+ end
10
+
4
11
  describe Talks do
5
12
 
6
13
  it 'should have default methods' do
@@ -25,7 +32,8 @@ describe Talks do
25
32
  end
26
33
 
27
34
  it 'should return voice for type' do
28
- Talks.config.voice(:info).should == 'vicki'
35
+ Talks.config.voice(:info).should == 'vicki' if talk_command == 'say'
36
+ Talks.config.voice(:info).should == 'en+f3' if talk_command == 'espeak'
29
37
  end
30
38
 
31
39
  it 'should return message for type' do
@@ -51,24 +59,24 @@ describe Talks do
51
59
  context 'hooks' do
52
60
 
53
61
  it 'should create hooks for any command by default' do
54
- Talks.add_hooks(['ls']).should == "say -v agnes 'ls task started'; ls; say -v agnes 'ls task ended'"
62
+ Talks.add_hooks(['ls']).should == "#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'ls task ended'"
55
63
  end
56
64
 
57
65
  it 'should create preconfigured hooks for command from .talksrc' do
58
- Talks.add_hooks(['bundle']).should == "say -v bad 'Bundle before message'; bundle; say -v bad 'Bundle after message'"
66
+ Talks.add_hooks(['bundle']).should == "#{talk_command} -v bad 'Bundle before message'; bundle; #{talk_command} -v bad 'Bundle after message'"
59
67
  end
60
68
 
61
69
  it 'should change voice if option sended' do
62
- Talks.add_hooks(['-v', 'vicki', 'ls']).should == "say -v vicki 'ls task started'; ls; say -v vicki 'ls task ended'"
70
+ Talks.add_hooks(['-v', 'vicki', 'ls']).should == "#{talk_command} -v vicki 'ls task started'; ls; #{talk_command} -v vicki 'ls task ended'"
63
71
  end
64
72
 
65
73
  it 'should change messages if option sended' do
66
- Talks.add_hooks(['-bm', 'test', 'ls']).should == "say -v agnes 'test'; ls; say -v agnes 'ls task ended'"
67
- Talks.add_hooks(['-am', 'test', 'ls']).should == "say -v agnes 'ls task started'; ls; say -v agnes 'test'"
74
+ Talks.add_hooks(['-bm', 'test', 'ls']).should == "#{talk_command} -v agnes 'test'; ls; #{talk_command} -v agnes 'ls task ended'"
75
+ Talks.add_hooks(['-am', 'test', 'ls']).should == "#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'test'"
68
76
  end
69
77
 
70
78
  it 'should create hooks for command inside `bundle exec` by default' do
71
- Talks.add_hooks(['bundle', 'exec', 'ls']).should == "say -v agnes 'ls task started'; bundle exec ls; say -v agnes 'ls task ended'"
79
+ Talks.add_hooks(['bundle', 'exec', 'ls']).should == "#{talk_command} -v agnes 'ls task started'; bundle exec ls; #{talk_command} -v agnes 'ls task ended'"
72
80
  end
73
81
 
74
82
  end
@@ -14,6 +14,11 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "talks"
16
16
 
17
+ s.add_dependency("notifier")
18
+
19
+ s.add_development_dependency("rspec")
20
+ s.add_development_dependency("simplecov")
21
+
17
22
  s.files = `git ls-files`.split("\n")
18
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-26 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: notifier
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: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
14
62
  description: This gem can be used for wraping command-lines with `talks` command or
15
63
  for adding hooks in ruby code which would tell you something
16
64
  email:
@@ -21,6 +69,7 @@ executables:
21
69
  extensions: []
22
70
  extra_rdoc_files: []
23
71
  files:
72
+ - .gitignore
24
73
  - .travis.yml
25
74
  - CHANGELOG.md
26
75
  - Gemfile