jota 0.9.0dev4 → 0.9.0dev5

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.
data/lib/clip.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: clip.rb 278 2010-08-08 19:44:10Z dz $
2
+ # $Id: clip.rb 287 2010-11-21 17:31:39Z dz $
3
3
 
4
4
  require 'time'
5
5
  require 'version'
@@ -158,11 +158,14 @@ def text=(str)
158
158
  end
159
159
 
160
160
  # Return modified title for easier readabiliy
161
+ # - empty string is replaced with "..."
162
+ # - tabs are replaced with 4 spaces
161
163
  def title!
162
164
  if @title.strip == "" then
163
165
  return "..."
164
166
  else
165
- return @title
167
+
168
+ return expand_tabs(@title)
166
169
  end
167
170
  end
168
171
 
data/lib/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: helper.rb 257 2010-05-02 19:47:26Z dz $
2
+ # $Id: helper.rb 287 2010-11-21 17:31:39Z dz $
3
3
 
4
4
  def escape_from(str)
5
5
  str.gsub!(/\n(>*)From /,"\n\\1>From ")
@@ -12,17 +12,27 @@ def unescape_from(str)
12
12
  end
13
13
 
14
14
  # expand strftime() time in str and expand %s to 'filename'
15
+
15
16
  def expand_filename(str, dirname, filename)
17
+ # test on $RUBY_PLATFORM is less reliable, can be mswin, mingw, java
18
+ if ENV["HOMEDRIVE"] then
19
+ homedir = ENV["HOMEDRIVE"]+"\\"+ENV["HOMEPATH"]
20
+ else
21
+ homedir = ENV["HOME"]
22
+ end
16
23
  result = Time.now.strftime(str)
17
24
  result = result.gsub(/\$f/,filename)
18
- result = result.gsub(/\$d/,dirname.gsub(/[^a-z0-9._-]+/i,"_"))
19
25
  result = result.gsub(/\$p/,Process::pid.to_s)
20
- result = result.gsub(/\$h/,ENV["HOME"]?ENV["HOME"]:"/") # TODO on windows?
26
+ result = result.gsub(/\$h/,homedir)
21
27
  result = result.gsub(/\$\$/,"$")
22
28
  print_debug "expanding '#{filename}' to '#{result}'"
23
29
  return result
24
30
  end
25
31
 
32
+ def expand_tabs(str)
33
+ return str.gsub(/([^\t]{8})|([^\t]*)\t/n){[$+].pack("A8")}
34
+ end
35
+
26
36
  def debug_file
27
37
  if $debug_file.nil? then
28
38
  begin
data/lib/immediate.rb CHANGED
@@ -13,6 +13,7 @@ def open(filename)
13
13
  begin
14
14
  new_data = ClipArray.open(filename)
15
15
  rescue AppError, SystemCallError => msg
16
+ puts msg
16
17
  return nil
17
18
  end
18
19
 
@@ -53,8 +54,9 @@ end
53
54
 
54
55
  def list
55
56
  print_verbose "immediately listing #{@data.length} clips"
56
- @data.each do | c |
57
- puts c.title! if c.type != :pref
57
+ @data.each_index do | i |
58
+ c = @data[i]
59
+ print "%d\t%s\t%s\n" % [i,c.type,c.title!]
58
60
  end
59
61
  @data.close
60
62
  end
data/lib/jota.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # $Id: jota.rb 278 2010-08-08 19:44:10Z dz $
3
+ # $Id: jota.rb 287 2010-11-21 17:31:39Z dz $
4
4
 
5
5
 
6
6
  require 'getoptlong'
@@ -130,7 +130,8 @@ def parse_args
130
130
  error("Illegal argument '#{opt}'")
131
131
  end
132
132
  end
133
- rescue GetoptLong::InvalidOption
133
+ rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument
134
+ puts "type #{$0} -h for help"
134
135
  exit(EX_USAGE)
135
136
  end
136
137
 
@@ -163,18 +164,23 @@ end
163
164
 
164
165
  def goto_or_fail(object,re)
165
166
  if not object.clip_array.goto_regexp(re) then
167
+ if object.respond_to? :finish then
168
+ object.finish # some objects needs to be tidied up
169
+ end
166
170
  error("Clip with title matching /#{re}/ not found.")
167
171
  end
168
172
  end
169
173
 
170
174
  def open_or_fail(object,filename)
171
175
  if not object.open(filename) then
