rbcurse 1.4.0 → 1.4.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/NOTES +68 -0
  2. data/README.markdown +73 -330
  3. data/TODO2.txt +2 -2
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +8 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +1 -24
  8. data/examples/appdirtree.rb +1 -1
  9. data/examples/appemail.rb +8 -14
  10. data/examples/appemaillb.rb +2 -2
  11. data/examples/appgcompose.rb +7 -5
  12. data/examples/common/file.rb +40 -0
  13. data/examples/{rmail.rb → common/rmail.rb} +0 -0
  14. data/examples/data/README.markdown +9 -0
  15. data/examples/data/brew.txt +38 -0
  16. data/examples/data/color.2 +37 -0
  17. data/examples/data/gemlist.txt +60 -0
  18. data/examples/data/lotr.txt +12 -0
  19. data/examples/data/ports.txt +136 -0
  20. data/examples/data/tasks.txt +27 -0
  21. data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
  22. data/examples/data/unix1.txt +21 -0
  23. data/examples/data/unix2.txt +11 -0
  24. data/examples/dbdemo.rb +49 -14
  25. data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
  26. data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
  27. data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
  28. data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
  29. data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
  30. data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
  31. data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
  32. data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
  33. data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
  34. data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
  35. data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
  36. data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
  37. data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
  38. data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
  39. data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
  40. data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
  41. data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
  42. data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
  43. data/examples/dirtree.rb +17 -7
  44. data/examples/experimental/resultsetdemo.rb +280 -0
  45. data/examples/experimental/testmform.rb +35 -0
  46. data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
  47. data/examples/experimental/teststackflow.rb +111 -0
  48. data/examples/menu1.rb +1 -0
  49. data/examples/multispl.rb +4 -4
  50. data/examples/newmessagebox.rb +130 -0
  51. data/examples/newtabbedwindow.rb +100 -0
  52. data/examples/newtesttabp.rb +0 -3
  53. data/examples/qdfilechooser.rb +0 -3
  54. data/examples/rfe.rb +134 -18
  55. data/examples/rfe_renderer.rb +48 -2
  56. data/examples/sqlc.rb +2 -1
  57. data/examples/sqlm.rb +0 -2
  58. data/examples/table1.rb +1 -7
  59. data/examples/term2.rb +4 -1
  60. data/examples/test1.rb +0 -5
  61. data/examples/test2.rb +42 -31
  62. data/examples/testapp2.rb +8 -1
  63. data/examples/testchars.rb +0 -4
  64. data/examples/testcombo.rb +5 -9
  65. data/examples/testkeypress.rb +0 -3
  66. data/examples/testmenu.rb +0 -4
  67. data/examples/testmulticomp.rb +3 -5
  68. data/examples/testmulticontainer.rb +94 -0
  69. data/examples/testtable.rb +0 -5
  70. data/examples/testtabp.rb +16 -18
  71. data/examples/testtodo.rb +1 -5
  72. data/examples/testwsshortcuts.rb +64 -0
  73. data/examples/testwsshortcuts2.rb +126 -0
  74. data/examples/viewtodo.rb +1 -4
  75. data/lib/rbcurse.rb +1 -1
  76. data/lib/rbcurse/app.rb +92 -69
  77. data/lib/rbcurse/applicationheader.rb +46 -6
  78. data/lib/rbcurse/celleditor.rb +1 -9
  79. data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
  80. data/lib/rbcurse/common/ansiparser.rb +117 -0
  81. data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
  82. data/lib/rbcurse/common/basestack.rb +407 -0
  83. data/lib/rbcurse/common/bordertitle.rb +41 -0
  84. data/lib/rbcurse/common/chunk.rb +177 -0
  85. data/lib/rbcurse/common/colorparser.rb +71 -0
  86. data/lib/rbcurse/common/keydefs.rb +30 -0
  87. data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
  88. data/lib/rbcurse/deprecated/README.markdown +12 -0
  89. data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
  90. data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
  91. data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
  92. data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
  93. data/lib/rbcurse/experimental/README.markdown +14 -0
  94. data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
  95. data/lib/rbcurse/experimental/stackflow.rb +478 -0
  96. data/lib/rbcurse/extras/bottomline.rb +85 -16
  97. data/lib/rbcurse/extras/box.rb +58 -0
  98. data/lib/rbcurse/extras/directorylist.rb +1 -1
  99. data/lib/rbcurse/extras/horizlist.rb +203 -0
  100. data/lib/rbcurse/extras/listselectable.rb +8 -0
  101. data/lib/rbcurse/extras/multiform.rb +330 -0
  102. data/lib/rbcurse/extras/multilinelabel.rb +142 -0
  103. data/lib/rbcurse/extras/newmessagebox.rb +328 -0
  104. data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
  105. data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
  106. data/lib/rbcurse/extras/padreader.rb +189 -0
  107. data/lib/rbcurse/extras/rcomboedit.rb +256 -0
  108. data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
  109. data/lib/rbcurse/extras/statusline.rb +44 -6
  110. data/lib/rbcurse/extras/tabularwidget.rb +141 -104
  111. data/lib/rbcurse/extras/textpad.rb +516 -0
  112. data/lib/rbcurse/extras/viewer.rb +2 -0
  113. data/lib/rbcurse/io.rb +120 -3
  114. data/lib/rbcurse/listcellrenderer.rb +2 -1
  115. data/lib/rbcurse/listkeys.rb +1 -1
  116. data/lib/rbcurse/listscrollable.rb +72 -7
  117. data/lib/rbcurse/rbasiclistbox.rb +64 -12
  118. data/lib/rbcurse/rchangeevent.rb +0 -1
  119. data/lib/rbcurse/rcombo.rb +54 -59
  120. data/lib/rbcurse/rcommandwindow.rb +46 -10
  121. data/lib/rbcurse/rcontainer.rb +415 -0
  122. data/lib/rbcurse/rdialogs.rb +242 -165
  123. data/lib/rbcurse/rinputdataevent.rb +0 -1
  124. data/lib/rbcurse/rlistbox.rb +19 -9
  125. data/lib/rbcurse/rmessagebox.rb +1 -5
  126. data/lib/rbcurse/rmulticontainer.rb +64 -61
  127. data/lib/rbcurse/rmultitextview.rb +0 -2
  128. data/lib/rbcurse/rpopupmenu.rb +0 -2
  129. data/lib/rbcurse/rscrollform.rb +61 -12
  130. data/lib/rbcurse/rtabbedpane.rb +89 -73
  131. data/lib/rbcurse/rtabbedwindow.rb +53 -211
  132. data/lib/rbcurse/rtable.rb +0 -2
  133. data/lib/rbcurse/rtextarea.rb +14 -14
  134. data/lib/rbcurse/rtextview.rb +165 -50
  135. data/lib/rbcurse/rvimsplit.rb +15 -12
  136. data/lib/rbcurse/rwidget.rb +404 -150
  137. data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
  138. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
  139. data/lib/ver/ncurses.rb +1 -9
  140. data/lib/ver/rpad.rb +375 -0
  141. data/lib/ver/window.rb +262 -440
  142. metadata +73 -31
