mancurses 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/mancurses +94 -23
  2. data/mancurses.gemspec +1 -1
  3. metadata +3 -3
data/bin/mancurses CHANGED
@@ -8,7 +8,7 @@
8
8
  # Author: rkumar http://github.com/rkumar/mancurses/
9
9
  # Date: 2011-11-09 - 16:59
10
10
  # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
11
- # Last update: 2013-03-08 21:03
11
+ # Last update: 2013-03-09 01:24
12
12
  #
13
13
  # == CHANGES
14
14
  # == TODO
@@ -80,7 +80,7 @@ module RubyCurses
80
80
  @scrollatrows = @height - 3
81
81
  @oldindex = @current_index = 0
82
82
  # column cursor
83
- @ccol = 0
83
+ @curpos = 0
84
84
  @repaint_required = true
85
85
  end
86
86
  def rowcol #:nodoc:
@@ -296,23 +296,63 @@ module RubyCurses
296
296
  bind_key([?\C-x, ?<], :scroll_left)
297
297
  bind_key(?\M-l, :scroll_right)
298
298
  bind_key(?\M-h, :scroll_left)
299
- #bind_key([?\C-x, ?\C-s], :saveas)
300
- #bind_key(?r) { getstr("Enter a word: ") }
301
- #bind_key(?m, :disp_menu)
299
+ bind_key(?L, :bottom_of_window)
300
+ bind_key(?M, :middle_of_window)
301
+ bind_key(?H, :top_of_window)
302
+ bind_key(?w, :forward_word)
302
303
  end
303
304
 
304
305
  # goto first line of file
305
306
  def goto_start
306
307
  @oldindex = @current_index
307
- @current_index = @ccol = 0
308
- @pcol = @prow = 0
308
+ $multiplier ||= 0
309
+ if $multiplier > 0
310
+ goto_line $multiplier
311
+ return
312
+ end
313
+ @current_index = 0
314
+ @curpos = @pcol = @prow = 0
315
+ @prow = 0
316
+ $multiplier = 0
309
317
  end
310
318
 
311
319
  # goto last line of file
312
320
  def goto_end
313
321
  @oldindex = @current_index
322
+ $multiplier ||= 0
323
+ if $multiplier > 0
324
+ goto_line $multiplier
325
+ return
326
+ end
314
327
  @current_index = @content_rows-1
315
328
  @prow = @current_index - @scrollatrows
329
+ $multiplier = 0
330
+ end
331
+ def goto_line line
332
+ ## we may need to calculate page, zfm style and place at right position for ensure visible
333
+ @current_index = line
334
+ ensure_visible line
335
+ $multiplier = 0
336
+ end
337
+ def top_of_window
338
+ @current_index = @prow
339
+ $multiplier ||= 0
340
+ if $multiplier > 0
341
+ @current_index += $multiplier
342
+ $multiplier = 0
343
+ end
344
+ end
345
+ def bottom_of_window
346
+ @current_index = @prow + @scrollatrows
347
+ $multiplier ||= 0
348
+ if $multiplier > 0
349
+ @current_index -= $multiplier
350
+ $multiplier = 0
351
+ end
352
+ end
353
+ def middle_of_window
354
+ @current_index = @prow + (@scrollatrows/2)
355
+ $multiplier = 0
316
356
  end
317
357
 
318
358
  # move down a line mimicking vim's j key
@@ -335,7 +375,7 @@ module RubyCurses
335
375
  @current_index -= num
336
376
  unless is_visible? @current_index
337
377
  if @prow > @current_index
338
- $status_message.value = "1 #{@prow} > #{@current_index} "
378
+ #$status_message.value = "1 #{@prow} > #{@current_index} "
339
379
  @prow -= 1
340
380
  else
341
381
  end
@@ -425,26 +465,25 @@ module RubyCurses
425
465
  # somehow maxcol going to -33
426
466
  @oldrow = @prow
427
467
  @oldcol = @pcol
428
- #$log.debug "XXX: PAD got #{ch} maxcol = #{@maxcol} cols=#{@cols}, maxpcol = #{maxpcol}"
468
+ $log.debug "XXX: PAD got #{ch} prow = #{@prow}"
429
469
  begin
430
470
  case ch
431
- when key(?H)
432
471
  when key(?l)
433
472
  # TODO take multipler
434
473
  #@pcol += 1
435
- if @ccol < @cols
436
- @ccol += 1
474
+ if @curpos < @cols
475
+ @curpos += 1
437
476
  end
438
477
  when key(?$)
439
478
  #@pcol = @maxcol - 1
440
- @ccol = [@content[@current_index].size, @cols].min
479
+ @curpos = [@content[@current_index].size, @cols].min
441
480
  when key(?h)
442
481
  # TODO take multipler
443
- if @ccol > 0
444
- @ccol -= 1
482
+ if @curpos > 0
483
+ @curpos -= 1
445
484
  end
446
485
  when key(?0)
447
- @ccol = 0
486
+ @curpos = 0
448
487
  when ?0.getbyte(0)..?9.getbyte(0)