172
- error("File '#{filename}' not found.")
176
+ # error message should be written in object.open
177
+ error("")
173
178
  end
174
179
  end
175
180
 
176
181
  def start_curses
177
182
  curses = JotaCurses.new
183
+
178
184
  if @filename then
179
185
  open_or_fail(curses,@filename)
180
186
  if @regexp then
@@ -299,7 +305,7 @@ def run
299
305
  else
300
306
  start_gui
301
307
  end
302
-
308
+
303
309
  if $VERBOSE then
304
310
  print_verbose "stopped at #{Time.now}"
305
311
  end
data/lib/jota_curses.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: jota_curses.rb 257 2010-05-02 19:47:26Z dz $
2
+ # $Id: jota_curses.rb 287 2010-11-21 17:31:39Z dz $
3
3
 
4
4
  require "curses"
5
5
  require 'tempfile'
@@ -55,9 +55,10 @@ def initialize
55
55
  @bot_bar = nil
56
56
 
57
57
  @mode = :normal
58
-
59
58
  @editor_running = false
60
59
 
60
+ default_focus
61
+
61
62
  Curses.init_screen
62
63
  Curses.cbreak
63
64
  Curses.noecho
@@ -67,6 +68,7 @@ def initialize
67
68
  @top_win_height = @lines/2
68
69
  set_windows
69
70
 
71
+
70
72
  begin
71
73
  # set SIGgnal handler if terminal WINdow CHanged
72
74
  Signal.trap("SIGWINCH") do
@@ -85,11 +87,16 @@ def initialize
85
87
  end
86
88
  end
87
89
 
90
+ def finish
91
+ Curses.close_screen
92
+ end
93
+
88
94
  def open(filename)
89
95
  begin
90
96
  new_data = ClipArray.open(filename)
91
97
  rescue AppError, SystemCallError => msg
92
- error(msg)
98
+ finish
99
+ puts msg
93
100
  return nil
94
101
  end
95
102
 
@@ -205,18 +212,24 @@ def draw_bars
205
212
  @top_bar.refresh
206
213
 
207
214
  @mid_bar.clear
208
- @mid_bar.addstr("="*@columns)
215
+ @mid_bar.addstr("==")
216
+ if @top_focus then
217
+ @mid_bar.addstr("^^^")
218
+ else
219
+ @mid_bar.addstr("vvv")
220
+ end
221
+ @mid_bar.addstr("="*(@columns-5))
209
222
  @mid_bar.refresh
210
223
 
211
224
  @bot_bar.clear
212
225
  case @mode
213
226
  when :normal
214
- @bot_bar.addstr("Crsr=le/ri/up/dn, e=edit, n=new, d=del, o=open, +/-=resize win, h=help, q=quit")
227
+ @bot_bar.addstr("Crsr=le/ri/up/dn, Tab=focus, e=edit, n=new, d=del, +/-=resize, h=help, q=quit")
215
228
  when :help
216
- @bot_bar.addstr("Crsr=up/dn, +/-=resize win, h/q=quit help")
229
+ @bot_bar.addstr("Crsr=up/dn, Tab=focus, +/-=resize win, h/q=quit help")
217
230
 
218
231
  when :pref
219
- @bot_bar.addstr("Crsr=up/dn, e=edit pref, +/-=resize win, p/q=quit pref")
232
+ @bot_bar.addstr("Crsr=up/dn, Tab=focus, e=edit pref, +/-=resize win, p/q=quit pref")
220
233
  else
221
234
  @bot_bar.addstr("h=help, q=quit")
222
235
  end
@@ -234,7 +247,7 @@ def draw_top_window
234
247
  end
235
248
  if i < @data.length then
236
249
  @top_win.addstr("%s %s\n" %
237
- [marker,@data[i].title![0..@columns-4]])
250
+ [marker, @data[i].title![@left_margin_top..@left_margin_top+@columns-4]])
238
251
  end
239
252
  end
240
253
  end
@@ -244,7 +257,7 @@ end
244
257
  def draw_bottom_window
245
258
  print_debug "drawing text in #{@mode} mode"
246
259
  case @mode
247
- when :normal
260
+ when :normal
248
261
  if @data then
249
262
  text = @data.current.text
250
263
  else
@@ -266,10 +279,9 @@ def draw_bottom_window
266
279
  arr = text.split(/\n/)
267
280
  @bot_win_first.upto @bot_win_first+self.get_bot_win_height-1 do | i |
268
281
  str = arr[i] || ""