@@ -1,8 +1,5 @@
1
1
  # this is a test program, tests out tabbed panes. type F1 to exit
2
2
  #
3
- #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
4
- require 'rubygems'
5
- #require 'ncurses' # FFI
6
3
  require 'logger'
7
4
  require 'rbcurse'
8
5
  #require 'rbcurse/newtabbedpane'
@@ -1,8 +1,5 @@
1
1
  # this is a test program, tests out messageboxes. type F1 to exit
2
2
  # a quick dirty file chooser in 2 lines of code.
3
- #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
4
- require 'rubygems'
5
- #require 'ncurses' # FFI
6
3
  require 'logger'
7
4
  require 'ver/ncurses'
8
5
  require 'ver/window'
data/examples/rfe.rb CHANGED
@@ -49,6 +49,7 @@ class FileExplorer
49
49
  @filter_pattern = '*'
50
50
  @prev_dirs=[]
51
51
  @inside_block = false
52
+ $entry_count = 0 # just for show... may not be accurate after deletes etc
52
53
 
53
54
  end
54
55
  def title str
@@ -80,6 +81,7 @@ class FileExplorer
80
81
  end
81
82
  end
82
83
  def goto_previous_dir
84
+ #alert "Previous dirs contain #{@prev_dirs} "
83
85
  d = @prev_dirs.pop
84
86
  if !d.nil? and d == @wdir
85
87
  d = @prev_dirs.pop
@@ -94,6 +96,7 @@ class FileExplorer
94
96
  end
95
97
  def rescan
