Sha256: ec031c405b5fedfa5453d7b2c5ecb35af87b0f68200d36e84169754e74e02e3b

Contents?: true

Size: 1.76 KB

Versions: 26

Compression:

Stored size: 1.76 KB

Contents

module Notiffany
  class Notifier
    class Tmux < Base
      # Wraps a notification with it's options
      class Notification
        def initialize(type, options)
          @type = type
          @options = options
          @color = options[type.to_sym] || options[:default]
          @separator = options[:line_separator]
          @message_color = _value_for(:message_color)
          @client = Client.new(options[:display_on_all_clients] ? :all : nil)
        end

        def display_title(title, message)
          title_format = _value_for(:title_format)

          teaser_message = message.split("\n").first
          display_title = format(title_format, title, teaser_message)

          client.title = display_title
        end

        def display_message(title, message)
          message = _message_for(title, message)

          client.display_time = options[:timeout] * 1000
          client.message_fg = message_color
          client.message_bg = color
          client.display_message(message)
        end

        def colorize(locations)
          locations.each do |location|
            client.set(location, color)
          end
        end

        private

        attr_reader :type
        attr_reader :options
        attr_reader :color
        attr_reader :message_color
        attr_reader :client
        attr_reader :separator

        def _value_for(field)
          format = "#{type}_#{field}".to_sym
          default = options["default_#{field}".to_sym]
          options.fetch(format, default)
        end

        def _message_for(title, message)
          message_format = _value_for(:message_format)
          formatted_message = message.split("\n").join(separator)
          format(message_format, title, formatted_message)
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 8 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/tmux/notification.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/notiffany-0.1.1/lib/notiffany/notifier/tmux/notification.rb
notiffany-0.1.3 lib/notiffany/notifier/tmux/notification.rb
notiffany-0.1.2 lib/notiffany/notifier/tmux/notification.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/tmux/notification.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/tmux/notification.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/tmux/notification.rb