269
- # expand tabs to spaces
270
- str.gsub!(/([^\t]{8})|([^\t]*)\t/n){[$+].pack("A8")}
271
- @bot_win.addstr(str[0..@columns-2])
272
- @bot_win.addstr("\n")
282
+ str = expand_tabs(str)
283
+ @bot_win.addstr(str[@left_margin_bot..@left_margin_bot+@columns-2])
284
+ @bot_win.addstr("\n")
273
285
  end
274
286
  result = arr.length
275
287
  @bot_win.refresh
@@ -283,7 +295,8 @@ Jota #{Version::STRING}, (C) #{Version::YEARS} #{Version::AUTHOR} <#{Version::AU
283
295
 
284
296
  Keys:
285
297
  Cursor up/down Scroll up/down
286
- Cursor left/right Show previous/next clip
298
+ Cursor left/right Scroll left/right
299
+ Tab toggle focus between top and bottom window
287
300
  e, ENTER Edit current clip (with $EDITOR)
288
301
  n Append new clip
289
302
  d Delete current clip
@@ -292,7 +305,7 @@ Jota #{Version::STRING}, (C) #{Version::YEARS} #{Version::AUTHOR} <#{Version::AU
292
305
  c Create new file
293
306
  C Close file
294
307
 
295
- + Grow top window
308
+ +,= Grow top window
296
309
  - Shrink top window
297
310
  p Preferences
298
311
  ! Execute command (default $SHELL)
@@ -347,9 +360,11 @@ def app_quit
347
360
  if @data then
348
361
  if really?("confirm_quit","Really quit?") then
349
362
  @data.close
350
- exit
363
+ finish
364
+ exit
351
365
  end
352
366
  else
367
+ finish
353
368
  exit
354
369
  end
355
370
  end
@@ -364,11 +379,18 @@ def call_editor(text)
364
379
  return text
365
380
  end
366
381
 
382
+ def default_focus
383
+ @top_focus = 0
384
+ @left_margin_top = 0
385
+ @left_margin_bot = 0
386
+ end
387
+
367
388
  def handle_key
368
389
  @bot_bar.move(0,79)
369
390
  @bot_bar.refresh
370
391
  # Ruby 1.8: getch return alway a Fixnum
371
- # Ruby 1.9: getch return a String if char is printable (between " " and "~"), Fixnum otherwise
392
+ # Ruby 1.9: getch return a String if char is printable (between " "
393
+ # and "~"), Fixnum otherwise
372
394
  begin
373
395
  ch = @bot_bar.getch
374
396
  ch = 0 if ch.nil?
@@ -381,7 +403,10 @@ def handle_key
381
403
  case ch.chr
382
404
  when "\f" # Ctrl-L
383
405
  redraw_all
384
- when "c"
406
+ when "\t" # Tab
407
+ @top_focus = ! @top_focus
408
+ draw_bars
409
+ when "c"
385
410
  filename = prompt_filename("Create File (?=list): ")
386
411
  if filename and filename != "" then
387
412
  create(filename)
@@ -403,19 +428,23 @@ def handle_key
403
428
  when :normal
404
429
  if @data then
405
430
  @data.current.text = call_editor(@data.current.text)
431
+ default_focus
406
432
  @data.save
407
433
  end
408
434
  when :pref
409
435
  if @data
410
436
  newpref = call_editor(@data.pref.write)
411
437
  @data.pref = Preferences.read(newpref)
438
+ default_focus
412
439
  end
413
440
  end
414
441
  when "h"
415
442
  if @mode == :help then
416
443
  @mode = :normal
444
+ @top_focus = true
417
445
  else
418
446
  @mode = :help
447
+ @top_focus = false
419
448
  end
420
449
  redraw_all
421
450
  @bot_win_first = 0
@@ -424,6 +453,7 @@ def handle_key
424
453
  @data.new
425
454
  @mode = :normal
426
455
  @data.current.text = call_editor(@data.current.text)
456
+ default_focus
427
457
  @data.save
428
458
  end
429
459
  when "o"
@@ -435,8 +465,10 @@ def handle_key
435
465
  when "p"
436
466
  if @mode == :pref then
437
467
  @mode = :normal
468
+ @top_focus = true
438
469
  else
439
470
  @mode = :pref
471
+ @top_focus = false
440
472
  end
441
473
  @bot_win_first = 0
442
474
  redraw_all
@@ -446,7 +478,8 @@ def handle_key
446
478
  else
447
479
  @mode = :normal
448
480
  end
