canis 0.0.4

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.
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,102 @@
1
+ require 'logger'
2
+ require 'canis'
3
+ require 'canis/core/widgets/rcombo'
4
+ require 'canis/core/include/appmethods.rb'
5
+ def help_text
6
+ <<-eos
7
+ # COMBO HELP
8
+
9
+ This is some help text for |Combos|
10
+
11
+ You may press <SPACE> to invoke the popup and then use arrow keys to traverse. (j and k may also work)
12
+ 'v' on the popup to select (or whatever has been set as $row_selector (#{keycode_tos($row_selector)}) )
13
+
14
+ You may press the first character of the desired item to see all those items starting with that char.
15
+ e.g. pressing "v" will cycle through vt100 and vt102
16
+
17
+
18
+ If the `arrow_key_policy` is set to `:popup` then a down arrow will also invoke popup. However, if you
19
+ prefer the down arrow to go to the next field, use `:ignore`. In that case, only <SPACE> can trigger POPUP.
20
+
21
+ -----------------------------------------------------------------------
22
+ eos
23
+ end
24
+ if $0 == __FILE__
25
+
26
+ include Canis
27
+ include Canis::Utils
28
+
29
+ begin
30
+ # Initialize curses
31
+ Canis::start_ncurses # this is initializing colors via ColorMap.setup
32
+ path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
33
+ file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
34
+ $log = Logger.new(path)
35
+ $log.level = Logger::DEBUG
36
+
37
+ @window = Canis::Window.root_window
38
+ # Initialize few color pairs
39
+ # Create the window to be associated with the form
40
+ # Un post form and free the memory
41
+
42
+ catch(:close) do
43
+ colors = Ncurses.COLORS
44
+ $log.debug "START #{colors} colors testcombo.rb --------- #{@window} "
45
+ @form = Form.new @window
46
+ title = (" "*30) + "Demo of Combo (F10 quits, F1 help, SPACE to popup combo) " + Canis::VERSION
47
+ Label.new @form, {:text => title, :row => 1, :col => 0, :color => :green, :bgcolor => :black}
48
+ r = 3; fc = 12;
49
+
50
+
51
+
52
+ cb = ComboBox.new @form, :row => 7, :col => 2, :width => 20,
53
+ :list => %w[xterm xterm-color xterm-256color screen vt100 vt102],
54
+ :arrow_key_policy => :popup,
55
+ :label => "Declare terminal as: "
56
+
57
+ # arrow_key_policy can be popup or ignore
58
+ # width is used to place combo symbol and popup and should be calculated
59
+ # from label.text
60
+
61
+ @form.help_manager.help_text = help_text
62
+ #@form.bind_key(FFI::NCurses::KEY_F1, 'help') { display_app_help help_text() }
63
+ #@form.bind_key(FFI::NCurses::KEY_F1, 'help') { display_app_help }
64
+ @form.repaint
65
+ @window.wrefresh
66
+ Ncurses::Panel.update_panels
67
+
68
+ # the main loop
69
+
70
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
71
+ break if ch == ?\C-q.getbyte(0)
72
+ begin
73
+ @form.handle_key(ch)
74
+
75
+ rescue => err
76
+ $log.error( err) if err
77
+ $log.error(err.backtrace.join("\n")) if err
78
+ textdialog err
79
+ $error_message.value = ""
80
+ end
81
+
82
+ # this should be avoided, we should not muffle the exception and set a variable
83
+ # However, we have been doing that
84
+ if $error_message.get_value != ""
85
+ alert($error_message, {:bgcolor => :red, 'color' => 'yellow'}) if $error_message.get_value != ""
86
+ $error_message.value = ""
87
+ end
88
+
89
+ @window.wrefresh
90
+ end # while loop
91
+ end # catch
92
+ rescue => ex
93
+ ensure
94
+ $log.debug " -==== EXCEPTION =====-"
95
+ $log.debug( ex) if ex
96
+ $log.debug(ex.backtrace.join("\n")) if ex
97
+ @window.destroy if !@window.nil?
98
+ Canis::stop_ncurses
99
+ puts ex if ex
100
+ puts(ex.backtrace.join("\n")) if ex
101
+ end
102
+ end
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Using tablewidget with sqlite3 resultset
4
+ # TODO : make columns hidden on key - toggle, how to get back then
5
+ # TODO : move column position
6
+ # TODO : filter column
7
+ # TODO : menu on C-x to delete a column, hide unhide expand etc, use pad menu
8
+ require 'logger'
9
+ require 'canis'
10
+ require 'canis/core/widgets/table'
11
+ require 'sqlite3'
12
+ #
13
+ def get_data
14
+ dbname = "movie.sqlite"
15
+ raise unless File.exists? dbname
16
+ db = SQLite3::Database.new(dbname)
17
+ sql = "select * from movie"
18
+ $columns, *rows = db.execute2(sql)
19
+ content = rows
20
+ return nil if content.nil? or content[0].nil?
21
+ $datatypes = content[0].types #if @datatypes.nil?
22
+ return content
23
+ end
24
+
25
+ def edit_row tw
26
+ row = tw.current_value
27
+ h = tw.columns
28
+ _edit h, row, " Edit "
29
+ tw.fire_row_changed tw.current_index
30
+ end
31
+ def insert_row tw
32
+ h = tw.columns
33
+ row = []
34
+ h.each { |e| row << "" }
35
+ ret = _edit h, row, "Insert"
36
+ if ret
37
+ tw.add row
38
+ tw.fire_dimension_changed
39
+ end
40
+ end
41
+
42
+ # making a generic edit messagebox - quick dirty
43
+ def _edit h, row, title
44
+ _l = longest_in_list h
45
+ _w = _l.size
46
+ # _w can be longer than 70, assuming that screen is 70 or more
47
+ config = { :width => 70, :title => title }
48
+ bw = get_color $datacolor, :black, :white
49
+ mb = MessageBox.new config do
50
+ txt = nil
51
+ h.each_with_index { |f, i|
52
+ txt = row[i] || ""
53
+ add LabeledField.new :label => "%*s:" % [_w, f], :text => txt.chomp, :name => i.to_s,
54
+ :bgcolor => :cyan,
55
+ :width => 50,
56
+ :label_color_pair => bw
57
+ }
58
+ button_type :ok_cancel
59
+ end
60
+ index = mb.run
61
+ return nil if index != 0
62
+ h.each_with_index { |e, i|
63
+ f = mb.widget(i.to_s)
64
+ row[i] = f.text
65
+ }
66
+ row
67
+ end
68
+ begin
69
+ # Initialize curses
70
+ Canis::start_ncurses # this is initializing colors via ColorMap.setup
71
+ path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
72
+ logfilename = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
73
+ $log = Logger.new(logfilename)
74
+ $log.level = Logger::DEBUG
75
+
76
+
77
+ colors = Ncurses.COLORS
78
+ back = :black
79
+ lineback = :blue
80
+ back = 234 if colors >= 256
81
+ lineback = 236 if colors >= 256
82
+
83
+ catch(:close) do
84
+ @window = Canis::Window.root_window
85
+ @form = Form.new @window
86
+
87
+ #header = app_header "0.0.1", :text_center => "Movie Database", :text_right =>"" , :name => "header" , :color => :white, :bgcolor => lineback , :attr => :bold
88
+
89
+
90
+
91
+ _col = "#[fg=yellow]"
92
+ $message = Variable.new
93
+ $message.value = ""
94
+ =begin
95
+ @status_line = status_line :row => Ncurses.LINES-1 #, :bgcolor => :red, :color => :yellow
96
+ @status_line.command {
97
+ "#[bg=236, fg=black]#{_col}F1#[/end] Help | #{_col}?#[/end] Keys | #{_col}M-c#[/end] Ask | #{_col}M-d#[/end] History | #{_col}M-m#[/end] Methods | %20s" % [$message.value]
98
+ }
99
+ =end
100
+
101
+ h = FFI::NCurses.LINES-4
102
+ w = FFI::NCurses.COLS
103
+ r = 1
104
+ #header = %w[ Pos Last Title Director Year Country Mins BW]
105
+ #file = "movies1000.txt"
106
+
107
+ arr = get_data
108
+ tv = Canis::Table.new @form, :row => 1, :col => 0, :height => h, :width => w, :name => "tv", :suppress_borders => false do |b|
109
+
110
+ b.resultset $columns, arr
111
+
112
+ b.model_row 1
113
+ b.column_width 0, 5
114
+ #b.get_column(2).color = :red
115
+ #b.get_column(3).color = :yellow
116
+ #b.get_column(2).bgcolor = :blue
117
+ b.column_width 1, 5
118
+ b.column_width 4, 5
119
+ #b.column_width 2, 5
120
+ b.column_align 6, :right
121
+ #b.column_width 2, b.calculate_column_width(2)
122
+ b.column_width 2, 50
123
+ b.column_width 3, 25
124
+ b.column_width 5, 10
125
+ #b.column_width 3, 55
126
+ #b.column_hidden 1, true
127
+ end
128
+ mcr = Canis::DefaultTableRenderer.new tv
129
+ mcr.header_colors :white, :red
130
+ tv.renderer mcr
131
+ mcr.column_model ( tv.column_model )
132
+ tv.create_default_sorter
133
+ tv.move_column 1,-1
134
+
135
+ # pressing ENTER on a method name will popup details for that method
136
+ tv.bind(:PRESS) { |ev|
137
+ if @current_index > 0
138
+ w = ev.word_under_cursor.strip
139
+ w = ev.text
140
+ # the curpos does not correspond to the formatted display, this is just the array
141
+ # without the width info XXX
142
+ alert "#{ev.current_index}, #{ev.curpos}: #{w}"
143
+ end
144
+ }
145
+ tv.bind_key(?e) { edit_row(tv) }
146
+ tv.bind_key(?i) { insert_row(tv) }
147
+ tv.bind_key(?D) { tv.delete_at tv.current_index }
148
+ @form.bind_key(?\M-c, "Filter") {
149
+ tv = @form.by_name["tv"];
150
+ str = get_string "Enter name of director:"
151
+ if str && str.length > 0
152
+ m = tv.matching_indices do |ix, fields|
153
+ fields[3] =~ /#{str}/i
154
+ end
155
+ else
156
+ tv.clear_matches
157
+ end
158
+ }
159
+
160
+
161
+ $message.value = "#{tv.current_index}: #{tv.lastrow}, #{tv.lastcol}"
162
+ @form.repaint
163
+ @window.wrefresh
164
+ Ncurses::Panel.update_panels
165
+ while((ch = @window.getchar()) != KEY_F10 )
166
+ break if ch == ?q.ord || ch == ?\C-q.getbyte(0)
167
+ @form.handle_key(ch)
168
+ $message.value = "#{tv.current_index}: #{tv.lastrow}, #{tv.lastcol}"
169
+ @window.wrefresh
170
+ end
171
+ end
172
+ rescue => ex
173
+ textdialog ["Error in rib: #{ex} ", *ex.backtrace], :title => "Exception"
174
+ $log.debug( ex) if ex
175
+ $log.debug(ex.backtrace.join("\n")) if ex
176
+ ensure
177
+ @window.destroy if !@window.nil?
178
+ Canis::stop_ncurses
179
+ p ex if ex
180
+ p(ex.backtrace.join("\n")) if ex
181
+ end
182
+ # a test renderer to see how things go
@@ -0,0 +1,208 @@
1
+ require 'logger'
2
+ require 'canis'
3
+ require 'canis/core/include/appmethods.rb'
4
+ def help_text
5
+ <<-eos
6
+ # FIELD HELP
7
+
8
+ This is some help text for |Fields|
9
+
10
+ *Name* is non-focusable
11
+ *Line* takes numbers from 1 to 200
12
+ *Regex* takes only alpha
13
+ *Password* takes only scotty or tiger or pass or qwerty, and can be left blank
14
+
15
+ Use Alt (meta) with the highlighted character to jump to that field.
16
+ <Alt-m> goes to line, <Alt-p> to password.
17
+
18
+ Notice how the field label (for first 3 fields) becomes red when focused (as in Pine/Alpine). This uses
19
+ the event `:ENTER` and `:LEAVE` and +set_label+. The other fields use `LabeledField+. In the first 3, the
20
+ labels row and col have not been specified, so are calculated. In the last 3, label's lcol and lrow are
21
+ specified for custom placement.
22
+
23
+
24
+ >
25
+ F10 - Exit application (also C-q)
26
+ Alt-! - Drop to shell
27
+ C-x c - Drop to shell
28
+ C-x l - list of files
29
+ C-x p - process list
30
+ C-x d - disk usage list
31
+ C-x s - Git status
32
+ C-x w - Git whatchanged
33
+ Alt-x - Command mode (<tab> to see commands and select)
34
+
35
+ F3 - View log
36
+ F4 - prompt for unix command and display in viewer
37
+ F5 - Drop to shell
38
+ <
39
+
40
+ -----------------------------------------------------------------------
41
+ eos
42
+ end
43
+ if $0 == __FILE__
44
+
45
+ include Canis
46
+ include Canis::Utils
47
+
48
+ begin
49
+ # Initialize curses
50
+ Canis::start_ncurses # this is initializing colors via ColorMap.setup
51
+ path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
52
+ file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
53
+ $log = Logger.new(path)
54
+ $log.level = Logger::DEBUG
55
+
56
+ @lookfeel = :classic # :dialog # or :classic
57
+
58
+ @window = Canis::Window.root_window
59
+ # Initialize few color pairs
60
+ # Create the window to be associated with the form
61
+ # Un post form and free the memory
62
+
63
+ catch(:close) do
64
+ colors = Ncurses.COLORS
65
+ $log.debug "START #{colors} colors testfield.rb --------- #{@window} "
66
+ @form = Form.new @window
67
+ title = (" "*30) + "Demo of Field (F10 quits, F1 help) " + Canis::VERSION
68
+ Label.new @form, {:text => title, :row => 1, :col => 0, :color => :green, :bgcolor => :black}
69
+ r = 3; fc = 12;
70
+ mnemonics = %w[ n l r p]
71
+ %w[ name line regex password].each_with_index do |w,i|
72
+ field = Field.new @form do
73
+ name w
74
+ row r
75
+ col fc
76
+ width 30
77
+ #text "abcd "
78
+ set_label Label.new @form, {:text => w, :color=> :cyan, :mnemonic => mnemonics[i]}
79
+ end
80
+ r += 1
81
+ end
82
+
83
+ f = @form.by_name["line"]
84
+ f.width(3).text(24).valid_range(1..200).
85
+ maxlen(3).
86
+ type(:integer)
87
+
88
+ @form.by_name["name"].text( "Not focusable").
89
+ focusable(false)
90
+
91
+ @form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/).
92
+ text( "SYNOP").
93
+ width(10).
94
+ maxlen = 20
95
+
96
+ @form.by_name["password"].text("").
97
+ mask('*').
98
+ color(:red).
99
+ values(%w[scotty tiger secret pass qwerty]).
100
+ null_allowed true
101
+
102
+ r += 3
103
+ l1 = Label.new @form, :name => "LabeledField", :attr => 'bold', :text => "Profile", :row => r, :col => fc
104
+ r += 1
105
+ f1 = LabeledField.new @form, :name => "name1", :maxlen => 20, :width => 20, :bgcolor => :white,
106
+ :color => :black, :text => "abc", :label => ' Name: ', :row => r, :col => fc
107
+ r += 1
108
+ f2 = LabeledField.new @form, :name => "email", :width => 20, :bgcolor => :white,
109
+ :color => :blue, :text => "me@google.com", :label => ' Email: ', :row => r, :col => fc
110
+ r += 3
111
+ f3 = LabeledField.new @form
112
+ f3.name("mobile").width(20).bgcolor(:white).color(:black).
113
+ text("").label(' Mobile: ').
114
+ row(r).col(fc).
115
+ type(:integer)
116
+ r += 2
117
+
118
+ LabeledField.new(@form).
119
+ name("landline").width(20).bgcolor(:white).color(:black).
120
+ text("").label('Landline: ').
121
+ row(r).col(fc).
122
+ chars_allowed(/[\d\-]/)
123
+ # a form level event, whenever any widget is focussed, make the label red
124
+ #
125
+
126
+ r += 2
127
+ %w[ profession title department].each_with_index do |w,i|
128
+ LabeledField.new(@form).label(w).width(20).text("").
129
+ bgcolor(:white).color(:black).
130
+ row(r+i).col(fc).lcol(01)
131
+ end
132
+ @form.bind_key(FFI::NCurses::KEY_F3,'view log') {
133
+ require 'canis/core/util/viewer'
134
+ Canis::Viewer.view(path || "canis14.log", :close_key => KEY_ENTER, :title => "<Enter> to close")
135
+ }
136
+ @form.bind_key(FFI::NCurses::KEY_F4, 'system command') { shell_output }
137
+ @form.bind_key(FFI::NCurses::KEY_F5, 'shell') { suspend }
138
+ @form.bind_key([?\C-x,?c], 'shell') { suspend }
139
+ @form.bind_key(?\M-!, 'shell') { suspend }
140
+ @form.bind_key([?\C-x,?l], 'ls -al') { run_command "ls -al" }
141
+ @form.bind_key([?\C-x,?p], 'ps -l') { run_command "ps -l" }
142
+ @form.bind_key([?\C-x,?d], 'df -h') { run_command "df -h" }
143
+ #@form.bind_key([?\C-x,?d], 'git diff') { run_command "git diff --name-status" }
144
+ @form.bind_key([?\C-x, ?s], 'git st') { run_command "git status" }
145
+ @form.bind_key([?\C-x,?w], 'git whatchanged') { run_command "git whatchanged" }
146
+
147
+ @form.help_manager.help_text = help_text
148
+ @form.repaint
149
+ @form.widgets.each { |ff|
150
+ if ff.focusable?
151
+ ff.bind(:ENTER) { |f| f.label && f.label.bgcolor = :red if (f.respond_to? :label and f.label.respond_to?(:bgcolor))}
152
+ ff.bind(:LEAVE) { |f| f.label && f.label.bgcolor = 'black' if (f.respond_to? :label and f.label.respond_to?(:bgcolor))}
153
+ end
154
+ }
155
+ @window.wrefresh
156
+ Ncurses::Panel.update_panels
157
+
158
+ # the main loop
159
+
160
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
161
+ break if ch == ?\C-q.getbyte(0)
162
+ begin
163
+ @form.handle_key(ch)
164
+
165
+ rescue FieldValidationException => fve
166
+ #alert fve.to_s
167
+ textdialog fve
168
+
169
+ f = @form.get_current_field
170
+ # lets restore the value
171
+ if f.respond_to? :restore_original_value
172
+ f.restore_original_value
173
+ #@form.select_field @form.active_index
174
+ @form.repaint
175
+ end
176
+ $error_message.value = ""
177
+ rescue => err
178
+ $log.error( err) if err
179
+ $log.error(err.backtrace.join("\n")) if err
180
+ textdialog err
181
+ $error_message.value = ""
182
+ end
183
+
184
+ # this should be avoided, we should not muffle the exception and set a variable
185
+ # However, we have been doing that
186
+ if $error_message.get_value != ""
187
+ if @lookfeel == :dialog
188
+ alert($error_message, {:bgcolor => :red, 'color' => 'yellow'}) if $error_message.get_value != ""
189
+ else
190
+ print_error_message $error_message, {:bgcolor => :red, :color => :yellow}
191
+ end
192
+ $error_message.value = ""
193
+ end
194
+
195
+ @window.wrefresh
196
+ end # while loop
197
+ end # catch
198
+ rescue => ex
199
+ ensure
200
+ $log.debug " -==== EXCEPTION =====-" if ex
201
+ $log.debug( ex) if ex
202
+ $log.debug(ex.backtrace.join("\n")) if ex
203
+ @window.destroy if !@window.nil?
204
+ Canis::stop_ncurses
205
+ puts ex if ex
206
+ puts(ex.backtrace.join("\n")) if ex
207
+ end
208
+ end