rbcurse 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +20 -0
  2. data/NOTES +45 -0
  3. data/README.markdown +47 -68
  4. data/TODO2.txt +29 -32
  5. data/VERSION +1 -1
  6. data/examples/abasiclist.rb +2 -0
  7. data/examples/app.rb +2 -2
  8. data/examples/app.sample +10 -0
  9. data/examples/appemail.rb +29 -2
  10. data/examples/appemaillb.rb +1 -1
  11. data/examples/appgcompose.rb +9 -2
  12. data/examples/appmethods.rb +69 -0
  13. data/examples/atree.rb +2 -2
  14. data/examples/menu1.rb +1 -1
  15. data/examples/newtesttabp.rb +8 -5
  16. data/examples/qdfilechooser.rb +6 -3
  17. data/examples/rfe.rb +71 -16
  18. data/examples/rmail.rb +76 -7
  19. data/examples/sqlc.rb +14 -3
  20. data/examples/sqlm.rb +3 -3
  21. data/examples/term.rb +48 -0
  22. data/examples/term2.rb +48 -21
  23. data/examples/test1.rb +2 -2
  24. data/examples/test2.rb +162 -71
  25. data/examples/testapp.rb +2 -2
  26. data/examples/testapp2.rb +1 -1
  27. data/examples/testchars.rb +47 -46
  28. data/examples/testcombo.rb +2 -2
  29. data/examples/testkeypress.rb +2 -2
  30. data/examples/testlistbox.rb +2 -2
  31. data/examples/testmenu.rb +1 -1
  32. data/examples/testmulticomp.rb +1 -1
  33. data/examples/testmultispl.rb +1 -1
  34. data/examples/testree.rb +1 -22
  35. data/examples/testscroller.rb +2 -2
  36. data/examples/testscrolllb.rb +2 -2
  37. data/examples/testscrollp.rb +2 -2
  38. data/examples/testscrollta.rb +2 -2
  39. data/examples/testscrolltable.rb +2 -2
  40. data/examples/testsplit.rb +2 -2
  41. data/examples/testsplit2.rb +2 -2
  42. data/examples/testsplit3.rb +2 -2
  43. data/examples/testsplit3_1.rb +2 -2
  44. data/examples/testsplit3a.rb +2 -2
  45. data/examples/testsplit3b.rb +2 -2
  46. data/examples/testsplitta.rb +2 -2
  47. data/examples/testsplittv.rb +2 -2
  48. data/examples/testsplittvv.rb +2 -2
  49. data/examples/testtable.rb +2 -2
  50. data/examples/testtabp.rb +2 -2
  51. data/examples/testtodo.rb +1 -1
  52. data/examples/testtpane.rb +2 -2
  53. data/examples/testtpane2.rb +2 -2
  54. data/examples/testtpanetable.rb +6 -5
  55. data/examples/testvimsplit.rb +2 -2
  56. data/examples/viewtodo.rb +1 -1
  57. data/lib/rbcurse.rb +2 -1
  58. data/lib/rbcurse/action.rb +1 -1
  59. data/lib/rbcurse/app.rb +51 -14
  60. data/lib/rbcurse/applicationheader.rb +1 -1
  61. data/lib/rbcurse/celleditor.rb +1 -1
  62. data/lib/rbcurse/colormap.rb +11 -11
  63. data/lib/rbcurse/comboboxcellrenderer.rb +1 -1
  64. data/lib/rbcurse/extras/bottomline.rb +22 -10
  65. data/lib/rbcurse/extras/directorylist.rb +14 -1
  66. data/lib/rbcurse/extras/divider.rb +1 -1
  67. data/lib/rbcurse/extras/listselectable.rb +2 -2
  68. data/lib/rbcurse/extras/masterdetail.rb +3 -1
  69. data/lib/rbcurse/extras/scrollbar.rb +1 -1
  70. data/lib/rbcurse/extras/stdscrwindow.rb +75 -24
  71. data/lib/rbcurse/extras/tabular.rb +8 -3
  72. data/lib/rbcurse/extras/viewer.rb +18 -2
  73. data/lib/rbcurse/io.rb +26 -13
  74. data/lib/rbcurse/keylabelprinter.rb +3 -2
  75. data/lib/rbcurse/listcellrenderer.rb +1 -0
  76. data/lib/rbcurse/listkeys.rb +3 -2
  77. data/lib/rbcurse/listselectable.rb +4 -3
  78. data/lib/rbcurse/rbasiclistbox.rb +12 -5
  79. data/lib/rbcurse/rcombo.rb +2 -2
  80. data/lib/rbcurse/rcommandwindow.rb +5 -3
  81. data/lib/rbcurse/rdialogs.rb +8 -2
  82. data/lib/rbcurse/rlistbox.rb +10 -2
  83. data/lib/rbcurse/rmenu.rb +4 -4
  84. data/lib/rbcurse/rmessagebox.rb +10 -5
  85. data/lib/rbcurse/rmulticontainer.rb +21 -8
  86. data/lib/rbcurse/rmultisplit.rb +2 -2
  87. data/lib/rbcurse/rmultitextview.rb +5 -3
  88. data/lib/rbcurse/rpopupmenu.rb +3 -3
  89. data/lib/rbcurse/rprogress.rb +3 -2
  90. data/lib/rbcurse/rscrollform.rb +2 -2
  91. data/lib/rbcurse/rscrollpane.rb +9 -9
  92. data/lib/rbcurse/rsplitpane.rb +2 -2
  93. data/lib/rbcurse/rsplitpane2.rb +2 -2
  94. data/lib/rbcurse/rtabbedpane.rb +48 -12
  95. data/lib/rbcurse/rtabbedwindow.rb +4 -4
  96. data/lib/rbcurse/rtable.rb +6 -3
  97. data/lib/rbcurse/rtextarea.rb +8 -8
  98. data/lib/rbcurse/rtextview.rb +3 -2
  99. data/lib/rbcurse/rtree.rb +2 -2
  100. data/lib/rbcurse/rviewport.rb +2 -2
  101. data/lib/rbcurse/rvimsplit.rb +3 -2
  102. data/lib/rbcurse/rwidget.rb +63 -26
  103. data/lib/rbcurse/scrollable.rb +1 -1
  104. data/lib/rbcurse/table/tablecellrenderer.rb +1 -1
  105. data/lib/rbcurse/table/tabledatecellrenderer.rb +1 -1
  106. data/lib/rbcurse/tree/treemodel.rb +1 -1
  107. data/lib/rbcurse/vieditable.rb +1 -0
  108. data/lib/ver/ncurses.rb +122 -4
  109. data/lib/ver/panel.rb +162 -0
  110. data/lib/ver/window.rb +262 -120
  111. metadata +19 -7
  112. data/examples/keytest.rb +0 -178
  113. data/examples/mpad2.rb +0 -156
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'ncurses'
2
+ #require 'ncurses'
3
3
  require 'logger'