449
- when "+" # grow top window
481
+ when "+","=" # grow top window
482
+ # = is on the same key as + on us-layout
450
483
  if @top_win_height + 5 <= @lines then
451
484
  @top_win_height += 1
452
485
  set_windows
@@ -479,33 +512,52 @@ def handle_key
479
512
  end
480
513
  else
481
514
  case ch
482
- when Curses::Key::LEFT, Curses::Key::RIGHT
483
- if @data then
484
- @data.current.pos = @bot_win_first
485
- if ch == Curses::Key::LEFT then
486
- @data.prev
487
- else
488
- @data.next
489
- end
490
- if @data.current.pos then
491
- @bot_win_first = @data.current.pos
492
- else
493
- @bot_win_first = 0
494
- end
495
- @mode = :normal
496
- end
515
+ when Curses::Key::LEFT
516
+ if @top_focus then
517
+ @left_margin_top -= 1 if @left_margin_top >= 1
518
+ else
519
+ @left_margin_bot -= 1 if @left_margin_bot >= 1
520
+ end
521
+ when Curses::Key::RIGHT
522
+ if @top_focus then
523
+ @left_margin_top += 1
524
+ else
525
+ @left_margin_bot += 1
526
+ end
497
527
  when Curses::Key::UP, Curses::Key::DOWN
498
- if @data then
499
- if ch == Curses::Key::UP then
500
- @bot_win_first -= 1
501
- else
502
- @bot_win_first += 1
503
- end
504
- end
528
+ if @data then
529
+ if @top_focus then
530
+ @data.current.pos = @bot_win_first
531
+ if ch == Curses::Key::UP then
532
+ @data.prev
533
+ else
534
+ @data.next
535
+ end
536
+ if @data.current.pos then
537
+ @bot_win_first = @data.current.pos
538
+ else
539
+ @bot_win_first = 0
540
+ end
541
+ @mode = :normal
542
+ else
543
+ if ch == Curses::Key::UP then
544
+ @bot_win_first -= 1
545
+ else
546
+ @bot_win_first += 1
547
+ end
548
+
549
+ end
550
+ end
505
551
  when Curses::Key::HOME
506
552
  if @data then
507
553
  @bot_win_first = 0
508
554
  end
555
+ when Curses::Key::END
556
+ # XXX
557
+ when Curses::Key::NPAGE
558
+ # XXX
559
+ when Curses::Key::PPAGE
560
+ # XXX
509
561
  end
510
562
  end
511
563
 
@@ -565,8 +617,16 @@ def prompt_filename(str)
565
617
  filename = prompt(str)
566
618
  if filename == "?" then
567
619
  @bot_win.clear
568
- Dir.foreach(".") do | f |
569
- @bot_win.addstr(f+"\t") if f !~ /^\./
620
+ @bot_win.addstr File.expand_path(".")
621
+ @bot_win.addstr(":\n")
622
+ ent = (Dir.entries ".").sort
623
+ ent.each do | f |
624
+ next if f =~ /^\./
625
+ @bot_win.addstr(f)
626
+ if File.directory? f then
627
+ @bot_win.addstr("/")
628
+ end
629
+ @bot_win.addstr("\t")
570
630
  end
571
631
  @bot_win.refresh
572
632
  else
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: version.rb 278 2010-08-08 19:44:10Z dz $
2
+ # $Id: version.rb 285 2010-11-21 09:26:46Z dz $
3
3
 
4
4
 
5
5
  class Version
@@ -29,7 +29,7 @@ MAJOR = 0
29
29
  MINOR = 9
30
30
  PATCH = 0
31
31
  STATE = "dev" # "dev", "beta", "rc", "" (for final)
32
- STATEVER = 4
32
+ STATEVER = 5
33
33
 
34
34
  STRING = "%d.%d.%d%s" % [MAJOR, MINOR,PATCH,Version.state]
35
35
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jota
3
3
  version: !ruby/object:Gem::Version
4
- hash: 470221476
4
+ hash: 470221477
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 0dev4
10
- version: 0.9.0dev4
9
+ - 0dev5
10
+ version: 0.9.0dev5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derik van Zuetphen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 09:11:00 +02:00
18
+ date: 2010-11-22 08:22:25 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -23,7 +23,6 @@ description: ""
23
23
  email: dz@426.ch
24
24
  executables:
25
25
  - jota
26
- - jota.bat
27
26
  extensions: []
28
27
 
29
28
  extra_rdoc_files: