canis 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +45 -0
  3. data/CHANGES +52 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +24 -0
  7. data/Rakefile +2 -0
  8. data/canis.gemspec +25 -0
  9. data/examples/alpmenu.rb +46 -0
  10. data/examples/app.sample +19 -0
  11. data/examples/appemail.rb +191 -0
  12. data/examples/atree.rb +105 -0
  13. data/examples/bline.rb +181 -0
  14. data/examples/common/devel.rb +319 -0
  15. data/examples/common/file.rb +93 -0
  16. data/examples/data/README.markdown +9 -0
  17. data/examples/data/brew.txt +38 -0
  18. data/examples/data/color.2 +37 -0
  19. data/examples/data/gemlist.txt +59 -0
  20. data/examples/data/lotr.txt +12 -0
  21. data/examples/data/ports.txt +136 -0
  22. data/examples/data/table.txt +37 -0
  23. data/examples/data/tasks.csv +88 -0
  24. data/examples/data/tasks.txt +27 -0
  25. data/examples/data/todo.txt +16 -0
  26. data/examples/data/todocsv.csv +28 -0
  27. data/examples/data/unix1.txt +21 -0
  28. data/examples/data/unix2.txt +11 -0
  29. data/examples/dbdemo.rb +506 -0
  30. data/examples/dirtree.rb +177 -0
  31. data/examples/newtabbedwindow.rb +100 -0
  32. data/examples/newtesttabp.rb +92 -0
  33. data/examples/tabular.rb +212 -0
  34. data/examples/tasks.rb +179 -0
  35. data/examples/term2.rb +88 -0
  36. data/examples/testbuttons.rb +307 -0
  37. data/examples/testcombo.rb +102 -0
  38. data/examples/testdb.rb +182 -0
  39. data/examples/testfields.rb +208 -0
  40. data/examples/testflowlayout.rb +43 -0
  41. data/examples/testkeypress.rb +98 -0
  42. data/examples/testlistbox.rb +187 -0
  43. data/examples/testlistbox1.rb +199 -0
  44. data/examples/testmessagebox.rb +144 -0
  45. data/examples/testprogress.rb +116 -0
  46. data/examples/testree.rb +107 -0
  47. data/examples/testsplitlayout.rb +53 -0
  48. data/examples/testsplitlayout1.rb +49 -0
  49. data/examples/teststacklayout.rb +48 -0
  50. data/examples/testwsshortcuts.rb +68 -0
  51. data/examples/testwsshortcuts2.rb +129 -0
  52. data/lib/canis.rb +16 -0
  53. data/lib/canis/core/docs/index.txt +104 -0
  54. data/lib/canis/core/docs/list.txt +16 -0
  55. data/lib/canis/core/docs/style_help.yml +34 -0
  56. data/lib/canis/core/docs/tabbedpane.txt +15 -0
  57. data/lib/canis/core/docs/table.txt +31 -0
  58. data/lib/canis/core/docs/textpad.txt +48 -0
  59. data/lib/canis/core/docs/tree.txt +23 -0
  60. data/lib/canis/core/include/.DS_Store +0 -0
  61. data/lib/canis/core/include/action.rb +83 -0
  62. data/lib/canis/core/include/actionmanager.rb +49 -0
  63. data/lib/canis/core/include/appmethods.rb +179 -0
  64. data/lib/canis/core/include/bordertitle.rb +49 -0
  65. data/lib/canis/core/include/canisparser.rb +100 -0
  66. data/lib/canis/core/include/colorparser.rb +437 -0
  67. data/lib/canis/core/include/defaultfilerenderer.rb +64 -0
  68. data/lib/canis/core/include/io.rb +320 -0
  69. data/lib/canis/core/include/layouts/SplitLayout.rb +161 -0
  70. data/lib/canis/core/include/layouts/abstractlayout.rb +213 -0
  71. data/lib/canis/core/include/layouts/flowlayout.rb +104 -0
  72. data/lib/canis/core/include/layouts/stacklayout.rb +109 -0
  73. data/lib/canis/core/include/listbindings.rb +89 -0
  74. data/lib/canis/core/include/listeditable.rb +319 -0
  75. data/lib/canis/core/include/listoperations.rb +61 -0
  76. data/lib/canis/core/include/listselectionmodel.rb +388 -0
  77. data/lib/canis/core/include/multibuffer.rb +173 -0
  78. data/lib/canis/core/include/ractionevent.rb +73 -0
  79. data/lib/canis/core/include/rchangeevent.rb +27 -0
  80. data/lib/canis/core/include/rhistory.rb +95 -0
  81. data/lib/canis/core/include/rinputdataevent.rb +47 -0
  82. data/lib/canis/core/include/textdocument.rb +111 -0
  83. data/lib/canis/core/include/vieditable.rb +175 -0
  84. data/lib/canis/core/include/widgetmenu.rb +66 -0
  85. data/lib/canis/core/system/colormap.rb +165 -0
  86. data/lib/canis/core/system/keydefs.rb +32 -0
  87. data/lib/canis/core/system/ncurses.rb +237 -0
  88. data/lib/canis/core/system/panel.rb +129 -0
  89. data/lib/canis/core/system/window.rb +1081 -0
  90. data/lib/canis/core/util/ansiparser.rb +119 -0
  91. data/lib/canis/core/util/app.rb +696 -0
  92. data/lib/canis/core/util/basestack.rb +412 -0
  93. data/lib/canis/core/util/defaultcolorparser.rb +84 -0
  94. data/lib/canis/core/util/extras/README +5 -0
  95. data/lib/canis/core/util/extras/bottomline.rb +1815 -0
  96. data/lib/canis/core/util/extras/padreader.rb +192 -0
  97. data/lib/canis/core/util/focusmanager.rb +31 -0
  98. data/lib/canis/core/util/helpmanager.rb +160 -0
  99. data/lib/canis/core/util/oldwidgetshortcuts.rb +304 -0
  100. data/lib/canis/core/util/promptmenu.rb +235 -0
  101. data/lib/canis/core/util/rcommandwindow.rb +933 -0
  102. data/lib/canis/core/util/rdialogs.rb +520 -0
  103. data/lib/canis/core/util/textutils.rb +74 -0
  104. data/lib/canis/core/util/viewer.rb +238 -0
  105. data/lib/canis/core/util/widgetshortcuts.rb +508 -0
  106. data/lib/canis/core/widgets/applicationheader.rb +103 -0
  107. data/lib/canis/core/widgets/box.rb +58 -0
  108. data/lib/canis/core/widgets/divider.rb +310 -0
  109. data/lib/canis/core/widgets/extras/README.md +12 -0
  110. data/lib/canis/core/widgets/extras/rtextarea.rb +960 -0
  111. data/lib/canis/core/widgets/extras/stackflow.rb +474 -0
  112. data/lib/canis/core/widgets/keylabelprinter.rb +194 -0
  113. data/lib/canis/core/widgets/listbox.rb +326 -0
  114. data/lib/canis/core/widgets/listfooter.rb +86 -0
  115. data/lib/canis/core/widgets/rcombo.rb +210 -0
  116. data/lib/canis/core/widgets/rcontainer.rb +415 -0
  117. data/lib/canis/core/widgets/rlink.rb +30 -0
  118. data/lib/canis/core/widgets/rmenu.rb +970 -0
  119. data/lib/canis/core/widgets/rmenulink.rb +30 -0
  120. data/lib/canis/core/widgets/rmessagebox.rb +400 -0
  121. data/lib/canis/core/widgets/rprogress.rb +118 -0
  122. data/lib/canis/core/widgets/rtabbedpane.rb +631 -0
  123. data/lib/canis/core/widgets/rtabbedwindow.rb +70 -0
  124. data/lib/canis/core/widgets/rwidget.rb +3634 -0
  125. data/lib/canis/core/widgets/scrollbar.rb +147 -0
  126. data/lib/canis/core/widgets/statusline.rb +113 -0
  127. data/lib/canis/core/widgets/table.rb +1072 -0
  128. data/lib/canis/core/widgets/tabular.rb +264 -0
  129. data/lib/canis/core/widgets/textpad.rb +1674 -0
  130. data/lib/canis/core/widgets/tree.rb +690 -0
  131. data/lib/canis/core/widgets/tree/treecellrenderer.rb +150 -0
  132. data/lib/canis/core/widgets/tree/treemodel.rb +432 -0
  133. data/lib/canis/version.rb +3 -0
  134. metadata +229 -0