4
4
  #require 'lib/rbcurse/rwidget'
5
5
 
@@ -1,21 +1,21 @@
1
- require 'rubygems'
2
1
  require 'ver/ncurses'
3
2
  module ColorMap
4
3
  # 2010-09-20 12:22 changed colors from string to symbol
5
4
  ## private
6
5
  # returns a color constant for a human color string
7
6
  def ColorMap.get_color_const colorstring
8
- Ncurses.const_get "COLOR_#{colorstring.upcase}"
7
+ ret = FFI::NCurses.const_get "COLOR_#{colorstring.upcase}"
8
+ #raise "color const nil ColorMap 8 " if !ret
9
9
  end
10
10
  ## private
11
11
  # creates a new color pair, puts in color map and returns color_pair
12
12
  # number
13
13
  def ColorMap.install_color fgc, bgc
14
- # $log.debug " install_color found #{fgc} #{@bgc} "
14
+ #$log.debug " install_color found #{fgc} #{@bgc} "
15
15
  @color_id += 1
16
16
  fg = ColorMap.get_color_const fgc
17
17
  bg = ColorMap.get_color_const bgc
18
- Ncurses.init_pair(@color_id, fg, bg);
18
+ FFI::NCurses.init_pair(@color_id, fg, bg);
19
19
  $color_map[[fgc, bgc]] = @color_id
20
20
  return @color_id
21
21
  end
@@ -36,10 +36,10 @@ module ColorMap
36
36
  fgc = fgc.to_sym if fgc.is_a? String
37
37
  bgc = bgc.to_sym if bgc.is_a? String
38
38
  if $color_map.include? [fgc, bgc]
39
- # $log.debug " get_color found #{fgc} #{@bgc} "
39
+ #$log.debug " get_color found #{fgc} #{@bgc} "
40
40
  return $color_map[[fgc, bgc]]
