notifaction 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/notifaction.rb +3 -0
- data/lib/notify.rb +141 -0
- data/lib/plugins/workingon.rb +11 -0
- data/lib/style.rb +32 -0
- data/lib/utils.rb +30 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b53a7a52c1365daddea0965161d52cfe29e25cd2
|
4
|
+
data.tar.gz: e85bb77a9f9b89680fb605ae79e0e18907529174
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e6f659236d07d4ba6c1d41c3ddc0f8931aa0f816ff71843112f827ebca2fa11be766db93ce227cbbcc2e2154a45eae708b1a4496b114311a3c6f4f8aed64776
|
7
|
+
data.tar.gz: cbcd4588e31de407dfa9878b9441690569af4c53600d05717e4a901dbb5848872b4b8811ff16f0307d193a6767061d94475a06f7c06bbcfc993f3f9921583f24
|
data/lib/notifaction.rb
ADDED
data/lib/notify.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class Notify
|
4
|
+
# Display a notification bubble
|
5
|
+
def self.bubble(message, title)
|
6
|
+
begin
|
7
|
+
if Utils.os == :macosx
|
8
|
+
if !osx_notification(message, title)
|
9
|
+
raise "No handler found, cannot show bubble notification"
|
10
|
+
end
|
11
|
+
else
|
12
|
+
if !notifysend(message, title)
|
13
|
+
raise "No handler found, cannot show bubble notification"
|
14
|
+
#elsif zenity(message, title)
|
15
|
+
# raise "No handler found, cannot show bubble notification"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rescue Exception => e
|
19
|
+
warning("[self.bubble] #{e.message}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.modal(message, title)
|
24
|
+
begin
|
25
|
+
if Utils.os == :macosx
|
26
|
+
if !osx_modal(message, title)
|
27
|
+
raise "No handler found, cannot show system popup"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue Exception => e
|
31
|
+
warning("[self.bubble] #{e.message}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Prints a pre-formatted error message to the console
|
36
|
+
def self.error(message)
|
37
|
+
message = message.split("\n").join("\n\u2716 ")
|
38
|
+
inline("\u2716 #{message} - #{Utils.formatted_time}", :red)
|
39
|
+
inline("\u2716 Exiting...", :red)
|
40
|
+
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
# Prints a pre-formatted warning message to the console
|
45
|
+
def self.warning(message)
|
46
|
+
message = message.split("\n").join("\n\u2011 ")
|
47
|
+
inline("\u2011 #{message} - #{Utils.formatted_time}", :yellow)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Prints a pre-formatted informational message to the console
|
51
|
+
def self.info(message)
|
52
|
+
inline("#{message} - #{Utils.formatted_time}", :blue)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Prints a pre-formatted secondary informational message to the console
|
56
|
+
def self.sinfo(message)
|
57
|
+
message = message.split("\n").join("\n\u2011 ")
|
58
|
+
inline("\u2011 #{message} - #{Utils.formatted_time}", :cyan)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Prints a pre-formatted success message to the console
|
62
|
+
def self.success(message)
|
63
|
+
message = message.split("\n").join("\n\u2713 ")
|
64
|
+
inline("\u2713 #{message} - #{Utils.formatted_time}", :green)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Prints a pre-formatted unstyled message to the console
|
68
|
+
def self.spit(message)
|
69
|
+
inline(message, :null)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Send status updates to WorkingOn
|
73
|
+
def self.wo(message, print_info_message = false)
|
74
|
+
begin
|
75
|
+
require_relative "plugins/workingon.rb"
|
76
|
+
|
77
|
+
plugin = Plugin::WorkingOn.new
|
78
|
+
plugin.send(message)
|
79
|
+
|
80
|
+
if print_info_message
|
81
|
+
info(message)
|
82
|
+
end
|
83
|
+
rescue Exception => e
|
84
|
+
error("Error notifying WO - #{e.message}", self)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# pretty-print a spacer
|
89
|
+
def self.spacer
|
90
|
+
inline("\u2011 =============", :magenta)
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
# Collate colour and style, build message string in format of
|
95
|
+
# "\e[#{style};#{colour}m#{text}\e[0m"
|
96
|
+
def self.inline(message, colour = nil, style = nil)
|
97
|
+
puts Style.format(message, colour, style)
|
98
|
+
end
|
99
|
+
|
100
|
+
def osx_notification(message, title)
|
101
|
+
begin
|
102
|
+
@response = `osascript -e 'display notification "#{message}" with title "#{title}"'`
|
103
|
+
|
104
|
+
$?.exitstatus == 0
|
105
|
+
rescue SystemExit, Interrupt
|
106
|
+
error("Interrupt caught, exiting", self)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# OSX system modal popup
|
111
|
+
def osx_modal(message, title, icon = :caution)
|
112
|
+
begin
|
113
|
+
@response = `osascript -e 'tell app "System Events" to display dialog "#{message}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'`
|
114
|
+
|
115
|
+
$?.exitstatus == 0
|
116
|
+
rescue SystemExit, Interrupt
|
117
|
+
error("Interrupt caught, exiting", self)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Linux system notification
|
122
|
+
def notifysend(message, title)
|
123
|
+
begin
|
124
|
+
@response = `notify-send "#{title}" "#{message}"`
|
125
|
+
|
126
|
+
$?.exitstatus == 0
|
127
|
+
rescue SystemExit, Interrupt
|
128
|
+
error("Interrupt caught, exiting", self)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def zenity(message, title)
|
133
|
+
begin
|
134
|
+
@response = `echo "message:#{message}" | zenity --notification --listen`
|
135
|
+
|
136
|
+
$?.exitstatus == 0
|
137
|
+
rescue SystemExit, Interrupt
|
138
|
+
error("Interrupt caught, exiting", self)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/style.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Style
|
2
|
+
@map = {
|
3
|
+
:colour => {
|
4
|
+
:red => 31,
|
5
|
+
:green => 32,
|
6
|
+
:yellow => 33,
|
7
|
+
:blue => 34,
|
8
|
+
:magenta => 35,
|
9
|
+
:cyan => 36,
|
10
|
+
:white => 37,
|
11
|
+
:null => 0
|
12
|
+
},
|
13
|
+
:style => {
|
14
|
+
:reset => 0,
|
15
|
+
:bold => 1,
|
16
|
+
:underline => 4,
|
17
|
+
:normal => ""
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
def self.format(message, colour = nil, style = nil)
|
22
|
+
c = @map[:colour][colour.to_sym] if !colour.nil?
|
23
|
+
|
24
|
+
if style.nil?
|
25
|
+
t = 0
|
26
|
+
else
|
27
|
+
t = @map[:style][style.to_sym]
|
28
|
+
end
|
29
|
+
|
30
|
+
"\e[#{t};#{c}m#{message}\e[0m"
|
31
|
+
end
|
32
|
+
end
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "time"
|
2
|
+
require "rbconfig"
|
3
|
+
|
4
|
+
class Utils
|
5
|
+
def self.formatted_time(time = nil)
|
6
|
+
if time.nil?
|
7
|
+
time = Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.os
|
14
|
+
@os ||= (
|
15
|
+
host_os = RbConfig::CONFIG['host_os']
|
16
|
+
case host_os
|
17
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
18
|
+
:windows
|
19
|
+
when /darwin|mac os/
|
20
|
+
:macosx
|
21
|
+
when /linux/
|
22
|
+
:linux
|
23
|
+
when /solaris|bsd/
|
24
|
+
:unix
|
25
|
+
else
|
26
|
+
puts "unknown os: #{host_os.inspect}"
|
27
|
+
end
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notifaction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Priebe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Include terminal and OS notifications in your project
|
14
|
+
email: hello@ryanpriebe.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/notifaction.rb
|
20
|
+
- lib/utils.rb
|
21
|
+
- lib/notify.rb
|
22
|
+
- lib/style.rb
|
23
|
+
- lib/plugins/workingon.rb
|
24
|
+
homepage: http://rubygems.org/gems/notifaction
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.14
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Notification Satisfaction
|
48
|
+
test_files: []
|