Permalink
Browse files

Merge branch 'master' into interactor/pry

Conflicts:
	Gemfile
  • Loading branch information...
2 parents 0411a58 + 7d263a0 commit 415c9b4970aff3b25e98c4b5dcb57187a41942fb @netzpirat netzpirat committed Oct 18, 2012
View
@@ -1,3 +1,11 @@
+## Master
+
+- [#342][] Add notifier for displying result in terminal title. ([@tomas-zemres][])
+- [#343][] Customize tmux notifier status location. ([@nickmabry][])
+- Adds ability to override default options in emacs notifier. ([@d1][])
+- Use `$stderr` instead of `STDERR` to allow redirection. ([@netzpirat][])
+- [#334][] Extend `:tmux` notifier with use of `tmux display-message` and options to configure them. ([@matthijsgroen][])
+
## 1.4.0 - 26 September, 2012
- [#331][] Add tmux notifier. ([@royvandewater][])
@@ -600,6 +608,9 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[#317]: https://github.com/guard/guard/issues/317
[#324]: https://github.com/guard/guard/issues/324
[#331]: https://github.com/guard/guard/issues/331
+[#334]: https://github.com/guard/guard/issues/334
+[#342]: https://github.com/guard/guard/issues/342
+[#343]: https://github.com/guard/guard/issues/343
[@Gazer]: https://github.com/Gazer
[@Maher4Ever]: https://github.com/Maher4Ever
[@alandipert]: https://github.com/alandipert
@@ -611,6 +622,7 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@capotej]: https://github.com/capotej
[@ches]: https://github.com/ches
[@chrisberkhout]: https://github.com/chrisberkhout
+[@d1]: https://github.com/d1
[@dgutov]: https://github.com/dgutov
[@dnagir]: https://github.com/dnagir
[@docwhat]: https://github.com/docwhat
@@ -639,12 +651,14 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@madtrick]: https://github.com/madtrick
[@maio]: https://github.com/maio
[@mattgreen]: https://github.com/mattgreen
+[@matthijsgroen]: https://github.com/matthijsgroen
[@mcmire]: https://github.com/mcmire
[@mislav]: https://github.com/mislav
[@monocle]: https://github.com/monocle
[@mordaroso]: https://github.com/mordaroso
[@nestegg]: https://github.com/nestegg
[@netzpirat]: https://github.com/netzpirat
+[@nickmabry]: https://github.com/nickmabry
[@nicksieger]: https://github.com/nicksieger
[@niklas]: https://github.com/niklas
[@oliamb]: https://github.com/oliamb
@@ -667,11 +681,12 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@thibaudgg]: https://github.com/thibaudgg
[@thierryhenrio]: https://github.com/thierryhenrio
[@tinogomes]: https://github.com/tinogomes
+[@tomas-zemres]: https://github.com/tomas-zemres
[@tpope]: https://github.com/tpope
[@uk-ar]: https://github.com/uk-ar
[@veged]: https://github.com/veged
[@viking]: https://github.com/viking
[@waldo]: https://github.com/waldo
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
-[@zonque]: https://github.com/zonque
+[@zonque]: https://github.com/zonque
View
@@ -6,14 +6,15 @@ File an issue
You can report bugs and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
-**Please don't ask question in the issue tracker**, instead ask them in our
-[Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
+**Please don't ask question in the issue tracker**, instead ask them on at Stack Overflow and use the
+[guard](http://stackoverflow.com/questions/tagged/guard) tag.
Try to figure out where the issue belongs to: Is it an issue with Guard itself or with a Guard plugin you're
using?
When you file a bug, please try to follow these simple rules if applicable:
+* Make sure you've read the README carefully.
* Make sure you run Guard with `bundle exec` first.
* Add debug information to the issue by running Guard with the `--debug` option.
* Add your `Guardfile` and `Gemfile` to the issue.
@@ -37,4 +38,4 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
* Please **do not change** the version number.
For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
-`#guard` (irc.freenode.net).
+`#guard` (irc.freenode.net).
View
@@ -28,7 +28,7 @@ group :development do
end rescue Errno::ENOENT
elsif RbConfig::CONFIG['target_os'] =~ /linux/i
- gem 'libnotify', '~> 0.7.1', :require => false
+ gem 'libnotify', '~> 0.8.0', :require => false
gem 'rb-inotify', :require => false
elsif RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
View
@@ -101,8 +101,7 @@ end
### System notifications
-You can configure Guard to make use of the following system notification libraries, but it's strongly recommended
-to use either Ruby GNTP, Libnotify or Notifu:
+You can configure Guard to make use of the following system notification libraries:
#### Ruby GNTP
@@ -219,13 +218,45 @@ group :development do
end
```
+#### Terminal Title
+
+* Runs in every terminal supporting XTerm escape sequences to set the window title.
+
#### Emacs
* Runs on any platform with Emacs + emacsclient (http://www.emacswiki.org/emacs/EmacsClient)
-### Tmux
+### TMux
+
+* To use TMux notifications, you have to start Guard within a [TMux](http://tmux.sourceforge.net/) session.
+
+The TMux notifier will color the background of the left part of the
+status bar indicating the status of the notifications. Optionally you
+can set `:display_message => true` to display the Guard notification as
+'display-message' notification.
+
+The way these messages are formatted is configurable.
+
+```ruby
+# Guardfile
+notification :tmux,
+ :display_message => true,
+ :timeout => 5, # in seconds
+ :default_message_format => '%s >> %s',
+ # the first %s will show the title, the second the message
+ # Alternately you can also configure *success_message_format*,
+ # *pending_message_format*, *failed_message_format*
+ :line_separator => ' > ', # since we are single line we need a separator
+ :color_location => 'status-left-bg' # to customize which tmux element will change color
+```
+
+The result will be for RSpec using example above
+
+ RSpec >> 15 test, 0 failures > in 0.002 sec
+
+You can use nice powerline chars here if you have that configured.
-* To use Tmux notifications, you have to start Guard within a [tmux](http://tmux.sourceforge.net/) session.
+You can get the message history by using `Ctrl+b ~` (where `Ctrl+b` is your key to activate TMux).
Add Guard plugins
-----------------
View
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'bundler'
s.add_development_dependency 'rspec', '~> 2.11.0'
- s.add_development_dependency 'guard-rspec', '~> 1.2.1'
+ s.add_development_dependency 'guard-rspec', '~> 2.0.0'
s.files = Dir.glob('{bin,images,lib}/**/*') + %w[CHANGELOG.md LICENSE man/guard.1 man/guard.1.html README.md]
s.executable = 'guard'
View
@@ -14,6 +14,7 @@ module Guard
# * rb-notifu
# * emacs
# * Terminal Notifier
+ # * Terminal Title
# * Tmux
#
# Please see the documentation of each notifier for more information about the requirements
@@ -46,6 +47,7 @@ module Notifier
require 'guard/notifiers/rb_notifu'
require 'guard/notifiers/emacs'
require 'guard/notifiers/terminal_notifier'
+ require 'guard/notifiers/terminal_title'
require 'guard/notifiers/tmux'
extend self
@@ -61,6 +63,7 @@ module Notifier
[:notifu, ::Guard::Notifier::Notifu],
[:emacs, ::Guard::Notifier::Emacs],
[:terminal_notifier, ::Guard::Notifier::TerminalNotifier],
+ [:terminal_title, ::Guard::Notifier::TerminalTitle],
[:tmux, ::Guard::Notifier::Tmux]
]
@@ -3,14 +3,6 @@
module Guard
module Notifier
- # Default options for EmacsClient
- DEFAULTS = {
- :client => 'emacsclient',
- :success => 'ForestGreen',
- :failed => 'Firebrick',
- :default => 'Black',
- }
-
# Send a notification to Emacs with emacsclient (http://www.emacswiki.org/emacs/EmacsClient).
#
# @example Add the `:emacs` notifier to your `Guardfile`
@@ -19,6 +11,13 @@ module Notifier
module Emacs
extend self
+ DEFAULTS = {
+ :client => 'emacsclient',
+ :success => 'ForestGreen',
+ :failed => 'Firebrick',
+ :default => 'Black',
+ }
+
# Test if Emacs with running server is available.
#
# @param [Boolean] silent true if no error messages should be shown
@@ -41,28 +40,33 @@ def available?(silent = false)
# @param [String] message the notification message body
# @param [String] image the path to the notification image
# @param [Hash] options additional notification library options
- # @option options [Boolean] sticky make the notification sticky
+ # @option options [String] success the color to use for success notifications (default is 'ForestGreen')
+ # @option options [String] failed the color to use for failure notifications (default is 'Firebrick')
+ # @option options [String] pending the color to use for pending notifications
+ # @option options [String] default the default color to use (default is 'Black')
+ # @option options [String] client the client to use for notification (default is 'emacsclient')
# @option options [String, Integer] priority specify an int or named key (default is 0)
#
def notify(type, title, message, image, options = { })
- system(%(#{ DEFAULTS[:client] } --eval "(set-face-background 'modeline \\"#{ emacs_color(type) }\\")"))
+ options = DEFAULTS.merge options
+ color = emacs_color type, options
+ system(%(#{ options[:client] } --eval "(set-face-background 'modeline \\"#{ color }\\")"))
end
# Get the Emacs color for the notification type.
# You can configure your own color by overwrite the defaults.
#
# @param [String] type the notification type
+ # @param [Hash] options aditional notification options
+ # @option options [String] success the color to use for success notifications (default is 'ForestGreen')
+ # @option options [String] failed the color to use for failure notifications (default is 'Firebrick')
+ # @option options [String] pending the color to use for pending notifications
+ # @option options [String] default the default color to use (default is 'Black')
# @return [String] the name of the emacs color
#
- def emacs_color(type)
- case type
- when 'success'
- DEFAULTS[:success]
- when 'failed'
- DEFAULTS[:failed]
- else
- DEFAULTS[:default]
- end
+ def emacs_color(type, options = {})
+ default = options[:default] || DEFAULTS[:default]
+ options.fetch(type.to_sym, default)
end
end
end
@@ -0,0 +1,35 @@
+# Module for notifying test result to terminal title
+module Guard
+ module Notifier
+ module TerminalTitle
+ extend self
+
+ # Test if the notification library is available.
+ #
+ # @param [Boolean] silent true if no error messages should be shown
+ # @return [Boolean] the availability status
+ #
+ def available?(silent = false)
+ true
+ end
+
+ # Show a system notification.
+ #
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
+ # @param [String] title the notification title
+ # @param [String] message the notification message body
+ # @param [String] image the path to the notification image
+ # @param [Hash] options additional notification library options
+ #
+ def notify(type, title, message, image, options = { })
+ message.sub!(/^\n/, '')
+ message.sub!(/\n.*/m, '')
+ set_terminal_title("[#{title}] #{message}")
+ end
+
+ def set_terminal_title(text)
+ puts "\e]2;#{text}\a"
+ end
+ end
+ end
+end
@@ -3,20 +3,30 @@ module Notifier
# Default options for Tmux
- # Changes the color of the Tmux status bar
+ # Changes the color of the Tmux status bar, and optionally
+ # shows messages in the status bar. (see display_message)
#
# @example Add the `:tmux` notifier to your `Guardfile`
# notification :tmux
#
+ # @example Customize the tmux status colored for notifications
+ # notification :tmux, :color_location => 'status-right-bg'
+ #
module Tmux
extend self
DEFAULTS = {
- :client => 'tmux',
- :tmux_environment => 'TMUX',
- :success => 'green',
- :failed => 'red',
- :default => 'green'
+ :client => 'tmux',
+ :tmux_environment => 'TMUX',
+ :success => 'green',
+ :failed => 'red',
+ :pending => 'yellow',
+ :default => 'green',
+ :timeout => 5,
+ :display_message => false,
+ :default_message_format => '%s - %s',
+ :line_separator => ' - ',
+ :color_location => 'status-left-bg'
}
# Test if currently running in a Tmux session
@@ -45,7 +55,35 @@ def available?(silent = false)
#
def notify(type, title, message, image, options = { })
color = tmux_color type, options
- system("#{ DEFAULTS[:client] } set -g status-left-bg #{ color }")
+ color_location = options[:color_location] || DEFAULTS[:color_location]
+ system("#{ DEFAULTS[:client] } set -g #{color_location} #{ color }")
+
+ show_message = options[:display_message] || DEFAULTS[:display_message]
+ display_message(type, title, message, options) if show_message
+ end
+
+ # Display a message in the statusbar of tmux.
+ #
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
+ # @param [String] title the notification title
+ # @param [String] message the notification message body
+ # @param [Hash] options additional notification library options
+ # @option options [Integer] timeout the amount of seconds to show the message in the statusbar (default is 5)
+ # @option options [String] default_message_format a string to use as formatter. (default is '%s - %s')
+ # @option options [String] line_separator a string to use instead of a line-break. (default is ' - ')
+ #
+ def display_message(type, title, message, options = { })
+ message_format = options["#{ type }_message_format".to_sym] || options[:default_message_format] || DEFAULTS[:default_message_format]
+ display_time = options[:timeout] || DEFAULTS[:timeout]
+ separator = options[:line_separator] || DEFAULTS[:line_separator]
+
+ color = tmux_color type, options
+ formatted_message = message.split("\n").join(separator)
+ display_message = message_format % [title, formatted_message]
+
+ system("#{ DEFAULTS[:client] } set display-time #{ display_time * 1000 }")
+ system("#{ DEFAULTS[:client] } set message-bg #{ color }")
+ system("#{ DEFAULTS[:client] } display-message '#{ display_message }'")
end
# Get the Tmux color for the notification type.
@@ -60,6 +98,8 @@ def tmux_color(type, options = { })
options[:success] || DEFAULTS[:success]
when 'failed'
options[:failed] || DEFAULTS[:failed]
+ when 'pending'
+ options[:pending] || DEFAULTS[:pending]
else
options[:default] || DEFAULTS[:default]
end
Oops, something went wrong.

0 comments on commit 415c9b4

Please sign in to comment.