41
41
  else
42
- # $log.debug " get_color NOT found #{fgc} #{@bgc} "
42
+ #$log.debug " get_color NOT found #{fgc} #{@bgc} "
43
43
  return ColorMap.install_color fgc, bgc
44
44
  end
45
45
  end
@@ -58,7 +58,7 @@ module ColorMap
58
58
  def ColorMap.setup
59
59
  @color_id = 0
60
60
  $color_map = {}
61
- Ncurses.start_color();
61
+ FFI::NCurses.start_color();
62
62
  # Initialize few color pairs
63
63
  $def_fg_color = :white # pls set these 2 for your application
64
64
  $def_bg_color = :black
@@ -92,14 +92,14 @@ module ColorMap
92
92
  end # modul
93
93
  if $0 == __FILE__
94
94
  require 'logger'
95
- require 'lib/ver/window'
96
- include Ncurses
95
+ require 'ver/window'
96
+ #include Ncurses # FFI 2011-09-8
97
97
  include ColorMap
98
98
  # Initialize curses
99
99
  begin
100
+ $log = Logger.new("rbc13.log")
100
101
  VER::start_ncurses
101
102
  @window = VER::Window.root_window
102
- $log = Logger.new("view.log")
103
103
  $log.level = Logger::DEBUG
104
104
  ColorMap.setup
105
105
 
@@ -115,7 +115,7 @@ include ColorMap
115
115
 
116
116
 
117
117
 
118
- while((ch = @window.getchar()) != KEY_F1 )
118
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F1 )
119
119
  next if ch == -1
120
120
  break if ch == ?q.getbyte(0)
121
121
  case ch
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'ncurses'
2
+ #require 'ncurses'
3
3
  require 'logger'
4
4
  #require 'lib/rbcurse/rwidget'
5
5
  module RubyCurses
@@ -1076,7 +1076,7 @@ module RubyCurses
1076
1076
  #win.mvprintw(x, y, "%-40s" % text);
1077
1077
  win.mvprintw(x, y, "%s" % text);
1078
1078
  win.attroff(color);
1079
- win.refresh
1079
+ win.refresh # FFI NW 2011-09-9 , added back gets overwritten
1080
1080
  end
1081
1081
 
1082
1082
  # actual input routine, gets each character from user, taking care of echo, limit,
@@ -1094,7 +1094,7 @@ module RubyCurses
1094
1094
  maxlen = @limit || 100 # fixme
1095
1095
 
1096
1096
 
1097
- raise "rbgetstr got no window. io.rb" if win.nil?
1097
+ raise "rbgetstr got no window. bottomline.rb" if win.nil?
1098
1098
  ins_mode = false
1099
1099
  oldstr = nil # for tab completion, origal word entered by user
1100
1100
  default = @default || ""
@@ -1122,7 +1122,7 @@ module RubyCurses
1122
1122
  entries = nil
1123
1123
  while true
1124
1124
  ch=win.getchar()
1125
- #$log.debug " rbgetstr got ch:#{ch}, str:#{str}. "
1125
+ $log.debug " XXXX FFI rbgetstr got ch:#{ch}, str:#{str}. "
1126
1126
  case ch
1127
1127
  when 3 # -1 # C-c # sometimes this causes an interrupt and crash
1128
1128
  return -1, nil
@@ -1131,7 +1131,8 @@ module RubyCurses
1131
1131
  when 10, 13 # hits ENTER, complete entry and return
1132
1132
  @history_list.push str
1133
1133
  break
1134
- when ?\C-h.getbyte(0), ?\C-?.getbyte(0), KEY_BSPACE # delete previous character/backspace
1134
+ when ?\C-h.getbyte(0), ?\C-?.getbyte(0), KEY_BSPACE, 263 # delete previous character/backspace
1135
+ # C-h is giving 263 i/o 8. 2011-09-19
1135
1136
  len -= 1 if len > @prompt_length
1136
1137
  curpos -= 1 if curpos > 0
1137
1138
  str.slice!(curpos)
@@ -1149,13 +1150,13 @@ module RubyCurses
1149
1150
  when KEY_LEFT
1150
1151
  curpos -= 1 if curpos > 0
1151
1152
  len -= 1 if len > @prompt_length
1152
- win.wmove r, c+len # since getchar is not going back on del and bs
1153
+ win.move r, c+len # since getchar is not going back on del and bs wmove to move FFIWINDOW
1153
1154
  next
