Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add notifier for displying result in terminal title #342

Merged
merged 1 commit into from

2 participants

@tomas-zemres

Signed-off-by: Tomas Pokorny tnt@netsafe.cz

Tomas Pokorny Add notifier for displying result in terminal title
Signed-off-by: Tomas Pokorny <tnt@netsafe.cz>
5da3704
@netzpirat netzpirat merged commit 5da3704 into guard:master

1 check passed

Details default The Travis build passed
@netzpirat
Owner

Great work. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. Add notifier for displying result in terminal title

    Tomas Pokorny authored
    Signed-off-by: Tomas Pokorny <tnt@netsafe.cz>
This page is out of date. Refresh to see the latest.
View
3  lib/guard/notifier.rb
@@ -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]
]
View
35 lib/guard/notifiers/terminal_title.rb
@@ -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
View
1  spec/guard/notifier_spec.rb
@@ -39,6 +39,7 @@
Guard::Notifier.should_receive(:add_notification).with(:notifu, { }, true).and_return false
Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true).and_return false
Guard::Notifier.should_receive(:add_notification).with(:terminal_notifier, { }, true).and_return false
+ Guard::Notifier.should_receive(:add_notification).with(:terminal_title, { }, true).and_return false
Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true).and_return false
Guard::Notifier.turn_on
end
View
43 spec/guard/notifiers/terminal_title_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe Guard::Notifier::TerminalTitle do
+ before(:all) { Object.send(:remove_const, :TerminalTitle) if defined?(::TerminalTitle) }
+
+ before do
+ subject.stub!(:puts)
+
+ class ::TerminalTitle
+ def self.show(options) end
+ end
+ end
+
+ after { Object.send(:remove_const, :TerminalTitle) if defined?(::TerminalTitle) }
+
+ describe '.available?' do
+ context 'without the silent option' do
+ it 'returns true' do
+ true.should be(subject.available?)
+ end
+ end
+ context 'with the silent option' do
+ it 'returns true' do
+ true.should be(subject.available?)
+ end
+ end
+ end
+
+ describe '.notify' do
+ it 'set title + first line of message to terminal title' do
+ subject.should_receive(:set_terminal_title).with("[any title] first line")
+ subject.notify('success', 'any title', "first line\nsecond line\nthird",
+ 'any image', { })
+ end
+ end
+
+ describe '.set_terminal_title' do
+ it 'puts string to display terminal title' do
+ subject.should_receive(:puts).with("\e]2;display this text in title\a")
+ subject.set_terminal_title('display this text in title')
+ end
+ end
+end
Something went wrong with that request. Please try again.