Permalink
Browse files

add display-message construction

  • Loading branch information...
1 parent 0d38bbb commit 8bb74fa9bfd99283dffedcc56970e331483604d4 @matthijsgroen matthijsgroen committed Oct 4, 2012
Showing with 25 additions and 1 deletion.
  1. +25 −1 lib/guard/notifiers/tmux.rb
@@ -16,7 +16,12 @@ module Tmux
:tmux_environment => 'TMUX',
:success => 'green',
:failed => 'red',
- :default => 'green'
+ :pending => 'yellow',
+ :default => 'green',
+ :timeout => 5,
+ :display_message => false,
+ :message_format => '%s - %s',
+ :line_separator => ' - '
}
# Test if currently running in a Tmux session
@@ -46,6 +51,23 @@ 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 }")
+
+ show_message = options[:display_message] || DEFAULTS[:display_message]
+ display_message(type, title, message, options) if show_message
+ end
+
+ def display_message(type, title, message, options)
+ message_format = options[:message_format] || DEFAULTS[: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 +82,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

0 comments on commit 8bb74fa

Please sign in to comment.