1154
1155
  when KEY_RIGHT
1155
1156
  if curpos < str.length
1156
1157
  curpos += 1 #if curpos < str.length
1157
1158
  len += 1
1158
- win.wmove r, c+len # since getchar is not going back on del and bs
1159
+ win.move r, c+len # since getchar is not going back on del and bs
1159
1160
  end
1160
1161
  next
1161
1162
  when ?\C-a.getbyte(0)
@@ -1163,13 +1164,13 @@ module RubyCurses
1163
1164
  clear_line len+maxlen+1, @prompt_length
1164
1165
  len -= curpos
1165
1166
  curpos = 0
1166
- win.wmove r, c+len # since getchar is not going back on del and bs
1167
+ win.move r, c+len # since getchar is not going back on del and bs
1167
1168
  when ?\C-e.getbyte(0)
1168
1169
  olen = str.length
1169
1170
  len += (olen - curpos)
1170
1171
  curpos = olen
1171
1172
  clear_line len+maxlen+1, @prompt_length
1172
- win.wmove r, c+len # since getchar is not going back on del and bs
1173
+ win.move r, c+len # since getchar is not going back on del and bs
1173
1174
 
1174
1175
  when ?\M-i.getbyte(0)
1175
1176
  ins_mode = !ins_mode
@@ -1310,7 +1311,10 @@ module RubyCurses
1310
1311
  begin
1311
1312
  cpentries = @change_proc.call(str) if @change_proc # added 2010-11-09 23:28
1312
1313
  rescue => exc
1313
- $log.debug "bottomline: change_proc EXC #{exc} " if $log.debug?
1314
+ $log.error "bottomline: change_proc EXC #{exc} " if $log.debug?
1315
+ $log.error( exc) if exc
1316
+ $log.error(exc.backtrace.join("\n")) if exc
1317
+ Ncurses.error
1314
1318
  end
1315
1319
  print_str(str, :y => @prompt_length+0)
1316
1320
  when false
@@ -1318,9 +1322,11 @@ module RubyCurses
1318
1322
  else
1319
1323
  print_str(@question.echo * str.length, :y => @prompt_length+0)
1320
1324
  end
1321
- win.wmove r, c+len # more for arrow keys, curpos may not be end
1325
+ win.move r, c+len # more for arrow keys, curpos may not be end
1322
1326
  prevchar = ch
1323
1327
  end
1328
+ $log.debug "XXXW bottomline: after while loop"
1329
+
1324
1330
  str = default if str == ""
1325
1331
  ensure
1326
1332
  Ncurses.noecho();
@@ -1416,10 +1422,12 @@ module RubyCurses
1416
1422
  val = list1[ret-1]
1417
1423
  if val.is_a? Array
1418
1424
  retval << val[0]
1425
+ $log.debug "NL: #{retval} "
1419
1426
  list1 = val[1..-1]
1420
1427
  rc.clear
1421
1428
  else
1422
1429
  retval << val
1430
+ $log.debug "NL1: #{retval} "
1423
1431
  break
1424
1432
  end
1425
1433
  end
@@ -1428,6 +1436,7 @@ module RubyCurses
1428
1436
  rc = nil
1429
1437
  end
1430
1438
  #list1[ret-1]
1439
+ $log.debug "NL2: #{retval} , #{retval.class} "
1431
1440
  retval
1432
1441
  end
1433
1442
  # Allows a selection in which options are shown over prompt. As user types
@@ -1456,6 +1465,7 @@ module RubyCurses
1456
1465
  begin
1457
1466
  w = rc.window
1458
1467
  rc.display_menu list1
1468
+ # earlier wmove bombed, now move is (window.rb 121)
1459
1469
  str = ask(prompt) { |q| q.change_proc = Proc.new { |str| w.wmove(1,1) ; w.wclrtobot; l = list1.select{|e| e.index(str)==0} ; rc.display_menu l; l} }
1460
1470
  # need some validation here that its in the list TODO
1461
1471
  ensure
@@ -1477,6 +1487,8 @@ module RubyCurses
1477
1487
  rc = nil
1478
1488
  end
1479
1489
  #def display_list_interactive text, config={}
1490
+ # returns a ListObject since you may not know what the list itself contained
1491
+ # You can do ret.list[ret.current_index] to get value
1480
1492
  def display_list text, config={}
1481
1493
  require 'rbcurse/rcommandwindow'
