rbcurse-core 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.md +69 -0
  2. data/VERSION +1 -0
  3. data/examples/abasiclist.rb +151 -0
  4. data/examples/alpmenu.rb +46 -0
  5. data/examples/app.sample +17 -0
  6. data/examples/atree.rb +100 -0
  7. data/examples/common/file.rb +45 -0
  8. data/examples/data/README.markdown +9 -0
  9. data/examples/data/brew.txt +38 -0
  10. data/examples/data/color.2 +37 -0
  11. data/examples/data/gemlist.txt +60 -0
  12. data/examples/data/lotr.txt +12 -0
  13. data/examples/data/ports.txt +136 -0
  14. data/examples/data/table.txt +37 -0
  15. data/examples/data/tasks.csv +88 -0
  16. data/examples/data/tasks.txt +27 -0
  17. data/examples/data/todo.txt +10 -0
  18. data/examples/data/todocsv.csv +28 -0
  19. data/examples/data/unix1.txt +21 -0
  20. data/examples/data/unix2.txt +11 -0
  21. data/examples/dbdemo.rb +487 -0
  22. data/examples/dirtree.rb +90 -0
  23. data/examples/newtabbedwindow.rb +100 -0
  24. data/examples/newtesttabp.rb +92 -0
  25. data/examples/tabular.rb +132 -0
  26. data/examples/tasks.rb +167 -0
  27. data/examples/term2.rb +83 -0
  28. data/examples/testkeypress.rb +72 -0
  29. data/examples/testlistbox.rb +158 -0
  30. data/examples/testmessagebox.rb +140 -0
  31. data/examples/testree.rb +106 -0
  32. data/examples/testwsshortcuts.rb +66 -0
  33. data/examples/testwsshortcuts2.rb +127 -0
  34. data/lib/rbcurse.rb +8 -0
  35. data/lib/rbcurse/core/docs/index.txt +73 -0
  36. data/lib/rbcurse/core/include/action.rb +40 -0
  37. data/lib/rbcurse/core/include/appmethods.rb +112 -0
  38. data/lib/rbcurse/core/include/bordertitle.rb +41 -0
  39. data/lib/rbcurse/core/include/chunk.rb +182 -0
  40. data/lib/rbcurse/core/include/io.rb +953 -0
  41. data/lib/rbcurse/core/include/listcellrenderer.rb +140 -0
  42. data/lib/rbcurse/core/include/listeditable.rb +317 -0
  43. data/lib/rbcurse/core/include/listscrollable.rb +590 -0
  44. data/lib/rbcurse/core/include/listselectable.rb +264 -0
  45. data/lib/rbcurse/core/include/multibuffer.rb +83 -0
  46. data/lib/rbcurse/core/include/orderedhash.rb +77 -0
  47. data/lib/rbcurse/core/include/ractionevent.rb +67 -0
  48. data/lib/rbcurse/core/include/rchangeevent.rb +27 -0
  49. data/lib/rbcurse/core/include/rhistory.rb +62 -0
  50. data/lib/rbcurse/core/include/rinputdataevent.rb +47 -0
  51. data/lib/rbcurse/core/include/vieditable.rb +170 -0
  52. data/lib/rbcurse/core/system/colormap.rb +163 -0
  53. data/lib/rbcurse/core/system/keyboard.rb +150 -0
  54. data/lib/rbcurse/core/system/keydefs.rb +30 -0
  55. data/lib/rbcurse/core/system/ncurses.rb +218 -0
  56. data/lib/rbcurse/core/system/panel.rb +162 -0
  57. data/lib/rbcurse/core/system/window.rb +901 -0
  58. data/lib/rbcurse/core/util/ansiparser.rb +117 -0
  59. data/lib/rbcurse/core/util/app.rb +1235 -0
  60. data/lib/rbcurse/core/util/basestack.rb +407 -0
  61. data/lib/rbcurse/core/util/bottomline.rb +1850 -0
  62. data/lib/rbcurse/core/util/colorparser.rb +71 -0
  63. data/lib/rbcurse/core/util/focusmanager.rb +31 -0
  64. data/lib/rbcurse/core/util/padreader.rb +189 -0
  65. data/lib/rbcurse/core/util/rcommandwindow.rb +587 -0
  66. data/lib/rbcurse/core/util/rdialogs.rb +619 -0
  67. data/lib/rbcurse/core/util/viewer.rb +149 -0
  68. data/lib/rbcurse/core/util/widgetshortcuts.rb +505 -0
  69. data/lib/rbcurse/core/widgets/applicationheader.rb +102 -0
  70. data/lib/rbcurse/core/widgets/box.rb +58 -0
  71. data/lib/rbcurse/core/widgets/divider.rb +310 -0
  72. data/lib/rbcurse/core/widgets/keylabelprinter.rb +178 -0
  73. data/lib/rbcurse/core/widgets/rcombo.rb +238 -0
  74. data/lib/rbcurse/core/widgets/rcontainer.rb +415 -0
  75. data/lib/rbcurse/core/widgets/rlink.rb +30 -0
  76. data/lib/rbcurse/core/widgets/rlist.rb +723 -0
  77. data/lib/rbcurse/core/widgets/rmenu.rb +939 -0
  78. data/lib/rbcurse/core/widgets/rmenulink.rb +22 -0
  79. data/lib/rbcurse/core/widgets/rmessagebox.rb +373 -0
  80. data/lib/rbcurse/core/widgets/rprogress.rb +118 -0
  81. data/lib/rbcurse/core/widgets/rtabbedpane.rb +615 -0
  82. data/lib/rbcurse/core/widgets/rtabbedwindow.rb +68 -0
  83. data/lib/rbcurse/core/widgets/rtextarea.rb +920 -0
  84. data/lib/rbcurse/core/widgets/rtextview.rb +780 -0
  85. data/lib/rbcurse/core/widgets/rtree.rb +787 -0
  86. data/lib/rbcurse/core/widgets/rwidget.rb +3040 -0
  87. data/lib/rbcurse/core/widgets/scrollbar.rb +143 -0
  88. data/lib/rbcurse/core/widgets/statusline.rb +94 -0
  89. data/lib/rbcurse/core/widgets/tabular.rb +264 -0
  90. data/lib/rbcurse/core/widgets/tabularwidget.rb +1211 -0
  91. data/lib/rbcurse/core/widgets/textpad.rb +516 -0
  92. data/lib/rbcurse/core/widgets/tree/treecellrenderer.rb +150 -0
  93. data/lib/rbcurse/core/widgets/tree/treemodel.rb +428 -0
  94. metadata +156 -0
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # rbcurse-core
2
+
3
+ Contains core widgets and infrastructure of rbcurse ncurses toolkit. rbcurse helps to easily build
4
+ ncurses application for text terminals.
5
+
6
+ rbcurse-core contains basic widgets for constructing applications. These include:
7
+
8
+ * field
9
+
10
+ * buttons - checkbox, radio, toggle
11
+
12
+ * list
13
+
14
+ * textview
15
+
16
+ * dialogs and popup
17
+
18
+ * table
19
+
20
+ * menu
21
+
22
+ * tabbedpane
23
+
24
+ * tree
25
+
26
+ * application header
27
+
28
+ * status line
29
+
30
+ Core intends to be :
31
+
32
+ * stable,
33
+
34
+ * have very few changes,
35
+
36
+ * be backward compatible.
37
+
38
+ * simple, maintaible code
39
+
40
+ I shall be standardizing core over the next one or two minor versions. I shall also be simplifying code as much as possible to make it maintainable and more bug-free.
41
+
42
+ Method names in some classes may change, and one or two widget names will change. rbasiclistbox will become listbox while the old listbox that has moved to extras will become something like editlistbox. Similarly the old table will become edittable in extras, whereas tabularwidget will becoming table in core.
43
+ The new tabbedpane and messagebox will replace the old ones, while the old ones will move to /deprecated.
44
+
45
+ Color formatting needs to be standardized and a proper API firmed up for that, so user code does not get affected by internal changes. Similarly, work on textpad may get integrated into some widgets since it could simplify their code.
46
+
47
+ ## Install
48
+
49
+ `gem install rbcurse-core` # just the core
50
+
51
+ To install more:
52
+
53
+ `gem install rbcurse-extras` # the core, and extra stuff
54
+
55
+ `gem install rbcurse` # the core, extra and experimental stuff
56
+
57
+ ## See also
58
+
59
+ * rbcurse - <http://github.com/rkumar/rbcurse/>
60
+
61
+ * rbcurse-core - <http://github.com/rkumar/rbcurse-core/>
62
+
63
+ * rbcurse-experimental - <http://github.com/rkumar/rbcurse-experimental/>
64
+
65
+ ## License
66
+
67
+ Same as ruby license.
68
+
69
+ (c) copyright rkumar, 2008-2011.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,151 @@
1
+ require 'rbcurse/core/util/app'
2
+ require 'rbcurse/core/include/appmethods'
3
+ require 'rbcurse/core/widgets/rlist'
4
+
5
+ def my_help_text
6
+ <<-eos
7
+ abasiclist.rb
8
+ =========================================================================
9
+ Basic Usage
10
+
11
+ This simple example shows 2 lists inside a "flow". Each takes 50 percent
12
+ of the screen's width.
13
+
14
+ If you have brew installed, you can refresh the list to show actual
15
+ brew packages on your system, using ':r'. Then you can view info, edit,
16
+ or see the man page for that program.
17
+
18
+ In the second list, you can refresh the list with your gems using ":r".
19
+ Place cursor on any gem, and execute any of the ":" commands to see the
20
+ output. "edit" shells out to your EDITOR.
21
+
22
+ You can try multiple selection using <space> and <ctrl-space> for range
23
+ select. Check the general help screen for more _list_ commands. The selections
24
+ are not mapped to any command.
25
+
26
+ =========================================================================
27
+ :n or Alt-n for next buffer. 'q' to quit.
28
+
29
+ eos
30
+ end
31
+
32
+
33
+
34
+ # just a simple test to ensure that rbasiclistbox is running inside a container.
35
+ App.new do
36
+ def disp_menu
37
+ f = @form.get_current_field
38
+
39
+ if f.name == "lb1"
40
+ menu = PromptMenu.new self do
41
+ item :r, :refresh
42
+ item :i, :info
43
+ item :m, :brew_man
44
+ item :e, :edit
45
+ end
46
+ else
47
+ menu = PromptMenu.new self do
48
+ item :r, :refresh
49
+ item :e, :edit
50
+ item :d, :dependency
51
+ item :s, :specification
52
+ item :w, :which
53
+ end
54
+ end
55
+ menu.display_new :title => "Menu"
56
+ end
57
+ # fill list with actual gems available on your system
58
+ def refresh
59
+ f = @form.get_current_field
60
+ if f.name == "lb2"
61
+ l = %x[gem list --local].split("\n")
62
+ w = @form.by_name['lb2']
63
+ w.list l
64
+ else
65
+ l = %x[brew list].split("\n")
66
+ w = @form.by_name['lb1']
67
+ w.list l
68
+ end
69
+ end
70
+ def specification
71
+ w = @form.by_name['lb2']
72
+ name = w.text.split()[0]
73
+ textdialog(%x[ gem specification #{name} ].split("\n") , :title => 'Specification')
74
+ end
75
+
76
+ # execute just man for the brew package
77
+ def brew_man
78
+ w = @form.by_name['lb1']
79
+ name = w.text.split()[0]
80
+ shell_out "man #{name}"
81
+ end
82
+
83
+ # using gem which to get path, and then shelling out to EDITOR
84
+ def edit
85
+ f = @form.get_current_field
86
+ if f.name == "lb2"
87
+ name = f.text.split()[0]
88
+ shell_out "gem edit #{name}"
89
+ else
90
+ name = f.text.split()[0]
91
+ shell_out "brew edit #{name}"
92
+ end
93
+ return
94
+
95
+ # this is our own home-cooked version which opens the actual file in your editor
96
+ res = %x[ gem which #{name} ].split("\n")
97
+ res = res[0]
98
+ if File.exists? res
99
+ require './common/file.rb'
100
+ file_edit res
101
+ end
102
+ end
103
+ #
104
+ # general purpose command to catch miscellaneous actions that can be
105
+ # executed in the same way. Or even take complex command lines
106
+ # such as what vim has.
107
+ def execute_this *cmd
108
+ f = @form.get_current_field
109
+ if f.name == "lb2"
110
+ m = "gem"
111
+ else
112
+ m = "brew"
113
+ end
114
+ w = f
115
+ name = w.text.split()[0]
116
+ cmd = cmd[0].to_s
117
+ res = %x[ #{m} #{cmd} #{name}].split("\n")
118
+ res ||= "Error in command [#{cmd}] [#{name}] "
119
+ textdialog( res, :title => cmd ) if res
120
+ end
121
+
122
+ colors = Ncurses.COLORS
123
+ back = :blue
124
+ back = 234 if colors >= 256
125
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Basic List Demo", :text_right =>"New Improved!", :color => :white, :bgcolor => back #, :attr => :bold
126
+ message "Press F10 to escape from here"
127
+ install_help_text my_help_text
128
+
129
+ alist = File.open("data/brew.txt",'r').readlines
130
+ list2 = File.open("data/gemlist.txt",'r').readlines
131
+ lb = nil
132
+
133
+ flow :margin_top => 1, :height => FFI::NCurses.LINES-2 do
134
+ lb = listbox :list => alist, :suppress_borders => false, :title => "[ brew packages ]",
135
+ :left_margin => 1, :width_pc => 50, :name => 'lb1'
136
+ lb.show_selector = false
137
+
138
+ lb2 = listbox :list => list2, :justify => :left, :title => "[ gems ]", :suppress_borders => false,
139
+ :left_margin => 1, :width_pc => 50, :name => 'lb2'
140
+ end
141
+
142
+
143
+ label({:text => "F1 Help, F10 Quit. Press F4 and F5 to test popup, space or enter to select", :row => Ncurses.LINES-1, :col => 0})
144
+
145
+ @form.bind_key(FFI::NCurses::KEY_F4) { row = lb.current_index+lb.row; col=lb.col+lb.current_value.length+1; ret = popuplist(%w[ andy berlioz strauss tchaiko matz beethoven], :row => row, :col => col, :title => "Names", :bgcolor => :blue, :color => :white) ; alert "got #{ret} "}
146
+
147
+ @form.bind_key(FFI::NCurses::KEY_F5) { list = %x[ls].split("\n");ret = popuplist(list, :title => "Files"); alert "Got #{ret} #{list[ret]} " }
148
+
149
+ @form.bind_key(?:) { disp_menu;
150
+ }
151
+ end # app
@@ -0,0 +1,46 @@
1
+ require 'rbcurse/core/util/app'
2
+
3
+ App.new do
4
+ #title "Demo of Menu - rbcurse"
5
+ #subtitle "Hit F1 to quit, F2 for menubar toggle"
6
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Alpine Menu Demo", :text_right =>""
7
+
8
+ stack :margin_top => 10, :margin_left => 15 do
9
+ #w = "Messages".length + 1
10
+ w = 60
11
+ menulink :text => "&View Todo", :width => w, :description => "View TODO in sqlite" do |s|
12
+ message "Pressed #{s.text} "
13
+ load './dirtree.rb'
14
+ #require './viewtodo'; todo = ViewTodo::TodoApp.new; todo.run
15
+ end
16
+ blank
17
+ menulink :text => "&Edit Todo", :width => w, :description => "Edit TODO in CSV" do |s|
18
+ message "Pressed #{s.text} "
19
+ load './tabular.rb'
20
+ #require './testtodo'; todo = TestTodo::TodoApp.new; todo.run
21
+ end
22
+ blank
23
+ menulink :text => "&Messages", :width => w, :description => "View messages in current folder" do |s|
24
+ message "Pressed #{s.text} "
25
+ load './tasks.rb'
26
+ end
27
+ blank
28
+ menulink :text => "&Compose", :width => w, :description => "Compose a mail" do |s|
29
+ message "Pressed #{s.getvalue} "
30
+ load './dbdemo.rb'
31
+ end
32
+ blank
33
+ # somehow ? in mnemonic won't work
34
+ menulink :text => "&Setup", :width => w, :description => "Configure Alpine options" do |s|
35
+ #message "Pressed #{s.text} "
36
+ alert "Not done!"
37
+ end
38
+ blank
39
+ menulink :text => "&Quit", :width => w, :description => "Quit this application" do |s|
40
+ quit
41
+ end
42
+ @form.bind(:ENTER) do |w|
43
+ header.text_right = w.text
44
+ end
45
+ end # stack
46
+ end # app
@@ -0,0 +1,17 @@
1
+ require 'rbcurse/core/util/app'
2
+
3
+ def help_text
4
+ <<-eos
5
+ eos
6
+ end
7
+
8
+ App.new do
9
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "My Demo", :text_right =>"New Improved!",
10
+ :color => :black, :bgcolor => :white, :attr => :bold
11
+ message "Press F10 to exit from here, F1 for help, F2 for menu"
12
+
13
+ stack :margin_top => 1, height => FFI::NCurses.LINES-3 do
14
+
15
+ end # stack
16
+ status_line :row => FFI::NCurses.LINES-1
17
+ end # app
data/examples/atree.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'rbcurse/core/util/app'
2
+
3
+ App.new do
4
+ var = Variable.new
5
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Tree Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
6
+ message "Press Enter to expand/collapse"
7
+
8
+ @form.bind_key(FFI::NCurses::KEY_F3) {
9
+ require 'rbcurse/core/util/viewer'
10
+ RubyCurses::Viewer.view("rbc13.log", :close_key => KEY_ENTER, :title => "<Enter> to close")
11
+ }
12
+
13
+ ww = FFI::NCurses.COLS-0
14
+ flow :width => ww , :margin_top => 1, :height => FFI::NCurses.LINES-2 do
15
+ stack :margin_top => 0, :width_pc => "30" do
16
+ tm = nil
17
+ atree = tree :height => 10, :title => '[ ruby way ]' do
18
+ root "root" do
19
+ branch "hello" do
20
+ leaf "ruby"
21
+ end
22
+ branch "goodbye" do
23
+ leaf "java"
24
+ leaf "verbosity"
25
+ end
26
+ end
27
+ end
28
+ found=atree.get_node_for_path "goodbye"
29
+ atree.set_expanded_state(atree.root, true)
30
+ atree.set_expanded_state(found,true)
31
+
32
+ # using a Hash
33
+ model = { :ruby => [ "jruby", {:mri => %W[ 1.8.6 1.8.7]}, {:yarv => %W[1.9.1 1.9.2]}, "rubinius", "macruby" ], :python => %W[ cpython jython laden-swallow ] }
34
+ tree :data => model, :title => "[ Hash ]"
35
+
36
+ end # stack
37
+ stack :margin_top => 0, :width_pc => "30" do
38
+
39
+ # using an Array, these would be expanded on selection, using an event
40
+ tree :data => Dir.glob("*"), :title=> "[ Array ]" do
41
+ command do |node|
42
+ # insert dir entries unless done so already
43
+ if node.children && !node.children.empty?
44
+ else
45
+ f = node.user_object
46
+ if File.directory? f
47
+ l = Dir.glob(f + "/*")
48
+ node.add(l) if l
49
+ end
50
+ end
51
+ end
52
+ bind :ENTER_ROW do |t|
53
+ var.value = t.text.user_object
54
+ end
55
+ end
56
+
57
+ # long way ISO 9001 certifed, SEI CMM 5 compliant
58
+ #
59
+ root = TreeNode.new "ROOT"
60
+ subroot = TreeNode.new "subroot"
61
+ leaf1 = TreeNode.new "leaf 1"
62
+ leaf2 = TreeNode.new "leaf 2"
63
+ model = DefaultTreeModel.new root
64
+ #model.insert_node_into(subroot, root, 0) # BLEAH JAVA !!
65
+
66
+ # slightly better, since we return self in ruby
67
+ root << subroot
68
+ subroot << leaf1 << leaf2
69
+ leaf1 << "leaf11"
70
+ leaf1 << "leaf12"
71
+
72
+ # more rubyish way
73
+ root.add "blocky", true do
74
+ add "block2"
75
+ add "block3" do
76
+ add "block31"
77
+ end
78
+ end
79
+
80
+ tree :data => model, :title => "[ legacy way ]"
81
+
82
+ end
83
+ #stack :margin_top => 2 do
84
+ stack :margin_top => 0, :width_pc => "40", :height => :expand do
85
+ t = textview :suppress_borders => true, :height_pc => 100
86
+ var.command do |filename|
87
+ filename = filename.value
88
+ if File.directory? filename
89
+ lines = Dir.entries(filename )
90
+ t.set_content lines
91
+ elsif File.exist? filename
92
+ lines = File.open(filename,'r').readlines
93
+ t.set_content lines
94
+ else
95
+ alert " #{filename} does not appear to be a file "
96
+ end
97
+ end
98
+ end
99
+ end # flow
100
+ end # app
@@ -0,0 +1,45 @@
1
+ # ----------------------------------------------------------------------------- #
2
+ # File: file.rb
3
+ # Description: some common file related methods which can be used across
4
+ # file manager demos, since we seems to have a lot of them :)
5
+ # Author: rkumar http://github.com/rkumar/rbcurse/
6
+ # Date: 2011-11-15 - 19:54
7
+ # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
8
+ # Last update: use ,,L
9
+ # ----------------------------------------------------------------------------- #
10
+ #
11
+
12
+ require 'rbcurse/core/include/appmethods'
13
+ module RubyCurses
14
+ def file_edit fp #=@current_list.filepath
15
+ #$log.debug " edit #{fp}"
16
+ editor = ENV['EDITOR'] || 'vi'
17
+ vimp = %x[which #{editor}].chomp
18
+ shell_out "#{vimp} #{fp}"
19
+ end
20
+
21
+ # TODO we need to move these to some common file so differnt programs and demos
22
+ # can use them on pressing space or enter.
23
+ def file_page fp #=@current_list.filepath
24
+ unless File.exists? fp
25
+ pwd = %x[pwd]
26
+ alert "No such file. My pwd is #{pwd} "
27
+ return
28
+ end
29
+ ft=%x[file #{fp}]
30
+ if ft.index("text")
31
+ pager = ENV['PAGER'] || 'less'
32
+ vimp = %x[which #{pager}].chomp
33
+ shell_out "#{vimp} #{fp}"
34
+ elsif ft.index(/zip/i)
35
+ shell_out "tar tvf #{fp} | less"
36
+ elsif ft.index(/directory/i)
37
+ shell_out "ls -lh #{fp} | less"
38
+ else
39
+ alert "#{fp} is not text, not paging "
40
+ #use_on_file "als", fp # only zip or archive
41
+ end
42
+ end
43
+
44
+ end # module
45
+ include RubyCurses
@@ -0,0 +1,9 @@
1
+ I've put some data here to use in programs as text for textareas, textviews or lists.
2
+
3
+ brew.txt - single list, use in listboxes
4
+ color.2 - ANSI formatted text, use in formatted textview
5
+ gemlist.txt - single column list
6
+ lotr.txt - running text for text views
7
+ ports.txt - 3 column list, use in tables, tabular
8
+ unix1.txt - running text
9
+ unix2.txt - running text