class Guard::Notifier::Tmux


notification :tmux, color_location: ‘status-right-bg’
@example Customize the tmux status colored for notifications
notification :tmux, display_message: true
@example Enable text messages
notification :tmux
@example Add the ‘:tmux` notifier to your `Guardfile`
shows messages in the status bar.
Changes the color of the Tmux status bar and optionally

def self._register!(opts)

Returns:
  • (Boolean) - whether or not a TMUX environment is available

Other tags:
    Private: -
def self._register!(opts)
  if _tmux_environment_available?(opts)
    true
  else
    unless opts[:silent]
      ::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.'
    end
    false
  end
end

def self._tmux_environment_available?(opts)

Returns:
  • (Boolean) - whether or not a TMUX environment is available

Other tags:
    Private: -
def self._tmux_environment_available?(opts)
  !ENV[opts.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
end

def self.available?(opts = {})

def self.available?(opts = {})
  super and _register!(opts)
end

def _reset_options_store


Reset the internal Tmux options store defaults.
def _reset_options_store
  @options_stored = false
  @options_store = {
    'status-left-bg'  => nil,
    'status-right-bg' => nil,
    'status-left-fg'  => nil,
    'status-right-fg' => nil,
    'message-bg'      => nil,
    'message-fg'      => nil,
    'display-time'    => nil
  }
end

def _run_client(args)

def _run_client(args)
  system("#{ DEFAULTS[:client] } #{args}")
end

def display_message(type, title, message, opts = {})

Options Hash: (**options)
  • line_separator (String) -- a string to use instead of a
  • default_message_color (String) -- a notification
  • pending_message_color (String) -- the pending notification
  • failed_message_color (String) -- the failed notification
  • success_message_color (String) -- the success notification
  • default_message_format (String) -- a string to use as
  • pending_message_format (String) -- a string to use as
  • failed_message_format (String) -- a string to use as
  • success_message_format (String) -- a string to use as
  • timeout (Integer) -- the amount of seconds to show the

Parameters:
  • options (Hash) -- additional notification library options
  • message (String) -- the notification message body
  • title (String) -- the notification title
  • type (String) -- the notification type. Either 'success',
def display_message(type, title, message, opts = {})
  message_format = opts.fetch("#{ type }_message_format".to_sym, opts.fetch(:default_message_format, DEFAULTS[:default_message_format]))
  message_color = opts.fetch("#{ type }_message_color".to_sym, opts.fetch(:default_message_color, DEFAULTS[:default_message_color]))
  display_time = opts.fetch(:timeout, DEFAULTS[:timeout])
  separator = opts.fetch(:line_separator, DEFAULTS[:line_separator])
  color = tmux_color type, opts
  formatted_message = message.split("\n").join(separator)
  display_message = message_format % [title, formatted_message]
  _run_client "set display-time #{ display_time * 1000 }"
  _run_client "set message-fg #{ message_color }"
  _run_client "set message-bg #{ color }"
  _run_client "display-message '#{ display_message }'"
end

def notify(message, opts = {})

Options Hash: (**opts)
  • display_message (Boolean) -- whether to display a message
  • color_location (String) -- the location where to draw the
  • change_color (Boolean) -- whether to show a color
  • image (String) -- the path to the notification image
  • message (String) -- the notification message body
  • type (String) -- the notification type. Either 'success',

Parameters:
  • opts (Hash) -- additional notification library options
  • title (String) -- the notification title
def notify(message, opts = {})
  super
  opts.delete(:image)
  if opts.fetch(:change_color, DEFAULTS[:change_color])
    color_location = opts.fetch(:color_location, DEFAULTS[:color_location])
    color = tmux_color(opts[:type], opts)
    _run_client "set #{ color_location } #{ color }"
  end
  if opts.fetch(:display_message, DEFAULTS[:display_message])
    display_message(opts.delete(:type).to_s, opts.delete(:title), message, opts)
  end
end

def options_store

def options_store
  @options_store ||= {}
end

def system(args)

def system(args)
  args += " >#{ DEV_NULL } 2>&1" if ENV['GUARD_ENV'] == 'test'
  super
end

def tmux_color(type, opts = {})

Returns:
  • (String) - the name of the emacs color

Parameters:
  • type (String) -- the notification type
def tmux_color(type, opts = {})
  type = type.to_sym
  type = :default unless [:success, :failed, :pending].include?(type)
  opts.fetch(type, DEFAULTS[type])
end

def turn_off


are unset) and unquiet the Tmux output.
if available (existing options are restored, new options
Notification stopping. Restore the previous Tmux state
def turn_off
  if @options_stored
    @options_store.each do |key, value|
      if value
        _run_client "set #{ key } #{ value }"
      else
        _run_client "set -u #{ key }"
      end
    end
    _reset_options_store
  end
  _run_client 'set quiet off'
end

def turn_on


and quiet the Tmux output.
Notification starting, save the current Tmux settings
def turn_on
  unless @options_stored
    _reset_options_store
    `#{ DEFAULTS[:client] } show`.each_line do |line|
      option, _, setting = line.chomp.partition(' ')
      options_store[option] = setting
    end
    @options_stored = true
  end
  _run_client 'set quiet on'
end