1482
1494
  ht = config[:height] || 15
@@ -83,7 +83,10 @@ module RubyCurses
83
83
  list @entries
84
84
  @list.insert 0, @_header
85
85
  @title = @current_path
86
- @current_index = @_first_data_index
86
+ #@current_index = @_first_data_index
87
+ # this next line will keep the cursor on header after sorting
88
+ # earlier cursor would appear in header but selection would be data row
89
+ @current_index = @_header_row_index # FFI 2011-09-16 keeping cursor synched with selection
87
90
  end
88
91
  # called by parent's repaint
89
92
  def convert_value_to_text file, crow
@@ -213,6 +216,7 @@ module RubyCurses
213
216
  Ncurses.error
214
217
  return
215
218
  end
219
+ $log.debug "inside fire_action_event of directorylist #{@current_index} #{toprow} "
216
220
  if @_header_row_index == @current_index
217
221
  # user hit enter on the header row. we determine column and sort.
218
222
  header = _get_word_under_cursor
@@ -236,6 +240,7 @@ module RubyCurses
236
240
  if File.directory? _path
237
241
  populate _path
238
242
  end
243
+ $log.debug "after fire_action_event of directorylist #{@current_index} #{toprow} "
239
244
 
240
245
  super
241
246
  end
@@ -337,7 +342,12 @@ module RubyCurses
337
342
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
338
343
  return if ret != 0
339
344
  @file_pattern = str
345
+ # 2011-09-19 doesn't work if pwd changed
346
+ if Dir.pwd != @current_path
347
+ Dir.chdir @current_path
348
+ end
340
349
  values = Dir.glob(str)
350
+ $log.debug "ask select dir.glob got #{values} "
341
351
  select_values values unless values.empty?
342
352
  @repaint_required = true
343
353
  end
@@ -349,6 +359,9 @@ module RubyCurses
349
359
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
350
360
  return if ret != 0
351
361
  @file_pattern = str
362
+ if Dir.pwd != @current_path
363
+ Dir.chdir @current_path
364
+ end
352
365
  values = Dir.glob(str)
353
366
  unselect_values values unless values.empty?
354
367
  @repaint_required = true
@@ -1,5 +1,5 @@
1
1
  require 'rbcurse/app'
2
- include Ncurses
2
+ #include Ncurses # FFI 2011-09-8
3
3
  include RubyCurses
4
4
 
5
5
  # TODO : We can consider making it independent of objects, or allow for a margin so it does not write
@@ -175,7 +175,7 @@ module RubyCurses
175
175
  @repaint_required = true
176
176
  end
177
177
  def get_matching_indices pattern
178
- alert "please implement this method get_matching_indices in your class "
178
+ alert "please implement this method get_matching_indices(pattern)->[] in your class "
179
179
  return []
180
180
  end # mod
181
181
  # Applications may call this or just copy and modify
@@ -185,7 +185,7 @@ module RubyCurses
185
185
  bind_key(32) { toggle_row_selection }
186
186
  bind_key(0) { add_to_selection }
187
187
  bind_key(?+, :ask_select) # --> calls select_values
188
- bind_key(?-, :ask_unselect)
188
+ bind_key(?-, :ask_unselect) # please implement FIXME TODO
189
189
  bind_key(?a, :select_all)
190
190
  bind_key(?*, :invert_selection)
191
191
  bind_key(?u, :clear_selection)
@@ -91,7 +91,7 @@ class MasterDetail < Widget
91
91
  #s.add @right1, :SECOND
92
92
  #s.add @right2, :SECOND
93
93
  s.bind :COMPONENT_RESIZE_EVENT do |e|
94
- #alert "got a resize event #{e.type} "
94
+ alert "masterdetail got a resize event #{e.type}, #{e.source} "
95
95
  case e.type
96
96
  when :INCREASE
97
97
  case e.source
@@ -100,6 +100,7 @@ class MasterDetail < Widget
100
100
  when @right1
101
101
  increase_headers
102
102
  when @left
103
+ alert "masterdetail left increase - not handled"
103
104
 
104
105
  end
105
106
  when :DECREASE
@@ -117,6 +118,7 @@ class MasterDetail < Widget
117
118
  @right2.repaint_required true
118
119
  @right1.repaint_required true
119
120
  @left.repaint_required true
121
+ alert "masterdetail left decrease"
120
122
  end
121
123
  when :EXPAND
122
124
  case e.source
