Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into interactor/pry

  • Loading branch information...
commit 4a9f16a4989c29184d9821e90814e8ecf15e83e3 2 parents c07093a + d78289e
@netzpirat netzpirat authored
View
4 lib/guard/cli.rb
@@ -21,13 +21,13 @@ class CLI < Thor
:type => :boolean,
:default => false,
:aliases => '-c',
- :banner => 'Auto clear shell before each change/run_all/reload'
+ :banner => 'Auto clear shell before each action'
method_option :notify,
:type => :boolean,
:default => true,
:aliases => '-n',
- :banner => 'Notifications feature (growl/libnotify)'
+ :banner => 'Notifications feature'
method_option :debug,
:type => :boolean,
View
37 lib/guard/notifiers/tmux.rb
@@ -3,12 +3,15 @@ module Notifier
# Default options for Tmux
- # Changes the color of the Tmux status bar, and optionally
- # shows messages in the status bar. (see display_message)
+ # Changes the color of the Tmux status bar and optionally
+ # shows messages in the status bar.
#
# @example Add the `:tmux` notifier to your `Guardfile`
# notification :tmux
#
+ # @example Enable text messages
+ # notification :tmux, :display_message => true
+ #
# @example Customize the tmux status colored for notifications
# notification :tmux, :color_location => 'status-right-bg'
#
@@ -25,6 +28,7 @@ module Tmux
:timeout => 5,
:display_message => false,
:default_message_format => '%s - %s',
+ :default_message_color => 'white',
:line_separator => ' - ',
:color_location => 'status-left-bg'
}
@@ -43,37 +47,49 @@ def available?(silent = false)
end
end
- # Show a system notification.
+ # Show a system notification. By default, the Tmux notifier only makes use of a color based
+ # notification, changing the background color of the `color_location` to the color defined
+ # in either the `success`, `failed`, `pending` or `default`, depending on the notification type.
+ # If you also want display a text message, you have to enable it explicit by setting `display_message`
+ # to `true`.
#
# @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
- # @option options [Boolean] sticky make the notification sticky
- # @option options [String, Integer] priority specify an int or named key (default is 0)
+ # @option options [String] color_location the location where to draw the color notification
+ # @option options [Boolean] display_message whether to display a message or not
#
def notify(type, title, message, image, options = { })
color = tmux_color type, options
color_location = options[:color_location] || DEFAULTS[:color_location]
- system("#{ DEFAULTS[:client] } set -g #{color_location} #{ color }")
+ 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.
+ # Display a message in the status bar 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 ' - ')
+ # @option options [Integer] timeout the amount of seconds to show the message in the status bar
+ # @option options [String] success_message_format a string to use as formatter for the success message.
+ # @option options [String] failed_message_format a string to use as formatter for the failed message.
+ # @option options [String] pending_message_format a string to use as formatter for the pending message.
+ # @option options [String] default_message_format a string to use as formatter when no format per type is defined.
+ # @option options [String] success_message_color the success notification foreground color name.
+ # @option options [String] failed_message_color the failed notification foreground color name.
+ # @option options [String] pending_message_color the pending notification foreground color name.
+ # @option options [String] default_message_color a notification foreground color to use when no color per type is defined.
+ # @option options [String] line_separator a string to use instead of a line-break.
#
def display_message(type, title, message, options = { })
message_format = options["#{ type }_message_format".to_sym] || options[:default_message_format] || DEFAULTS[:default_message_format]
+ message_color = options["#{ type }_message_color".to_sym] || options[:default_message_color] || DEFAULTS[:default_message_color]
display_time = options[:timeout] || DEFAULTS[:timeout]
separator = options[:line_separator] || DEFAULTS[:line_separator]
@@ -82,6 +98,7 @@ def display_message(type, title, message, options = { })
display_message = message_format % [title, formatted_message]
system("#{ DEFAULTS[:client] } set display-time #{ display_time * 1000 }")
+ system("#{ DEFAULTS[:client] } set message-fg #{ message_color }")
system("#{ DEFAULTS[:client] } set message-bg #{ color }")
system("#{ DEFAULTS[:client] } display-message '#{ display_message }'")
end
View
69 spec/guard/notifiers/tmux_spec.rb
@@ -75,7 +75,7 @@ def self.show(options) end
it 'should set the right tmux status bar color on success when the right status bar is passed in as an option' do
subject.should_receive(:system).with "tmux set -g status-right-bg green"
-
+
subject.notify('success', 'any title', 'any message', 'any image', { :color_location => 'status-right-bg' })
end
@@ -100,34 +100,69 @@ def self.show(options) end
end
it 'sets the display-time' do
- subject.should_receive(:system).with('tmux set display-time 3000').once
+ subject.should_receive(:system).with('tmux set display-time 3000')
subject.display_message 'success', 'any title', 'any message', :timeout => 3
end
- it 'sets the background color' do
- subject.stub :tmux_color => 'blue'
- subject.should_receive(:system).with('tmux set message-bg blue').once
- subject.display_message 'success', 'any title', 'any message'
- end
-
it 'displays the message' do
subject.should_receive(:system).with('tmux display-message \'any title - any message\'').once
subject.display_message 'success', 'any title', 'any message'
end
- it 'formats the message' do
- subject.should_receive(:system).with('tmux display-message \'(any title) -> any message - line two\'').once
- subject.display_message 'success', 'any title', "any message\nline two", :default_message_format => '(%s) -> %s'
+ it 'handles line-breaks' do
+ subject.should_receive(:system).with('tmux display-message \'any title - any message xx line two\'').once
+ subject.display_message 'success', 'any title', "any message\nline two", :line_separator => ' xx '
end
- it 'formats the message based on type' do
- subject.should_receive(:system).with('tmux display-message \'[any title] => any message - line two\'').once
- subject.display_message 'success', 'any title', "any message\nline two", :success_message_format => '[%s] => %s', :default_message_format => '(%s) -> %s'
+ context 'with success message type options' do
+ it 'formats the message' do
+ subject.should_receive(:system).with('tmux display-message \'[any title] => any message - line two\'').once
+ subject.display_message 'success', 'any title', "any message\nline two", :success_message_format => '[%s] => %s', :default_message_format => '(%s) -> %s'
+ end
+
+ it 'sets the foreground color based on the type for success' do
+ subject.should_receive(:system).with('tmux set message-fg green')
+ subject.display_message 'success', 'any title', 'any message', { :success_message_color => 'green' }
+ end
+
+ it 'sets the background color' do
+ subject.should_receive(:system).with('tmux set message-bg blue')
+ subject.display_message 'success', 'any title', 'any message', { :success => :blue }
+ end
end
- it 'handles line-breaks' do
- subject.should_receive(:system).with('tmux display-message \'any title - any message xx line two\'').once
- subject.display_message 'success', 'any title', "any message\nline two", :line_separator => ' xx '
+ context 'with pending message type options' do
+ it 'formats the message' do
+ subject.should_receive(:system).with('tmux display-message \'[any title] === any message - line two\'').once
+ subject.display_message 'pending', 'any title', "any message\nline two", :pending_message_format => '[%s] === %s', :default_message_format => '(%s) -> %s'
+ end
+
+ it 'sets the foreground color' do
+ subject.should_receive(:system).with('tmux set message-fg blue')
+ subject.display_message 'pending', 'any title', 'any message', { :pending_message_color => 'blue' }
+ end
+
+ it 'sets the background color' do
+ subject.should_receive(:system).with('tmux set message-bg white')
+ subject.display_message 'pending', 'any title', 'any message', { :pending => :white }
+ end
+ end
+
+ context 'with failed message type options' do
+ it 'formats the message' do
+ subject.should_receive(:system).with('tmux display-message \'[any title] <=> any message - line two\'').once
+ subject.display_message 'failed', 'any title', "any message\nline two", :failed_message_format => '[%s] <=> %s', :default_message_format => '(%s) -> %s'
+ end
+
+ it 'sets the foreground color' do
+ subject.should_receive(:system).with('tmux set message-fg red')
+ subject.display_message 'failed', 'any title', 'any message', { :failed_message_color => 'red' }
+ end
+
+ it 'sets the background color' do
+ subject.should_receive(:system).with('tmux set message-bg black')
+ subject.display_message 'failed', 'any title', 'any message', { :failed => :black }
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.