449
488
  if ch == ?0.getbyte(0) && $multiplier == 0
450
489
  # copy of C-a - start of line
@@ -462,6 +501,7 @@ module RubyCurses
462
501
  # check for bindings, these cannot override above keys since placed at end
463
502
  begin
464
503
  ret = process_key ch, self
504
+ $multiplier = 0
465
505
  ## If i press C-x > i get an alert from rwidgets which blacks the screen
466
506
  # if i put a padrefresh here it becomes okay but only for one pad,
467
507
  # i still need to do it for all pads.
@@ -522,10 +562,10 @@ module RubyCurses
522
562
  r,c = rowcol
523
563
  @current_index = 0 if @current_index < 0
524
564
  @current_index = @content_rows-1 if @current_index > @content_rows-1
525
- $status_message.value = "visible #{@prow} , #{@current_index} "
565
+ #$status_message.value = "visible #{@prow} , #{@current_index} "
526
566
  unless is_visible? @current_index
527
567
  if @prow > @current_index
528
- $status_message.value = "1 #{@prow} > #{@current_index} "
568
+ #$status_message.value = "1 #{@prow} > #{@current_index} "
529
569
  @prow -= 1
530
570
  else
531
571
  end
@@ -537,8 +577,8 @@ module RubyCurses
537
577
  @crow = r if @crow < r
538
578
  # 2 depends on whetehr suppressborders
539
579
  @crow = @row + @height -2 if @crow >= r + @height -2
540
- setrowcol @crow, @ccol+c
541
- lastcurpos @crow, @ccol+c
580
+ setrowcol @crow, @curpos+c
581
+ lastcurpos @crow, @curpos+c
542
582
  if @oldrow != @prow || @oldcol != @pcol
543
583
  @repaint_required = true
544
584
  end
@@ -575,7 +615,7 @@ module RubyCurses
575
615
 
576
616
  @oldindex = @current_index
577
617
  @current_index = ix[0]
578
- @ccol = ix[1]
618
+ @curpos = ix[1]
579
619
  ensure_visible
580
620
  end
581
621
  ##
@@ -587,7 +627,7 @@ module RubyCurses
587
627
  return unless ix
588
628
  @oldindex = @current_index
589
629
  @current_index = ix[0]
590
- @ccol = ix[1]
630
+ @curpos = ix[1]
591
631
  ensure_visible
592
632
  end
593
633
 
@@ -615,11 +655,41 @@ module RubyCurses
615
655
  # TODO - need to check if its at end and then reduce scroll at rows,
616
656
  # @param current_index (default if not given)
617
657
  #
618
- def ensure_visible row = @current_line
658
+ def ensure_visible row = @current_index
619
659
  unless is_visible? row
620
660
  @prow = @current_index
621
661
  end
622
662
  end
663
+ def forward_word
664
+ $multiplier = 1 if !$multiplier || $multiplier == 0
665
+ line = @current_index
666
+ buff = @content[line].to_s
667
+ return unless buff
668
+ pos = @curpos || 0 # list does not have curpos
669
+ $multiplier.times {
670
+ found = buff.index(/[[:punct:][:space:]]\w/, pos)
671
+ if !found
672
+ # if not found, we've lost a counter
673
+ if line+1 < @content.length
674
+ line += 1
675
+ else
676
+ return
677
+ end
678
+ pos = 0
679
+ else
680
+ pos = found + 1
681
+ end
682
+ $log.debug " forward_word: pos #{pos} line #{line} buff: #{buff}"
683
+ }
684
+ $multiplier = 0
685
+ @current_index = line
686
+ @curpos = pos
687
+ ensure_visible
688
+ #@buffer = @list[@current_index].to_s
689
+ #set_form_row
690
+ #set_form_col pos
691
+ @repaint_required = true
692
+ end
623
693
 
624
694
  end # class textpad
625
695
 
@@ -714,6 +784,7 @@ if __FILE__ == $PROGRAM_NAME
714
784
  p = RubyCurses::TextPad.new @form, :height => FFI::NCurses.LINES-1, :width => w, :row => 0, :col => 0 , :title => " mancurses ", :name => "textpad"
715
785
  #fn = "m.m"
716
786
  #text = File.open(fn,"r").readlines
787
+ ENV["MANWIDTH"] = w.to_s
717
788
  file = `man man`
718
789
  text = convert_man_to_ansi(file)
719
790
  #File.open("t.t", 'w') { |file| file.write(text.join "\n") }
data/mancurses.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "mancurses"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.3"
8
8
  spec.authors = ["Rahul Kumar"]
9
9
  spec.email = ["sentinel1879@gmail.com"]
10
10
  spec.description = %q{view manpages in an ncurses window and navigate with vim bindings}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mancurses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: 2382845020894572024
92
+ hash: 3321737941092796151
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: 2382845020894572024
101
+ hash: 3321737941092796151
102
102
  requirements: []
103
103
  rubyforge_project:
104
104
  rubygems_version: 1.8.25