@@ -1,5 +1,5 @@
1
1
  require 'rbcurse/app'
2
- include Ncurses
2
+ #include Ncurses # FFI 2011-09-8
3
3
  include RubyCurses
4
4
 
5
5
  # This paints a vertical white bar given row and col, and length. It also calculates and prints
@@ -9,12 +9,18 @@ module RubyCurses
9
9
  # We should be able to pass this window to bottomline and have one global bottomline
10
10
  # created once (by window class ?)
11
11
  #
12
+ # FFI: 2011-09-9 The change to FFI has affected this a lot since I do not get window
13
+ # methods in rbcurse for stdscr whereas suprisingly if i run the samples, i get them
14
+ # all.
12
15
  class StdscrWindow
13
16
  attr_reader :width, :height, :top, :left
14
17
 
15
18
  def initialize
16
19
 
17
- @window = Ncurses.stdscr
20
+ #@window_pointer = FFI::NCurses.initscr
21
+ @window_pointer = Ncurses.initscr # FFIWINDOW
22
+ $log.debug "STDSCR window pointer is #{@window_pointer.class}"
23
+ #$log.debug "STDSCR window pointer mehtods #{@window_pointer.public_methods}"
18
24
  $error_message_row ||= Ncurses.LINES-1
19
25
  $error_message_col ||= 1
20
26
  init_vars
@@ -22,29 +28,63 @@ module RubyCurses
22
28
 
23
29
  end
24
30
  def init_vars
25
- Ncurses::keypad(@window, true)
31
+ #Ncurses::keypad(@window_pointer, true)
32
+ Ncurses.keypad(@window_pointer.pointer, true)
26
33
  @stack = []
27
34
  end
28
35
  ##
29
36
 
30
37
  # Ncurses
31
38
 
32
- def method_missing(meth, *args)
33
- @window.send(meth, *args)
39
+
40
+ # taken from Window
41
+ def method_missing(name, *args)
42
+ name = name.to_s
43
+ if (name[0,2] == "mv")
44
+ test_name = name.dup
45
+ test_name[2,0] = "w" # insert "w" after"mv"
46
+ if (@window_pointer.respond_to?(test_name)) # FFIPOINTER
47
+ return @window_pointer.send(test_name,*args)
48
+ end
49
+
50
+ if (FFI::NCurses.respond_to?(test_name))
51
+ return FFI::NCurses.send(test_name, @window_pointer, *args)
52
+ end
53
+ end
54
+ test_name = "w" + name
55
+ # FFI responds but the pointer does not !!! bottomline 1045
56
+ if (@window_pointer.respond_to?(test_name)) # FFIPOINTER
57
+ return @window_pointer.send(test_name,*args)
58
+ end
59
+ if (FFI::NCurses.respond_to?(test_name))
60
+ return FFI::NCurses.send(test_name, @window_pointer, *args)
61
+ end
62
+ # what if it does not respond, can go into loop and give stack overflow
63
+ FFI::NCurses.send(name, @window_pointer, *args)
64
+ end
65
+ def respond_to?(name)
66
+ name = name.to_s
67
+ if (name[0,2] == "mv" && FFI::NCurses.respond_to?("mvw" + name[2..-1]))
68
+ return true
69
+ end
70
+ FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name)
34
71
  end
72
+ #@window.send(meth, *args)
35
73
 
74
+ # FFI WARNING XXX I think these methods one window_pointer will fail
75
+ # since somehow stdscr is not getting these methods here.
36
76
  def print(string, width = width)
37
77
  return unless visible?
38
- @window.waddnstr(string.to_s, width)
78
+ @window_pointer.waddnstr(string.to_s, width)
39
79
  end
40
80
 
41
81
  def print_yx(string, y = 0, x = 0)
42
- @window.mvwaddnstr(y, x, string, width)
82
+ @window_pointer.mvwaddnstr(y, x, string, width)
43
83
  end
44
84
 
45
85
  def print_empty_line
46
86
  return unless visible?
47
- @window.printw(' ' * width)
87
+ @window_pointer.printw(' ' * width)
48
88
  end
49
89
 
50
90
  def print_line(string)
@@ -55,27 +95,37 @@ module RubyCurses
55
95
  print(strings.join("\n") << "\n")
56
96
  end
57
97
 
58
- def refresh
59
- @window.refresh
98
+ # FFI 2011-09-9 commented off so it goes to method missing
99
+ def XXXrefresh
100
+ @window_pointer.refresh
60
101
  end