96
98
  flist = @dir.entries
99
+ $entry_count = flist.size # just for show... may not be accurate after deletes etc
97
100
  flist.shift
98
101
  #populate @entries
99
102
  populate flist
@@ -110,6 +113,7 @@ class FileExplorer
110
113
  #list.list_data_model.insert 0, *fl
111
114
  list.list_data_model.insert 0, *flist
112
115
  list.set_form_row
116
+ #$entry_count = list.size # just for show... may not be accurate after deletes etc
113
117
  end
114
118
  def sort key, reverse=false
115
119
  # remove parent before sorting, keep at top
@@ -227,6 +231,7 @@ class FileExplorer
227
231
  # flist << format_string(f, stat)
228
232
  #}
229
233
  @entries = fl
234
+ $entry_count = @entries.size
230
235
  title = pwd()
231
236
  @wdir = title
232
237
  rfe = self
@@ -242,6 +247,7 @@ class FileExplorer
242
247
  title wdir
243
248
  #title_attrib 'reverse'
244
249
  cell_renderer RfeRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => rfe, "display_length"=> wid-2}
250
+ KEY_ROW_SELECTOR 0 # C-space since space used for preview
245
251
  end
246
252
  @list = lista
247
253
  lista.bind(:ENTER) {|l| @rfe.current_list(self); l.title_attrib 'reverse'; }
@@ -266,6 +272,7 @@ class FileExplorer
266
272
  end
267
273
  def filepath ix=current_index()
268
274
  f = filename(ix)
275
+ return unless f
269
276
  if f[0,1]=='/'
270
277
  f
271
278
  else
@@ -479,6 +486,8 @@ class RFe
479
486
  fp = @current_list.filepath
480
487
  content = get_contents(fp)
481
488
  rescue => err
489
+ $log.debug err.to_s
490
+ $log.debug(err.backtrace.join("\n"))
482
491
  alert err.to_s
483
492
  return
484
493
  end
@@ -565,6 +574,10 @@ class RFe
565
574
  when 'x'
566
575
  str= "exec #{fp}"
567
576
  exec_popup fp
577
+ when 'p'
578
+ page fp
579
+ when 'q'
580
+ qlmanage fp
568
581
  end
569
582
  end
570
583
  def opt_dir c
@@ -639,7 +652,53 @@ class RFe
639
652
  end
640
653
  def edit fp=@current_list.filepath
641
654
  $log.debug " edit #{fp}"
