-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
executable file
·74 lines (62 loc) · 1.78 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'date'
require 'optparse'
require_relative './calendar.rb'
def read_config(config)
OptionParser.new do |opts|
opts.banner = "Usage: dzen2-calendar [options]"
opts.on("--bg '#0E0D15'", "Set background color") do |color|
config[:color0] = color
end
opts.on("--fg '#DDDDDD'", "Set foreground color") do |color|
config[:color1] = color
end
opts.on("-x 1650", Integer, "X position") do |x|
config[:x] = x
end
opts.on("-y 810", Integer, "Y position") do |y|
config[:y] = y
end
opts.on("-w", "--width 26", Integer, "Set calendar width") do |width|
config[:width] = width
end
opts.on("-s", "--screen 1", Integer, "Set screen on which the calendar is displayed") do |screen|
config[:screen] = screen
end
opts.on("--year 1970", Integer, "Set the displayed year") do |year|
config[:year] = year
end
opts.on("--month 2", Integer, "Set the displayed month") do |month|
config[:month] = month
end
opts.on("--no-toggle", "Determine if a new calendar should be opened after closing the previous one") do
config[:toggle] = false
end
end.parse!
config
end
def open(config)
content = "#{get_header(config)}#{get_body(config)}"
dzen_string = <<END
echo "#{get_title(config)}\n#{content}" | dzen2 \
-title-name "calendar" \
-bg "#{config[:color0]}" \
-fg "#{config[:color1]}" \
-x "#{config[:x]}" \
-y "#{config[:y]}" \
-h 30 \
-l 7 \
-w #{config[:width] * 10} \
-tw #{config[:width] * 10} \
-e "onstart=uncollapse;button3=exit" \
-ta c \
-sa l \
-xs #{config[:screen]} \
-fn mono \
-p &
END
exec(dzen_string)
end
def close
`pkill -f "dzen2 -title-name calendar"`
$?.exitstatus == 0
end