ohac-ricalv 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ricalv.rb +28 -5
- metadata +1 -1
data/lib/ricalv.rb
CHANGED
@@ -31,6 +31,10 @@ class Date
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def escseq(str = '')
|
35
|
+
"\x1b[#{str}m"
|
36
|
+
end
|
37
|
+
|
34
38
|
WEEKTABLE = { 'SU' => 7, 'MO' => 1, 'TU' => 2,
|
35
39
|
'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6 }
|
36
40
|
KEYS = [ 'FREQ', 'BYDAY', 'BYMONTH', 'WKST', 'UNTIL', 'INTERVAL' ]
|
@@ -58,7 +62,8 @@ icss = icss.map { |fn|
|
|
58
62
|
when /http:\/\//
|
59
63
|
FileUtils.mkdir_p(CACHEDIR)
|
60
64
|
d = CACHEDIR + '/' + Digest::MD5.hexdigest(fn)
|
61
|
-
|
65
|
+
expire = File.exist?(d) && (File.mtime(d).to_i + 10 * 60) # 10 min
|
66
|
+
`wget -q -O #{d} #{fn}` if !expire || Time.now.to_i > expire
|
62
67
|
d
|
63
68
|
else
|
64
69
|
HOME + '/' + fn
|
@@ -69,12 +74,14 @@ calss = icss.map { |fn|
|
|
69
74
|
File.open(fn) { |f| Icalendar.parse(f) }
|
70
75
|
}
|
71
76
|
|
77
|
+
colors = [ '31', '32', '33', '35', '36', '37' ] * 10 # TODO
|
72
78
|
items = calss.map { |cals|
|
79
|
+
color = colors.shift
|
73
80
|
cals.map { |cal|
|
74
81
|
cal.events.map { |event|
|
75
82
|
lines = []
|
76
83
|
d = Date.parse(event.dtstart.to_s)
|
77
|
-
lines << { :d => d, :e => event }
|
84
|
+
lines << { :d => d, :e => event, :color => color }
|
78
85
|
rrule = event.properties["rrule"]
|
79
86
|
if rrule
|
80
87
|
rulehash = {}
|
@@ -120,7 +127,7 @@ items = calss.map { |cals|
|
|
120
127
|
d += 1 while d.cwday != week
|
121
128
|
d += (day - 1) * 7
|
122
129
|
end
|
123
|
-
lines << { :d => d, :e => event }
|
130
|
+
lines << { :d => d, :e => event, :color => color }
|
124
131
|
d = d.next_year
|
125
132
|
d = Date.new(d.year, mon, 1) if mon
|
126
133
|
end
|
@@ -131,11 +138,27 @@ items = calss.map { |cals|
|
|
131
138
|
}
|
132
139
|
}.flatten
|
133
140
|
|
134
|
-
items << {:d => today, :t => '*** TODAY ***'}
|
141
|
+
items << {:d => today, :t => '*** TODAY ***', :color => '32' }
|
135
142
|
|
136
143
|
items = items.select{|v|
|
137
144
|
d = v[:d]
|
138
145
|
d.year == today.year && d.month == today.month
|
139
146
|
}
|
140
|
-
|
147
|
+
keys = items.map{|v| v[:d]}.uniq
|
148
|
+
items = keys.inject({}){|h,v| h[v] = items.select{|x| x[:d] == v}; h}
|
149
|
+
items = items.map{|k,v|
|
150
|
+
s = v.map{|x|
|
151
|
+
escseq(x[:color]) + (x[:t] || x[:e].summary) + escseq()
|
152
|
+
}.join(', ')
|
153
|
+
w = WEEKTOSTR[k.wday]
|
154
|
+
wc = case k.wday
|
155
|
+
when 0; '31'
|
156
|
+
when 6; '36'
|
157
|
+
end
|
158
|
+
w = escseq(wc) + w + escseq() if wc
|
159
|
+
"#{k}(#{w}) #{s}"
|
160
|
+
}
|
161
|
+
|
162
|
+
print escseq()
|
141
163
|
items.sort.each{|v| puts v}
|
164
|
+
print escseq()
|