61
102
 
62
103
 
63
104
  def color=(color)
64
105
  @color = color
65
- @window.color_set(color, nil)
106
+ @window_pointer.color_set(color, nil)
66
107
  end
67
108
 
68
109
  def highlight_line(color, y, x, max)
69
- @window.mvchgat(y, x, max, Ncurses::A_NORMAL, color, nil)
110
+ @window_pointer.mvchgat(y, x, max, FFI::NCurses::A_NORMAL, color, nil)
70
111
  end
71
112
 
72
113
  def ungetch(ch)
73
- Ncurses.ungetch(ch)
114
+ FFI::NCurses.ungetch(ch)
74
115
  end
75
116
 
117
+ # this used to work fine in ncursesruby
118
+ # but somehow in ffi, stdscr does not have most methods, i am unable to figure
119
+ # this out. C-c will crash this.
76
120
  def getch
77
- c = @window.getch
78
- #if c == Ncurses::KEY_RESIZE
121
+ c = @window_pointer.getch # FFI NW stdscr must get key not some window
122
+ #raise "Ncurses.stdscr does not have getch" if !Ncurses.stdscr.respond_to? :getch
123
+ #$log.debug " XXXX before calling getch"
124
+ #c = Ncurses.stdscr.getch # FFIW if you use the FFIWINDOW
125
+ #c = FFI::NCurses.getch # FFI 2011-09-9 # without FFIWINDOW
126
+ #$log.debug " XXXX after calling getch #{c}"
127
+ #if c == FFI::NCurses::KEY_RESIZE
128
+ return c
79
129
  rescue Interrupt => ex
80
130
  3 # is C-c
81
131
  end
@@ -85,8 +135,9 @@ module RubyCurses
85
135
  # Please test with above combinations before using on your terminal
86
136
  # added by rkumar 2008-12-12 23:07
87
137
  def getchar
138
+ FFI::NCurses.raw # FFI required so that getch does not crash on C-c
88
139
  while 1
89
- ch = getch
140
+ ch = getch
90
141
  #$log.debug "window getchar() GOT: #{ch}" if ch != -1
91
142
  if ch == -1
92
143
  # the returns escape 27 if no key followed it, so its SLOW if you want only esc
@@ -174,26 +225,26 @@ module RubyCurses
174
225
  # @param color - color pair
175
226
  # @ param att - ncurses attribute: normal, bold, reverse, blink,
176
227
  # underline
177
- def printstring(r,c,string, color, att = Ncurses::A_NORMAL)
228
+ def printstring(r,c,string, color, att = FFI::NCurses::A_NORMAL)
178
229
  prv_printstring(r,c,string, color, att )
179
230
  end
180
231
 
181
232
  ## name changed from printstring to prv_prinstring
182
- def prv_printstring(r,c,string, color, att = Ncurses::A_NORMAL)
233
+ def prv_printstring(r,c,string, color, att = FFI::NCurses::A_NORMAL)
183
234
 
184
235
  #$log.debug " #{@name} inside window printstring r #{r} c #{c} #{string} "
185
- att = Ncurses::A_NORMAL if att.nil?
236
+ att = FFI::NCurses::A_NORMAL if att.nil?
186
237
  case att.to_s.downcase
187
238
  when 'normal'
188
- att = Ncurses::A_NORMAL
239
+ att = FFI::NCurses::A_NORMAL
189
240
  when 'underline'
190
- att = Ncurses::A_UNDERLINE
241
+ att = FFI::NCurses::A_UNDERLINE
191
242
  when 'bold'
192
- att = Ncurses::A_BOLD
243
+ att = FFI::NCurses::A_BOLD
193
244
  when 'blink'
194
- att = Ncurses::A_BLINK # unlikely to work
245
+ att = FFI::NCurses::A_BLINK # unlikely to work
195
246
  when 'reverse'
196
- att = Ncurses::A_REVERSE
247
+ att = FFI::NCurses::A_REVERSE
197
248
  end
198
249
 
199
250
  attron(Ncurses.COLOR_PAIR(color) | att)
@@ -241,7 +292,7 @@ module RubyCurses
241
292
  $error_message_clear_pending = false
242
293
  end
243
294
  ##
244
- def get_window; @window; end
295
+ def get_window; @window_pointer; end
245
296
  def to_s; @name || self; end
246
297
  end
247
298
  end