642
- shell_out "/opt/local/bin/vim #{fp}"
655
+ editor = ENV['EDITOR'] || 'vi'
656
+ vimp = %x[which #{editor}].chomp
657
+ shell_out "#{vimp} #{fp}"
658
+ end
659
+
660
+ # TODO we need to move these to some common file so differnt programs and demos
661
+ # can use them on pressing space or enter.
662
+ def page fp=@current_list.filepath
663
+ ft=%x[file #{fp}]
664
+ if ft.index("text")
665
+ pager = ENV['PAGER'] || 'less'
666
+ vimp = %x[which #{pager}].chomp
667
+ shell_out "#{vimp} #{fp}"
668
+ elsif ft.index(/zip/i)
669
+ shell_out "tar tvf #{fp} | less"
670
+ elsif ft.index(/directory/i)
671
+ shell_out "ls -lh #{fp} | less"
672
+ else
673
+ alert "#{fp} is not text, not paging "
674
+ #use_on_file "als", fp # only zip or archive
675
+ end
676
+ end
677
+ def qlmanage fp=@current_list.filepath
678
+ begin
679
+ a=%x[which qlmanage]
680
+ if a != ""
681
+ cmd="qlmanage -p #{@current_list.filepath} 2>/dev/null"
682
+ %x[#{cmd}]
683
+ else
684
+ alert "qlmanage not present on your system. Trying pager"
685
+ page fp
686
+ end
687
+ rescue Interrupt
688
+ rescue => err
689
+ alert err.to_s
690
+ end
691
+ end
692
+ # also if calling program gives output but does not stop
693
+ # or take control, then nothing will show up
694
+ def use_on_file prog, args, fp=@current_list.filepath
695
+ vimp = %x[which #{prog}].chomp
696
+ if vimp != ""
697
+ alert "using #{prog} "
698
+ shell_out "#{vimp} #{args } #{fp}"
699
+ else
700
+ alert "could not locate #{prog} "
701
+ end
643
702
  end
644
703
  def stopping?
645
704
  @stopping
@@ -688,7 +747,7 @@ class RFe
688
747
  while((ch = @window.getchar()) != ?\C-c.getbyte(0) )
689
748
  if ch < 33 || ch > 126
690
749
  Ncurses.beep
691
- elsif "cmdsuvrex".index(ch.chr) == nil
750
+ elsif "cmdsuvrexpq".index(ch.chr) == nil
692
751
  Ncurses.beep
693
752
  else
694
753
  opt_file ch.chr
@@ -717,12 +776,11 @@ class RFe
717
776
  @form.bind_key(127){
718
777
  @current_list.goto_previous_dir
719
778
  }
779
+ # form gives this to list which consumes it for selection.
780
+ # need to bind to list's LIST_SELECTION_EVENT
720
781
  @form.bind_key(32){
721
- begin
722
- cmd="qlmanage -p #{@current_list.filepath} 2>/dev/null"
723
- %x[#{cmd}]
724
- rescue Interrupt
725
- end
782
+ fp = @current_list.filepath
783
+ page fp
726
784
  }
727
785
  @form.bind_key(FFI::NCurses::KEY_F3){
728
786
  begin
@@ -733,17 +791,30 @@ class RFe
733
791
  }
734
792
  @form.bind_key(FFI::NCurses::KEY_F1){
735
793
  #Io.view(["this is some help text","hello there"])
794
+ color0 = get_color($promptcolor, 'black','green')
795
+ color1 = get_color($reversecolor, 'green','black')
796
+ color2 = get_color($reversecolor, 'magenta','black')
736
797
  arr = []
737
- arr << " FILE BROWSER HELP "
798
+ #arr << " FILE BROWSER HELP "
799
+ arr << [color0," FILE BROWSER HELP ", FFI::NCurses::A_NORMAL]
738
800
  arr << " "
739
- arr << " <tab> - switch between windows"
740
- arr << " <enter> - open dir"
741
- arr << " F3 - view file/dir/zip contents (toggle) "
742
- arr << " F4 - edit file content"
743
- arr << " <char> - first file starting with <char>"
801
+ arr << [[color1," <tab> ",nil],[color2, "- switch between windows", nil]]
802
+ arr << [[color1," <enter> ",nil],[color2, "- open dir", nil]]
803
+ arr << [[color1," F3 ",nil],[color2, "- view file/dir/zip contents (toggle) ", nil]]
804
+ arr << [[color1," F4 ",nil],[color2, "- edit file content", nil]]
805
+ arr << [[color1," <char> ", nil],[color2, "first file starting with <char>",nil]]
806
+ #arr << " VIM MODE "
807
+ arr << [color0," VIM MODE ", FFI::NCurses::A_NORMAL]
808
+ arr << [[color1," M",nil],[color2, "-v - Vim like bindings for navigation (toggle)", nil]]
809
+ arr << " jk gg G up down motion, C-n C-p, Alt-0, Alt-9 "
810
+ arr << [[color1," p or Space ",nil],[color2, "- use pager on current file", nil]]
811
+ arr << [[color1," q ",nil],[color2, "- use qlmanage on file ",nil],[$promptcolor, " (OSX)", nil]]
812
+ arr << [[color1," f<char> ",nil],[color2, "- first file starting with <char>", nil]]
813
+
744
814
  arr << " "
745
815
  arr << " < > ^ V - move help window "
746
816
  arr << " "
817
+ # next line does not work due to chunks
747
818
  w = arr.max_by(&:length).length
748
819
  #arr = ["this is some help text","hello there"]
749
820
 
@@ -754,7 +825,8 @@ class RFe
754
825
  #t.color = :black
755
826
  #t.bgcolor = :white
756
827
  # or
757
- t.attr = :reverse
828
+ #t.attr = :reverse
829
+ t.attr = :normal
758
830
  #t.bind_key(KEY_F1){ alert "closing up!"; throw :close }
759
831
  # just for kicks move window around
760
832
  t.bind_key('<'){ f = t.form.window; c = f.left - 1; f.hide; f.mvwin(f.top, c); f.show;
@@ -789,6 +861,13 @@ class RFe
789
861
  @form.bind_key(FFI::NCurses::KEY_F8){
790
862
  system_popup()
791
863
  }
864
+ # will work if you are in vim mode
865
+ @form.bind_key(?p){
866
+ page
867
+ }
868
+ @form.bind_key(?q){
869
+ qlmanage
870
+ }
792
871
  # will no longer come here. list event has to be used
793
872
  #@form.bind_key(?\C-m){ # listbox has eaten it up
794
873
  @lista.list.bind(:PRESS){
@@ -803,7 +882,11 @@ class RFe
803
882
  @current_list.change_dir dir
804
883
  end
805
884
  }
885
+ gw = get_color($reversecolor, 'green', 'black')
886
+ bw = get_color($datacolor, 'blue', 'black')
806
887
  @klp = RubyCurses::KeyLabelPrinter.new @form, get_key_labels
888
+ @klp.footer_color_pair = bw
889
+ @klp.footer_mnemonic_color_pair = gw
807
890
  @klp.set_key_labels get_key_labels(:file), :file
808
891
  @klp.set_key_labels get_key_labels(:view), :view
809
892
  @klp.set_key_labels get_key_labels(:dir), :dir
@@ -811,13 +894,32 @@ class RFe
811
894
  @window.wrefresh
812
895
  Ncurses::Panel.update_panels
813
896
  begin
897
+ chunks=["File","Key"]
898
+ color0 = get_color($promptcolor, 'black','cyan')
899
+ color1 = get_color($datacolor, 'white','cyan')
900
+
814
901
  ## qq stops program, but only if M-v (vim mode)
815
902
  while(!stopping? && (ch = @window.getchar()) != ?\C-q.getbyte(0) )
816
903
  s = keycode_tos ch
817
- status_row.text = "Pressed #{ch} , #{s}"
904
+ #status_row.text = "| Pressed #{ch} , #{s}"
818
905
  @form.handle_key(ch)
819
906
 
820
- @form.repaint
907
+ # the following is just a test of show_colored_chunks
908
+ #count = @current_list.list.size
909
+ count1 = @lista.list.size
910
+ count2 = @listb.list.size
911
+ x, y = FFI::NCurses::getyx @window.get_window
912
+ chunks[0]=[color0, "%-30s" % status_row.text, FFI::NCurses::A_BOLD]
913
+ chunks[1]=[color1, "%-18s" % " | #{ch}, #{s} |", FFI::NCurses::A_NORMAL]
914
+ chunks[2]=[color0, " Total: #{count1}, #{count2}"]
915
+ @window.wmove(Ncurses.LINES-3,0)
916
+ @window.color_set(color0, nil)
917
+ @window.print_empty_line
918
+ @window.wmove(Ncurses.LINES-3,0)
919
+ @window.show_colored_chunks chunks
920
+ @window.wmove(x,y)
921
+
922
+ #@form.repaint
821
923
  @window.wrefresh
822
924
  end
823
925
  ensure
@@ -847,12 +949,13 @@ def get_key_labels categ=nil
847
949
  key_labels = [
848
950
  ['C-q', 'Exit'], ['C-v', 'View'],
849
951
  ['C-f', 'File'], ['C-d', 'Dir'],
850
- ['C-x','Select'], nil,
952
+ ['C-Sp','Select'], ['Spc', "Preview"],
851
953
  ['F3', 'View'], ['F4', 'Edit'],
852
954
  ['F5', 'Filter'], ['F6', 'Sort'],
853
955
  ['F7', 'Grep'], ['F8', 'System'],
854
956
  ['M-0', 'Top'], ['M-9', 'End'],
855
- ['C-p', 'PgUp'], ['C-n', 'PgDn']
957
+ ['C-p', 'PgUp'], ['C-n', 'PgDn'],
958
+ ['M-v', 'Vim Mode'], ['BSpc', 'PrevDir']
856
959
  ]
857
960
  elsif categ == :file
858
961
  key_labels = [
@@ -944,6 +1047,10 @@ def filter
944
1047
  @current_list.filter_pattern = f
945
1048
  @current_list.rescan
946
1049
  end
1050
+
1051
+ # ask user for pattern to grep through files
1052
+ # and display file names in same list
1053
+
947
1054
  def grep_popup
948
1055
  last_regex = @last_regex || ""
949
1056
  last_pattern = @last_pattern || "*"
@@ -990,16 +1097,25 @@ def grep_popup
990
1097
  flags=""
991
1098
  flags << " -i " if mform.by_name["case insensitive"].value==true
992
1099
  flags << " -R " if mform.by_name["Recurse"].value==true
1100
+ # sometimes grep pukes "No such file or directory if you specify some
1101
+ # filespec that is not present. I don't want it to come in filestr
1102
+ # so i am not piping stderr to stdout
993
1103
  cmd = "cd #{@current_list.cur_dir()};grep -l #{flags} #{inp} #{fp}"
994
1104
  filestr = %x[ #{cmd} ]
995
1105
  files = nil
996
1106
  files = filestr.split(/\n/) unless filestr.nil?
997
1107
  #view filestr
1108
+ if !files || files.empty?
1109
+ alert "Sorry! No files for regex #{inp}"
1110
+ return
1111
+ end
998
1112
  @current_list.title "grep #{inp}"
999
1113
  @current_list.populate files
1114
+ # Use backspace to go back
1000
1115
  end
1001
1116
  return mb.selected_index, mform.by_name["regex"].getvalue, mform.by_name["filepattern"].getvalue, mform.by_name["Recurse"].value, mform.by_name["case insensitive"].value
1002
1117
  end
1118
+
1003
1119
  def system_popup
1004
1120
  deflt = @last_system || ""
1005
1121
  options=["run in shell","view output","file explorer"]
@@ -10,9 +10,54 @@ module RubyCurses
10
10
  @orig_bgcolor = @bgcolor
11
11
  @orig_color = @color
12
12
  @orig_attr = @attr
13
+ # we need to refer to file types, executable, dir, link, otherwise we'll go crazy
14
+ @color_hash = {
15
+ '.rb' => [get_color($datacolor, 'red', 'black'), 0],
16
+ '.txt' => [get_color($datacolor, 'white', 'black'), 0],
17
+ '.gemspec' => [get_color($datacolor, 'yellow', 'black'), 0],
18
+ '.gem' => [get_color($datacolor, 'yellow', 'black'), 0],
19
+ '.c' => [get_color($datacolor, 'green', 'black'), 0],
20
+ '.py' => [get_color($datacolor, 'green', 'black'), 0],
21
+ '.tgz' => [get_color($datacolor, 'red', 'black'), get_attrib('bold')],
22
+ '.gz' => [get_color($datacolor, 'red', 'black'), 0],
23
+ '.zip' => [get_color($datacolor, 'red', 'black'), 0],
24
+ '.jar' => [get_color($datacolor, 'red', 'black'), 0],
25
+ '.html' => [get_color($datacolor, 'green', 'black'), get_attrib('reverse')],
26
+ "" => [get_color($datacolor, 'yellow', 'black'), get_attrib('bold')],
27
+ '.jpg' => [get_color($datacolor, 'magenta', 'black'), 0],
28
+ '.png' => [get_color($datacolor, 'magenta', 'black'), 0],
29
+ '.sh' => [get_color($datacolor, 'red', 'black'), 0],
30
+ '.mp3' => [get_color($datacolor, 'cyan', 'blue'), 0],
31
+ '.bak' => [get_color($datacolor, 'magenta', 'black'), 0],
32
+ '.tmp' => [get_color($datacolor, 'black', 'blue'), 0],
33
+ '.pl' => [get_color($datacolor, 'green', 'black'), 0],
34
+ '.java' => [get_color($datacolor, 'cyan', 'blue'), 0],
35
+ '.class' => [get_color($datacolor, 'magenta', 'black'), 0],
36
+ '.pyc' => [get_color($datacolor, 'magenta', 'black'), 0],
37
+ '.o' => [get_color($datacolor, 'magenta', 'black'), 0],
38
+ '.a' => [get_color($datacolor, 'magenta', 'black'), 0],
39
+ '.lib' => [get_color($datacolor, 'magenta', 'black'), 0]
40
+ }
41
+ end
42
+
43
+ # override parent method to set color_pair and attr for different kind of files
44
+ def select_colors focussed, selected
45
+ ext = File.extname(@path)
46
+ c = @color_hash[ext]
47
+ c = [$datacolor, FFI::NCurses::A_NORMAL] unless c
48
+ if File.directory? @path
49
+ c = [get_color($datacolor, 'blue', 'black'), FFI::NCurses::A_BOLD]
50
+ end
51
+ @color_pair, @attr = *c
52
+ if selected
53
+ #@attr = FFI::NCurses::A_UNDERLINE | FFI::NCurses::A_BOLD # UL not avaible on screen
54
+ @attr = FFI::NCurses::A_REVERSE | FFI::NCurses::A_BOLD
55
+ @color_pair = $datacolor
56
+ end
57
+ if focussed
58
+ @attr = FFI::NCurses::A_REVERSE # | FFI::NCurses::A_BOLD
59
+ end
13
60
  end
14
- ##
15
- ##
16
61
  #
17
62
  def repaint graphic, r=@row,c=@col, row_index=-1, value=@text, focussed=false, selected=false
18
63
 
@@ -26,6 +71,7 @@ module RubyCurses
26
71
  else
27
72
  path = @parent.cur_dir()+"/"+value
28
73
  end
74
+ @path = path # i need it in select_color
29
75
  begin
30
76
  stat = File.stat(path)
31
77
  if File.directory? path
data/examples/sqlc.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  ## rkumar, 2009
2
+ #
2
3
  #DEPRECATED. See sqlm.rb or sqlt.rb in which i use a TabularWidget instead of Table.
3
4
  #AVOID USING TabbedPane till its rewritten 1.3.2 or so.
4
5
 
@@ -167,7 +168,7 @@ class Sqlc
167
168
  end
168
169
  def run
169
170
  title = "rbcurse"
170
- @header = ApplicationHeader.new @form, title, {:text2=>"Demo", :text_center=>"SQL Client using TabbedPane and Table (see sqlm.rb instead) "}
171
+ @header = ApplicationHeader.new @form, title, {:text2=>"Demo", :text_center=>"SQL Client using deprecated TabbedPane and Table (see sqlm.rb instead) "}
171
172
  status_row = RubyCurses::Label.new @form, {'text' => "", :row => Ncurses.LINES-4, :col => 0, :display_length=>70}
172
173
  @status_row = status_row
173
174
  # setting ENTER across all objects on a form
data/examples/sqlm.rb CHANGED
@@ -7,8 +7,6 @@
7
7
  # This is an offshoot of sqlc.rb -- this demo uses a multicontainer for tables
8
8
  # instead of a tabbed panes.
9
9
  #
10
- require 'rubygems'
11
- #require 'ncurses' # FFI
12
10
  require 'logger'
13
11
  require 'sqlite3'
14
12
  require 'rbcurse'
data/examples/table1.rb CHANGED
@@ -1,13 +1,7 @@
1
1
  require 'rbcurse/app'
2
2
 
3
3
  if $0 == __FILE__
4
- #app = App.new
5
- #window = app.window
6
- #window.printstring 2, 30, "Demo of Listbox - rbcurse", $normalcolor, 'reverse'
7
- #app.logger.info "beforegetch"
8
- #window.getch
9
- #app.close
10
- # this was the yield example, but now we've moved to instance eval
4
+ # NOTE try using the readonly tabular or tabular widget instead, see term2.rb
11
5
  App.new do
12
6
  @window.printstring 1, 30, "Demo of Table - rbcurse", $normalcolor, 'reverse'
13
7
  @window.printstring 2, 30, "Hit F1 to quit", $datacolor, 'normal'
data/examples/term2.rb CHANGED
@@ -16,7 +16,10 @@ App.new do
16
16
  #list_box :list => t.to_s.split("\n")
17
17
  list_box :list => t.render
18
18
  end # stack
19
- r = `df -gh`
19
+ r = `/bin/df -gh` # stock BSD df
20
+ #r = `df -gh` # I've installed brew, the df (maybe coreutils gives an error due to g option"
21
+
22
+ raise "df -gh not returning anything. correct command here. Try removing g option" if r == ""
20
23
  # on my system there are extra spaces so i need to remove them, or else
21
24
  # there'll be a mismatch between headers and columns
22
25
  r.gsub!("Mounted on", "Mounted_on")
data/examples/test1.rb CHANGED
@@ -5,12 +5,7 @@
5
5
  # TERM=xterm-color does but does not trap F1, f2 etc
6
6
  # TERM=xterm does not but other things are fine.
7
7
  #
8
- #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
9
- require 'rubygems'
10
- #require 'ncurses' # FFI
11
8
  require 'logger'
12
- #require 'lib/rbcurse/mapper'
13
- #require 'lib/rbcurse/keylabelprinter'
14
9
  require 'rbcurse'
15
10
  require 'rbcurse/rmessagebox'
16
11