@@ -0,0 +1,43 @@
1
+ # ----------------------------------------------------------------------------- #
2
+ # File: testflowlayout.rb
3
+ # Description:
4
+ # Author: j kepler http://github.com/mare-imbrium/canis/
5
+ # Date: 2014-05-09 - 20:24
6
+ # License: MIT
7
+ # Last update: 2014-05-09 20:39
8
+ # ----------------------------------------------------------------------------- #
9
+ # testflowlayout.rb Copyright (C) 2012-2014 j kepler
10
+
11
+ if __FILE__ == $PROGRAM_NAME
12
+ require 'canis/core/util/app'
13
+ require 'canis/core/widgets/listbox'
14
+ require 'canis/core/include/layouts/flowlayout'
15
+ App.new do
16
+
17
+ # if i add form here, it will repaint them first, and have no dimensions
18
+ lb = Listbox.new @form, :list => ["borodin","berlioz","bernstein","balakirev", "elgar"] , :name => "mylist"
19
+ lb1 = Listbox.new @form, :list => ["bach","beethoven","mozart","gorecki", "chopin","wagner","grieg","holst"] , :name => "mylist1"
20
+
21
+ lb2 = Listbox.new @form, :list => `gem list --local`.split("\n") , :name => "mylist2"
22
+ =begin
23
+
24
+ alist = %w[ ruby perl python java jruby macruby rubinius rails rack sinatra pylons django cakephp grails]
25
+ str = "Hello, people of Earth.\nI am HAL, a textbox.\nUse arrow keys, j/k/h/l/gg/G/C-a/C-e/C-n/C-p\n"
26
+ str << alist.join("\n")
27
+ tv = TextPad.new @form, :name => "text", :text => str.split("\n")
28
+ =end
29
+
30
+ w = Ncurses.COLS-1
31
+ h = Ncurses.LINES-3
32
+ #layout = StackLayout.new :height => -1, :top_margin => 1, :bottom_margin => 1, :left_margin => 1
33
+ layout = FlowLayout.new :height => -1, :top_margin => 1, :bottom_margin => 1, :left_margin => 1
34
+ layout.form = @form
35
+ @form.layout_manager = layout
36
+ layout.cset lb, :weight, 15
37
+ layout.cset lb1, :weight, 25
38
+ #$status_message.value =" Flow: #{@r.components[0].orientation} | Stack #{@r.components[1].orientation}. Use Ctrl-Space to change "
39
+
40
+
41
+ st = status_line :row => -1
42
+ end # app
43
+ end # if
@@ -0,0 +1,98 @@
1
+ # demo to test keypresses
2
+ # press any key and see the value that ncurses or our routines catch.
3
+ # Press alt and control combinations and Function keys
4
+ # Ideally each key should return only one value. Sometimes, some TERM setting
5
+ # or terminal emulator may not give correct values or may give different values
6
+ # from what we are expecting.
7
+ # Exit using 'q'.
8
+ # # see window.rb for keycodes related to shift+F C_LEFT C_RIGHT etc.
9
+ require 'logger'
10
+ require 'canis'
11
+ #require 'canis/core/widgets/rtextview'
12
+ if $0 == __FILE__
13
+ include Canis
14
+ include Canis::Utils
15
+
16
+ dumpfile = "dump.yml"
17
+
18
+ begin
19
+ # Initialize curses
20
+ Canis::start_ncurses # this is initializing colors via ColorMap.setup
21
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"canis14.log")))
22
+
23
+ $log.level = Logger::DEBUG
24
+
25
+ @window = Canis::Window.root_window
26
+
27
+ catch(:close) do
28
+ colors = Ncurses.COLORS
29
+ $log.debug "START #{colors} colors ---------"
30
+ @form = Form.new @window
31
+ r = 1; c = 1;
32
+ w = Ncurses.COLS - c
33
+ h = Ncurses.LINES - 4
34
+ FFI::NCurses.set_escdelay(500)
35
+ nd = Ncurses.ESCDELAY
36
+
37
+ # please use a hash to pass these values, avoid this old style
38
+ # i want to move away from it as it comlpicates code
39
+ texta = TextPad.new @form do
40
+ name "mytext"
41
+ row r
42
+ col c
43
+ width w
44
+ height h
45
+ #editable false
46
+ focusable false
47
+ title "[ Keypresses ]"
48
+ #title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
49
+ title_attrib (Ncurses::A_BOLD)
50
+ end
51
+ help = "q to quit. escdelay is #{nd}. Check keys. F1..10, C-a..z, Alt a-zA-Z0-9, C-left,rt, Sh-F5..10 .: #{$0}"
52
+ help1 = "Press in quick succession: 1) M-[, w and (2) M-[, M-w. (3) M-Sh-O, w."
53
+ Canis::Label.new @form, {'text' => help, "row" => r+h+1, "col" => 2, "color" => "yellow"}
54
+ Canis::Label.new @form, {'text' => help1, "row" => r+h+2, "col" => 2, "color" => "green"}
55
+ texta.text = ["Press any key, Function, control, alt etc to see ","if it works.",
56
+ "See window.rb for keycodes if something is not being trapped properly"]
57
+
58
+ @form.repaint
59
+ @window.wrefresh
60
+ Ncurses::Panel.update_panels
61
+ while((ch = @window.getchar()) != 999 )
62
+ str = keycode_tos ch if ch.is_a? Fixnum
63
+ #str1 = @window.key_tos ch if ch.is_a? Fixnum
64
+ str1 = $key_chr
65
+ $log.debug "#{ch} got (#{str} #{str1})"
66
+ texta << "#{ch} got (#{str}) #{str1}"
67
+ if ch == 99999
68
+ name = get_string "Add a name for #{$key_chr}?"
69
+ if name
70
+ texta << "setting #{name} for #{str1} "
71
+ $kh[str1] = name
72
+ _name = $kh[str1]
73
+ texta << "set #{_name} for #{str1} "
74
+ $kh.each_pair { |name, val| $log.debug " MMMAP #{name} : #{val}" }
75
+ File.open(dumpfile, 'w' ) do |f|
76
+ f << YAML::dump($kh)
77
+ end
78
+ texta << "Written new keys to #{dumpfile}. Pls copy over ~/ncurses-keys.yml"
79
+ end
80
+ end
81
+ texta.goto_end
82
+ texta.repaint
83
+ @form.repaint
84
+ @window.wrefresh
85
+ break if ch == ?\q.getbyte(0)
86
+ #break if ch == "q"
87
+ end
88
+ end
89
+ rescue => ex
90
+ ensure
91
+ @window.destroy if !@window.nil?
92
+ Canis::stop_ncurses
93
+ p ex if ex
94
+ p(ex.backtrace.join("\n")) if ex
95
+ $log.debug( ex) if ex
96
+ $log.debug(ex.backtrace.join("\n")) if ex
97
+ end
98
+ end
@@ -0,0 +1,187 @@
1
+ # NOTE: If the listbox is empty, that could mean that you have not generated
2
+ # ri documentation for this version of ruby. You can do so by doing:
3
+ # rvm docs generate-ri
4
+ # or
5
+ # rvm docs generate
6
+ # (This assumes you are using rvm)
7
+ #
8
+ # WARNING : IF THIS PROGRAM HANGS check the ri command
9
+ # Maybe your version of ri has different options and is going interactive.
10
+ # ruby 1.9.3's ri requires a -l option or else if becomes interactive.
11
+ # this program tests out a listbox
12
+ # This is written in the old style where we start and end ncurses and initiate a
13
+ # getch loop. It gives more control.
14
+ # The new style is to use App which does the ncurses setup and teardown, as well
15
+ # as manages keys. It also takes care of logger and includes major stuff.
16
+ # NOTE : this is the new listbox (based on Textpad version, the original
17
+ # version has been moved to deprecated. 2014-04-08 - 18:32
18
+ require 'logger'
19
+ require 'canis'
20
+ require 'canis/core/widgets/listbox'
21
+ require 'canis/core/include/vieditable'
22
+ #require 'canis/experimental/widgets/undomanager'
23
+ class Canis::Listbox
24
+ # vieditable includes listeditable which
25
+ # does bring in some functions which can crash program like x and X TODO
26
+ # also, f overrides list f mapping. TODO
27
+ include ViEditable
28
+ end
29
+ def get_data str
30
+ #lines = `ri -f bs #{str}`.split("\n")
31
+ lines = `ri -f ansi #{str} 2>&1`.gsub('','').split("\n")
32
+ end
33
+ def my_help_text
34
+ <<-eos
35
+
36
+ =========================================================================
37
+ ## Basic Usage
38
+
39
+ Press <ENTER> on a class name on the first list, to view `ri` information
40
+ for it on the right.
41
+
42
+ Tab to right box, navigate to a method name, and press <ENTER> on a method
43
+ name, to see its details in a popup screen.
44
+ Press */* <slash> in any box to search. e.g "/String" will take you to the
45
+ first occurrence of "String". <n> will take you to the next match.
46
+
47
+ To go quickly to the first Class starting with 'S', type <f> followed by <S>.
48
+ Then press <n> to go to next match.
49
+
50
+ =========================================================================
51
+ ## Vim Edit Keys
52
+
53
+ The [[list]] on left has some extra vim keys enabled such as :
54
+ >
55
+ yy - yank/copy current line/s
56
+ P, p - paste after or before
57
+ dd - delete current line
58
+ o - insert a line after this one
59
+ C - change content of current line
60
+ <
61
+ These are not of use here, but are demonstrative of list capabilities.
62
+
63
+ =========================================================================
64
+ ## Buffers
65
+
66
+ Ordinary a [[textpad]] contains only one buffer. However, the one on the right
67
+ is extended for multiple buffers. Pressing <ENTER> on the left on several
68
+ rows opens multiple buffers on the right. Use <M-n> (Alt-N) and <M-p> to navigate.
69
+ ALternatively, <:> maps to a menu, so :n and :p may also be used.
70
+ <BACKSPACE> will also go to previous buffer, like a browser.
71
+
72
+ =========================================================================
73
+ Press <M-n> for next help screen, or try ":n", [[index]]
74
+
75
+ eos
76
+ end
77
+ if $0 == __FILE__
78
+ include Canis
79
+
80
+ begin
81
+ # Initialize curses
82
+ Canis::start_ncurses # this is initializing colors via ColorMap.setup
83
+ path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
84
+ logfilename = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
85
+ $log = Logger.new(logfilename)
86
+ $log.level = Logger::DEBUG
87
+
88
+ @window = Canis::Window.root_window
89
+ $log.debug " WINDOW #{FFI::NCurses.LINES} "
90
+ $catch_alt_digits = true; # emacs like alt-1..9 numeric arguments
91
+ # Initialize few color pairs
92
+ # Create the window to be associated with the form
93
+ # Un post form and free the memory
94
+
95
+ catch(:close) do
96
+ @form = Form.new @window
97
+ @form.help_manager.help_text = my_help_text
98
+ #@form.bind_key(KEY_F1, 'help'){ display_app_help }
99
+
100
+ # this is the old style of printing something directly on the window.
101
+ # The new style is to use a header
102
+ @form.window.printstring 0, 30, "Demo of Listbox - some vim keys", $normalcolor, BOLD
103
+ r = 1; fc = 1;
104
+
105
+ # this is the old style of using a label at the screen bottom, you can use the status_line
106
+
107
+ v = "F10 quits. F1 Help. Try j k gg G o O C dd f<char> w yy p P / . Press ENTER on Class or Method"
108
+ var = Canis::Label.new @form, {'text' => v, "row" => FFI::NCurses.LINES-2,
109
+ "col" => fc, "width" => 100}
110
+
111
+ h = FFI::NCurses.LINES-3
112
+ file = "./data/ports.txt"
113
+ #mylist = File.open(file,'r').readlines
114
+ mylist = `ri -l `.split("\n")
115
+ w = 25
116
+ #0.upto(100) { |v| mylist << "#{v} scrollable data" }
117
+ #
118
+ listb = Listbox.new @form, :name => "mylist" ,
119
+ :row => r ,
120
+ :col => 1 ,
121
+ :width => w,
122
+ :height => h,
123
+ :list => mylist,
124
+ :selection_mode => :single,
125
+ :show_selector => true,
126
+ #row_selected_symbol "[X] "
127
+ #row_unselected_symbol "[ ] "
128
+ :title => " Ruby Classes "
129
+ #title_attrib 'reverse'
130
+ #listb.one_key_selection = false # this allows us to map keys to methods
131
+ listb.vieditable_init_listbox
132
+ include Io
133
+ listb.bind_key(?r, 'get file'){ get_file("Get a file:") }
134
+ listb.bind(:PRESS) {
135
+ w = @form.by_name["tv"];
136
+ #lines = `ri -f bs #{listb.current_value}`.split("\n")
137
+ #lines = `ri -f ansi #{listb.current_value} 2>&1`.gsub('','').split("\n")
138
+ lines = get_data listb.current_value
139
+ #w.set_content(lines, :ansi)
140
+ w.add_content(lines, {:content_type => :ansi, :title => listb.current_value})
141
+ w.buffer_last
142
+ #w.title = listb.current_value
143
+ }
144
+
145
+ tv = Canis::TextPad.new @form, :row => r, :col => w+1, :height => h, :width => FFI::NCurses.COLS-w-1,
146
+ :name => "tv", :title => "Press Enter on method"
147
+ tv.set_content ["Press Enter on list to view ri information in this area.",
148
+ "Press ENTER on method name to see details"]
149
+ require 'canis/core/include/multibuffer'
150
+ tv.extend(Canis::MultiBuffers)
151
+ # with format 'bs' we had a '=' but now it is colored so we've lost section.
152
+ tv.text_patterns[:section] = Regexp.new(/^= /)
153
+ tv.bind_key(?s, "goto section") { tv.next_regex(:section) }
154
+
155
+ # pressing ENTER on a method name will popup details for that method
156
+ tv.bind(:PRESS) { |ev|
157
+ w = ev.word_under_cursor.strip
158
+ # check that user did not hit enter on empty area
159
+ if w != ""
160
+ #_text = `ri -f bs #{tv.title}.#{w} 2>&1`
161
+ #_text = _text.split("\n")
162
+ _text = get_data "#{tv.title}.#{w}"
163
+ if _text && _text.size != 0
164
+ view(_text, :content_type => :ansi)
165
+ end
166
+ end
167
+ }
168
+
169
+
170
+ @form.repaint
171
+ @window.wrefresh
172
+ Ncurses::Panel.update_panels
173
+ while((ch = @window.getchar()) != KEY_F10 )
174
+ @form.handle_key(ch)
175
+ @window.wrefresh
176
+ end
177
+ end
178
+ rescue => ex
179
+ $log.debug( ex) if ex
180
+ $log.debug(ex.backtrace.join("\n")) if ex
181
+ ensure
182
+ @window.destroy if !@window.nil?
183
+ Canis::stop_ncurses
184
+ p ex if ex
185
+ p(ex.backtrace.join("\n")) if ex
186
+ end
187
+ end
@@ -0,0 +1,199 @@
1
+ require 'canis/core/util/app'
2
+ require 'canis/core/include/appmethods'
3
+ require 'canis/core/widgets/listbox'
4
+ require 'canis/core/util/promptmenu'
5
+ require './common/devel.rb'
6
+
7
+ def my_help_text
8
+ <<-eos
9
+ |abasiclist.rb|
10
+ =========================================================================
11
+ **Basic Usage**
12
+
13
+ This simple example shows 2 lists inside a "flow". Each takes 50 percent
14
+ of the screen's width.
15
+
16
+ If you have brew installed, you can refresh the list to show actual
17
+ brew packages on your system, using ':r'. Then you can view info, edit,
18
+ or see the man page for that program.
19
+
20
+ In the second list, you can refresh the list with your gems using ":r".
21
+ Place cursor on any gem, and execute any of the ":" commands to see the
22
+ output. "edit" shells out to your EDITOR.
23
+
24
+ You can try multiple selection using <v> and <V> for range
25
+ select. Check the general help screen for more [[list]] commands. The selections
26
+ are not mapped to any command.
27
+
28
+ =========================================================================
29
+ :n or Alt-n for next buffer. 'q' to quit. [[index]]
30
+
31
+ eos
32
+ end
33
+
34
+
35
+
36
+ # just a simple test to ensure that rbasiclistbox is running inside a container.
37
+ App.new do
38
+ devel_bindings
39
+ def disp_menu
40
+ # ideally this shuld get action_manager and add_action so these are added to widgets actions
41
+ f = @form.get_current_field
42
+
43
+ if f.name == "lb1"
44
+ menu = PromptMenu.new self do
45
+ item :r, :refresh
46
+ item :i, :info
47
+ item :m, :brew_man
48
+ item :e, :edit
49
+ end
50
+ else
51
+ menu = PromptMenu.new self do
52
+ item :r, :refresh
53
+ item :e, :edit
54
+ item :d, :dependency
55
+ item :s, :specification
56
+ item :w, :which
57
+ end
58
+ end
59
+ menu.display_new :title => "Menu"
60
+ end
61
+ # fill list with actual gems available on your system
62
+ def refresh
63
+ f = @form.get_current_field
64
+ if f.name == "lb2"
65
+ l = %x[gem list --local].split("\n")
66
+ w = @form.by_name['lb2']
67
+ w.list l
68
+ else
69
+ l = %x[brew list].split("\n")
70
+ w = @form.by_name['lb1']
71
+ w.list l
72
+ end
73
+ end
74
+ def specification
75
+ w = @form.by_name['lb2']
76
+ name = w.current_value.split()[0]
77
+ textdialog(%x[ gem specification #{name} ].split("\n") , :title => 'Specification')
78
+ end
79
+
80
+ # execute just man for the brew package
81
+ def brew_man
82
+ w = @form.by_name['lb1']
83
+ #name = w.text.split()[0]
84
+ name = w.current_value.split()[0]
85
+ shell_out "man #{name}"
86
+ end
87
+
88
+ # using gem which to get path, and then shelling out to EDITOR
89
+ def edit
90
+ f = @form.get_current_field
91
+ if f.name == "lb2"
92
+ name = f.current_value.split()[0]
93
+ shell_out "gem edit #{name}"
94
+ else
95
+ name = f.current_value.split()[0]
96
+ shell_out "brew edit #{name}"
97
+ end
98
+ return
99
+
100
+ # this is our own home-cooked version which opens the actual file in your editor
101
+ res = %x[ gem which #{name} ].split("\n")
102
+ res = res[0]
103
+ if File.exists? res
104
+ require './common/file.rb'
105
+ file_edit res
106
+ end
107
+ end
108
+ #
109
+ # general purpose command to catch miscellaneous actions that can be
110
+ # executed in the same way. Or even take complex command lines
111
+ # such as what vim has.
112
+ def execute_this *cmd
113
+ f = @form.get_current_field
114
+ if f.name == "lb2"
115
+ m = "gem"
116
+ else
117
+ m = "brew"
118
+ end
119
+ w = f
120
+ # textpad returns array not just line DARN
121
+ #name = w.text.split()[0]
122
+ name = w.current_value.split()[0]
123
+ cmd = cmd[0].to_s
124
+ res = %x[ #{m} #{cmd} #{name}].split("\n")
125
+ res ||= "Error in command [#{cmd}] [#{name}] "
126
+ textdialog( res, :title => cmd ) if res
127
+ end
128
+ # handle resizing, sadly I am not sure flow and stack can do a resize, i am sure the xperimental one can.
129
+ def resize
130
+ lb1 = @form.by_name["lb1"]
131
+ lb2 = @form.by_name["lb2"]
132
+ maxc = Ncurses.COLS
133
+ maxr = Ncurses.LINES
134
+ lb1.height = maxr-2
135
+ lb2.height = maxr-2
136
+ lb1.width = ((lb1.width_pc * maxc) / 100).floor
137
+ lb2.width = ((lb2.width_pc * maxc) / 100).floor
138
+ lb2.col = lb1.col + lb1.width
139
+ lab = @form.by_name["lab"]
140
+ lab.row = maxr-1
141
+ end
142
+
143
+ colors = Ncurses.COLORS
144
+ back = :blue
145
+ back = 234 if colors >= 256
146
+ header = app_header "canis #{Canis::VERSION}", :text_center => "Basic List Demo", :text_right =>"New Improved!", :color => :white, :bgcolor => back #, :attr => :bold
147
+ message "Press F10 to escape from here"
148
+ #install_help_text my_help_text
149
+ @form.help_manager.help_text = my_help_text
150
+
151
+ @form.define_prefix_command :csmap, :scope => self
152
+ #@form.define_key(:csmap, "r", 'refresh') { refresh }
153
+ @form.define_key(:csmap, "r", 'refresh', :refresh )
154
+ @form.define_key(:csmap, "s", 'specification') { specification }
155
+ @form.bind_key ?\C-s, :csmap
156
+ #pm = PrefixCommand.new :csmap, self do |p|
157
+ #p.key("r", 'refresh', :refresh )
158
+ #p.key("s", 'specification'){ specification }
159
+ #end
160
+ #@form.bind_key(?\C-x){ pm.call }
161
+ # testing that 'q' works along with 'qq'
162
+ @form.bind_key(?q){ ht = @form.current_widget.help_text || "No help for this widget"; alert ht }
163
+
164
+ # testing triple bindings, along with a fall-back with only two bindings.
165
+ @form.bind_key([?\\, ?\\, ?h]){ ht = @form.current_widget.help_text || "No help for this widget"; alert ht }
166
+ @form.bind_key([?\\, ?\\, ?H]){ ht = @form.current_widget.help_text || "No help for this widget";
167
+ str = get_string("Enter help text:", :default => ht);
168
+ @form.current_widget.help_text = str
169
+ }
170
+ @form.bind_key([?\\, ?\\]){ alert "Enter h for seeing helptext on this widget, H for setting it"; }
171
+
172
+ alist = File.open("data/brew.txt",'r').readlines
173
+ list2 = File.open("data/gemlist.txt",'r').readlines
174
+ lb = nil
175
+
176
+ flow :margin_top => 1, :height => FFI::NCurses.LINES-2 do
177
+ lb = listbox :list => alist, :suppress_borders => false, :title => "[ brew packages ]",
178
+ :left_margin => 0, :width_pc => 50, :name => 'lb1', :selection_mode => :single
179
+ lb.show_selector = false
180
+ lb.help_text = "Brew packages on your system. Use vim keys to navigate, or : to run a command"
181
+
182
+ lb2 = listbox :list => list2, :justify => :left, :title => "[ gems ]", :suppress_borders => false,
183
+ :left_margin => 0, :width_pc => 50, :name => 'lb2'
184
+ end
185
+
186
+
187
+ label({:text => "F1 Help, F10 Quit. : for menu. Press F4 and F5 to test popup, v to select", :row => Ncurses.LINES-1, :col => 0, :name => 'lab'})
188
+
189
+ @form.bind(:RESIZE) { resize() }
190
+ @form.bind_key(FFI::NCurses::KEY_F4, "Popup") { row = lb.visual_index+lb.row; col=lb.col+lb.current_value.length+1;
191
+
192
+ row = [row, FFI::NCurses.LINES - 8].min
193
+ ret = popuplist(%w[ chopin berlioz strauss tchaiko matz beethoven], :row => row, :col => col, :title => "Names", :bgcolor => :blue, :color => :white) ; alert "got #{ret} "}
194
+
195
+ @form.bind_key(FFI::NCurses::KEY_F5, "Popup") { list = %x[ls].split("\n");ret = popuplist(list, :title => "Files"); alert "Got #{ret} #{list[ret]} " }
196
+
197
+ @form.bind_key(?:, "Menu") { disp_menu;
198
+ }
199
+ end # app