Class: Notify
- Inherits:
-
Object
- Object
- Notify
- Defined in:
- lib/notify.rb
Class Method Summary collapse
-
.bubble(message, title) ⇒ Object
Display a notification bubble.
- .configure {|_self| ... } ⇒ Object
-
.error(message) ⇒ Object
Prints a pre-formatted error message to the console.
-
.info(message) ⇒ Object
Prints a pre-formatted informational message to the console.
-
.inline(message, colour = nil, style = nil) ⇒ Object
Collate colour and style, build message string in format of “e[#style;#colourm#texte[0m”.
- .modal(message, title) ⇒ Object
-
.notifysend(message, title) ⇒ Object
Linux system notification.
-
.osx_modal(message, title, icon = :caution) ⇒ Object
OSX system modal popup.
- .osx_notification(message, title) ⇒ Object
-
.plugins=(plugin_config_arr) ⇒ Object
register new plugins.
-
.sinfo(message) ⇒ Object
Prints a pre-formatted secondary informational message to the console.
-
.spacer ⇒ Object
pretty-print a spacer.
-
.spit(message) ⇒ Object
Prints a pre-formatted unstyled message to the console.
-
.success(message) ⇒ Object
Prints a pre-formatted success message to the console.
-
.warning(message) ⇒ Object
Prints a pre-formatted warning message to the console.
-
.workingon(message, print_info_message = false) ⇒ Object
Send status updates to WorkingOn.
- .zenity(message, title) ⇒ Object
Class Method Details
.bubble(message, title) ⇒ Object
Display a notification bubble
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/notify.rb', line 3 def self.bubble(, title) begin if Utils.os == :macosx if !osx_notification(, title) raise "No handler found, cannot show bubble notification" end else if !notifysend(, title) raise "No handler found, cannot show bubble notification" #elsif zenity(message, title) # raise "No handler found, cannot show bubble notification" end end rescue Exception => e warning("[self.bubble] #{e.}") end end |
.configure {|_self| ... } ⇒ Object
89 90 91 |
# File 'lib/notify.rb', line 89 def self.configure yield self if block_given? end |
.error(message) ⇒ Object
Prints a pre-formatted error message to the console
34 35 36 37 38 39 40 |
# File 'lib/notify.rb', line 34 def self.error() = .split("\n").join("\n\u2716 ") inline("\u2716 #{} - #{Utils.formatted_time}", :red) inline("\u2716 Exiting...", :red) exit end |
.info(message) ⇒ Object
Prints a pre-formatted informational message to the console
49 50 51 |
# File 'lib/notify.rb', line 49 def self.info() inline("#{} - #{Utils.formatted_time}", :blue) end |
.inline(message, colour = nil, style = nil) ⇒ Object
Collate colour and style, build message string in format of “e[#style;#colourm#texte[0m”
108 109 110 |
# File 'lib/notify.rb', line 108 def self.inline(, colour = nil, style = nil) puts Style.format(, colour, style) end |
.modal(message, title) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/notify.rb', line 21 def self.modal(, title) begin if Utils.os == :macosx if !osx_modal(, title) raise "No handler found, cannot show system popup" end end rescue Exception => e warning("[self.bubble] #{e.}") end end |
.notifysend(message, title) ⇒ Object
Linux system notification
134 135 136 137 138 139 140 141 142 |
# File 'lib/notify.rb', line 134 def self.notifysend(, title) begin @response = `notify-send "#{title}" "#{}"` $?.exitstatus == 0 rescue SystemExit, Interrupt error("Interrupt caught, exiting") end end |
.osx_modal(message, title, icon = :caution) ⇒ Object
OSX system modal popup
123 124 125 126 127 128 129 130 131 |
# File 'lib/notify.rb', line 123 def self.osx_modal(, title, icon = :caution) begin @response = `osascript -e 'tell app "System Events" to display dialog "#{}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'` $?.exitstatus == 0 rescue SystemExit, Interrupt error("Interrupt caught, exiting") end end |
.osx_notification(message, title) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/notify.rb', line 112 def self.osx_notification(, title) begin @response = `osascript -e 'display notification "#{}" with title "#{title}"'` $?.exitstatus == 0 rescue SystemExit, Interrupt error("Interrupt caught, exiting") end end |
.plugins=(plugin_config_arr) ⇒ Object
register new plugins
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/notify.rb', line 94 def self.plugins=(plugin_config_arr) plugin_config_arr.each do |hash| hash.each_pair do |plugin, key| # include the requested plugin require_relative "plugins/#{plugin.downcase}.rb" instance_variable_set("@#{plugin}_key".to_sym, key) end end end |
.sinfo(message) ⇒ Object
Prints a pre-formatted secondary informational message to the console
54 55 56 57 |
# File 'lib/notify.rb', line 54 def self.sinfo() = .split("\n").join("\n\u2011 ") inline("\u2011 #{} - #{Utils.formatted_time}", :cyan) end |
.spacer ⇒ Object
pretty-print a spacer
85 86 87 |
# File 'lib/notify.rb', line 85 def self.spacer inline("\u2011 =============", :magenta) end |
.spit(message) ⇒ Object
Prints a pre-formatted unstyled message to the console
66 67 68 |
# File 'lib/notify.rb', line 66 def self.spit() inline(, :null) end |
.success(message) ⇒ Object
Prints a pre-formatted success message to the console
60 61 62 63 |
# File 'lib/notify.rb', line 60 def self.success() = .split("\n").join("\n\u2713 ") inline("\u2713 #{} - #{Utils.formatted_time}", :green) end |
.warning(message) ⇒ Object
Prints a pre-formatted warning message to the console
43 44 45 46 |
# File 'lib/notify.rb', line 43 def self.warning() = .split("\n").join("\n\u2011 ") inline("\u2011 #{} - #{Utils.formatted_time}", :yellow) end |
.workingon(message, print_info_message = false) ⇒ Object
Send status updates to WorkingOn
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/notify.rb', line 71 def self.workingon(, = false) begin plugin = Plugin::WorkingOn.new plugin.send() if info() end rescue Exception => e error("Error notifying WO - #{e.}") end end |
.zenity(message, title) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/notify.rb', line 144 def self.zenity(, title) begin @response = `echo "message:#{}" | zenity --notification --listen` $?.exitstatus == 0 rescue SystemExit, Interrupt error("Interrupt caught, exiting") end end |