cali 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +50 -0
  2. data/VERSION +1 -1
  3. data/lib/cali.rb +43 -15
  4. metadata +6 -6
  5. data/README +0 -32
@@ -0,0 +1,50 @@
1
+ = cali
2
+
3
+ Interactive cal(1) (but the name ical was taken)
4
+
5
+ == Usage
6
+
7
+ gem install cali
8
+ cali
9
+ # interactive session
10
+
11
+ cat > ~/dates <<END
12
+ 2010-09-01 Write a better README for cali
13
+ 2010-09-02 ...
14
+ 2010-09-03 Profit
15
+ END
16
+
17
+ cali -d ~/dates
18
+ # interactive session with calendar entries
19
+
20
+ cat > ~/.calirc <<END
21
+ Cali.config.dates = '~/dates'
22
+ END
23
+
24
+ cali
25
+ # interactive session with calendar entries
26
+
27
+ == Screenshots
28
+
29
+ RUBYLIB=lib ruby -rubygems bin/cali -d README
30
+
31
+ September 2010
32
+ Su Mo Tu We Th Fr Sa
33
+ 1 2 3 4
34
+ 5 6 7 8 9 10 11
35
+ 12 13 14 15 16 17 18
36
+ 19 20 21 22 23 24 25
37
+ 26 27 28 29 30
38
+
39
+ 2010-09-01 Write a better README for cali
40
+
41
+ ( The 1st is highlighted, and the 1st, 2nd, and 3rd are underlined. )
42
+
43
+ == Key bindings
44
+
45
+ [Up/down/left/right] hjkl, Emacs bindings, arrow keys
46
+ [Next/previous month] n/p, page down/page up
47
+ [Next/previous year] }/{
48
+ [Next/previous event] w/b (this navigates between underlined days)
49
+ [Quit] q
50
+ [Refresh] ^L (Ctrl-L)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -18,6 +18,21 @@ require 'date'
18
18
  require 'optparse'
19
19
  require 'ncurses'
20
20
 
21
+ class OpenStruct
22
+ attr_reader :hsh
23
+ def method_missing(method, value = nil)
24
+ method = method.to_s
25
+ if method.match(/^(.*)=$/)
26
+ @hsh[$1] = value
27
+ else
28
+ @hsh[method]
29
+ end
30
+ end
31
+ def initialize
32
+ @hsh = {}
33
+ end
34
+ end
35
+
21
36
  class Cali
22
37
  KEYBINDINGS = {
23
38
  ['q'[0]]=> :quit,
@@ -35,27 +50,32 @@ class Cali
35
50
  }
36
51
 
37
52
  def Cali::run
38
- options = {}
53
+ dotcali = File.expand_path "~/.calirc"
54
+ load dotcali if File.exist? dotcali
55
+
56
+ dates = nil
39
57
  OptionParser.new { |opts|
40
58
  opts.banner = "Usage: cali [-d FILE]"
41
59
  opts.on("-d","--dates FILE","Use FILE for events") {|d|
42
- options[:dates] = d
60
+ Cali.config.dates = d
43
61
  }
44
62
  }.parse!
45
- dotcali = Dir["#{ENV['HOME']}/.calirc.rb"][0]
46
- require dotcali if dotcali
47
- cali=Cali.new(options[:dates])
63
+
64
+ cali=Cali.new
48
65
  cali.run
49
66
  end
50
67
 
51
- def initialize(dates=nil)
52
- preinit_hook
68
+ def Cali::config
69
+ @@config ||= OpenStruct.new
70
+ @@config
71
+ end
72
+
73
+ def initialize
53
74
  @today = Date.today
54
75
  @days = {}
55
- dates ||= @default_dates
56
76
  @dates = {}
57
- if dates
58
- open(dates){|f|
77
+ if Cali.config.dates
78
+ open(File.expand_path(Cali.config.dates)){|f|
59
79
  until f.eof
60
80
  line = f.readline.strip
61
81
  d = line.match(/(\d{4})-(\d{2})-(\d{2})/)
@@ -73,8 +93,8 @@ class Cali
73
93
  @key[kk] = v
74
94
  }
75
95
  }
76
- postinit_hook
77
96
  end
97
+
78
98
  def run
79
99
  begin
80
100
  Ncurses.initscr
@@ -86,6 +106,7 @@ class Cali
86
106
  Ncurses.endwin
87
107
  end
88
108
  end
109
+
89
110
  def mainloop
90
111
  displaycal
91
112
  displayevents
@@ -95,6 +116,7 @@ class Cali
95
116
  end
96
117
  end
97
118
  end
119
+
98
120
  def displaycal
99
121
  Ncurses.clear
100
122
  Ncurses.move(0,0)
@@ -103,6 +125,7 @@ class Cali
103
125
  displaydays
104
126
  Ncurses.refresh
105
127
  end
128
+
106
129
  def displaydays
107
130
  counter = (first - first.wday)
108
131
  before_month = true
@@ -136,6 +159,7 @@ class Cali
136
159
  end
137
160
  Ncurses.move(y,x+1)
138
161
  end
162
+
139
163
  def displayevents
140
164
  displaycal
141
165
  bounce {
@@ -147,11 +171,13 @@ class Cali
147
171
  } if @dates[@today]
148
172
  }
149
173
  end
174
+
150
175
  def bounce (&block)
151
176
  y,x = Ncurses.getcury(Ncurses.stdscr),Ncurses.getcurx(Ncurses.stdscr)
152
177
  yield
153
178
  Ncurses.move(y,x)
154
179
  end
180
+
155
181
  def movecursor(old)
156
182
  if old != @today
157
183
  a = @days[old.day]
@@ -168,6 +194,7 @@ class Cali
168
194
  Ncurses.attroff(Ncurses::A_UNDERLINE) if has_items?(@today)
169
195
  Ncurses.move(a[1],a[0]+1)
170
196
  end
197
+
171
198
  def update(&block)
172
199
  oldtoday = @today.dup
173
200
  yield
@@ -177,6 +204,7 @@ class Cali
177
204
  displaycal
178
205
  end
179
206
  end
207
+
180
208
  def move(to)
181
209
  case to
182
210
  when :quit
@@ -232,6 +260,7 @@ class Cali
232
260
  end
233
261
  displayevents
234
262
  end
263
+
235
264
  def weekdays
236
265
  wds = []
237
266
  counter = (@today - @today.wday)
@@ -244,9 +273,11 @@ class Cali
244
273
  end
245
274
  wds
246
275
  end
276
+
247
277
  def first
248
278
  Date.new(@today.year,@today.month,1)
249
279
  end
280
+
250
281
  def last
251
282
  newlast = @today.dup
252
283
  until newlast.month != @today.month
@@ -255,11 +286,8 @@ class Cali
255
286
  end
256
287
  last
257
288
  end
289
+
258
290
  def has_items?(date=@today)
259
291
  @dates.include?(date)
260
292
  end
261
- def preinit_hook
262
- end
263
- def postinit_hook
264
- end
265
293
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cali
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Adams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-31 00:00:00 +01:00
18
+ date: 2010-09-01 00:00:00 +01:00
19
19
  default_executable: cali
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -39,11 +39,11 @@ executables:
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
- - README
42
+ - README.rdoc
43
43
  files:
44
44
  - .gitignore
45
45
  - LICENCE
46
- - README
46
+ - README.rdoc
47
47
  - Rakefile
48
48
  - VERSION
49
49
  - bin/cali
data/README DELETED
@@ -1,32 +0,0 @@
1
-
2
- cali
3
- ====
4
-
5
- Interactive cal(1) (but the name ical was taken)
6
-
7
- .calirc.rb
8
- ==========
9
-
10
- This file lives in your home directory and is a Ruby script which gets
11
- required if it exists. See examples/dotcalirc.rb for an example.
12
-
13
- dates
14
- =====
15
-
16
- The -d/--dates option takes a filename as an argument. That file should
17
- contain linebreak-separated items containing strings of the form
18
- /\d{4}-\d{2}-\d{2}/.
19
-
20
- I have something similar in my home directory containing items such as:
21
-
22
- 2008-12-21 Start on RE essay, ML revision
23
-
24
- 2009-01-04 The L Word season 6 (final season)
25
-
26
- 2009-01-22 Shop meeting
27
-
28
- It's a very simple diary. Try running:
29
- ruby -rubygems bin/cali -d README
30
-
31
- The above dates should be underlined in the calendar, and pressing the
32
- appropriate key should display the item below the calendar.