rbcurse 1.4.0 → 1.4.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/NOTES +68 -0
  2. data/README.markdown +73 -330
  3. data/TODO2.txt +2 -2
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +8 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +1 -24
  8. data/examples/appdirtree.rb +1 -1
  9. data/examples/appemail.rb +8 -14
  10. data/examples/appemaillb.rb +2 -2
  11. data/examples/appgcompose.rb +7 -5
  12. data/examples/common/file.rb +40 -0
  13. data/examples/{rmail.rb → common/rmail.rb} +0 -0
  14. data/examples/data/README.markdown +9 -0
  15. data/examples/data/brew.txt +38 -0
  16. data/examples/data/color.2 +37 -0
  17. data/examples/data/gemlist.txt +60 -0
  18. data/examples/data/lotr.txt +12 -0
  19. data/examples/data/ports.txt +136 -0
  20. data/examples/data/tasks.txt +27 -0
  21. data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
  22. data/examples/data/unix1.txt +21 -0
  23. data/examples/data/unix2.txt +11 -0
  24. data/examples/dbdemo.rb +49 -14
  25. data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
  26. data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
  27. data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
  28. data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
  29. data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
  30. data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
  31. data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
  32. data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
  33. data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
  34. data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
  35. data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
  36. data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
  37. data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
  38. data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
  39. data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
  40. data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
  41. data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
  42. data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
  43. data/examples/dirtree.rb +17 -7
  44. data/examples/experimental/resultsetdemo.rb +280 -0
  45. data/examples/experimental/testmform.rb +35 -0
  46. data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
  47. data/examples/experimental/teststackflow.rb +111 -0
  48. data/examples/menu1.rb +1 -0
  49. data/examples/multispl.rb +4 -4
  50. data/examples/newmessagebox.rb +130 -0
  51. data/examples/newtabbedwindow.rb +100 -0
  52. data/examples/newtesttabp.rb +0 -3
  53. data/examples/qdfilechooser.rb +0 -3
  54. data/examples/rfe.rb +134 -18
  55. data/examples/rfe_renderer.rb +48 -2
  56. data/examples/sqlc.rb +2 -1
  57. data/examples/sqlm.rb +0 -2
  58. data/examples/table1.rb +1 -7
  59. data/examples/term2.rb +4 -1
  60. data/examples/test1.rb +0 -5
  61. data/examples/test2.rb +42 -31
  62. data/examples/testapp2.rb +8 -1
  63. data/examples/testchars.rb +0 -4
  64. data/examples/testcombo.rb +5 -9
  65. data/examples/testkeypress.rb +0 -3
  66. data/examples/testmenu.rb +0 -4
  67. data/examples/testmulticomp.rb +3 -5
  68. data/examples/testmulticontainer.rb +94 -0
  69. data/examples/testtable.rb +0 -5
  70. data/examples/testtabp.rb +16 -18
  71. data/examples/testtodo.rb +1 -5
  72. data/examples/testwsshortcuts.rb +64 -0
  73. data/examples/testwsshortcuts2.rb +126 -0
  74. data/examples/viewtodo.rb +1 -4
  75. data/lib/rbcurse.rb +1 -1
  76. data/lib/rbcurse/app.rb +92 -69
  77. data/lib/rbcurse/applicationheader.rb +46 -6
  78. data/lib/rbcurse/celleditor.rb +1 -9
  79. data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
  80. data/lib/rbcurse/common/ansiparser.rb +117 -0
  81. data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
  82. data/lib/rbcurse/common/basestack.rb +407 -0
  83. data/lib/rbcurse/common/bordertitle.rb +41 -0
  84. data/lib/rbcurse/common/chunk.rb +177 -0
  85. data/lib/rbcurse/common/colorparser.rb +71 -0
  86. data/lib/rbcurse/common/keydefs.rb +30 -0
  87. data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
  88. data/lib/rbcurse/deprecated/README.markdown +12 -0
  89. data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
  90. data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
  91. data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
  92. data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
  93. data/lib/rbcurse/experimental/README.markdown +14 -0
  94. data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
  95. data/lib/rbcurse/experimental/stackflow.rb +478 -0
  96. data/lib/rbcurse/extras/bottomline.rb +85 -16
  97. data/lib/rbcurse/extras/box.rb +58 -0
  98. data/lib/rbcurse/extras/directorylist.rb +1 -1
  99. data/lib/rbcurse/extras/horizlist.rb +203 -0
  100. data/lib/rbcurse/extras/listselectable.rb +8 -0
  101. data/lib/rbcurse/extras/multiform.rb +330 -0
  102. data/lib/rbcurse/extras/multilinelabel.rb +142 -0
  103. data/lib/rbcurse/extras/newmessagebox.rb +328 -0
  104. data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
  105. data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
  106. data/lib/rbcurse/extras/padreader.rb +189 -0
  107. data/lib/rbcurse/extras/rcomboedit.rb +256 -0
  108. data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
  109. data/lib/rbcurse/extras/statusline.rb +44 -6
  110. data/lib/rbcurse/extras/tabularwidget.rb +141 -104
  111. data/lib/rbcurse/extras/textpad.rb +516 -0
  112. data/lib/rbcurse/extras/viewer.rb +2 -0
  113. data/lib/rbcurse/io.rb +120 -3
  114. data/lib/rbcurse/listcellrenderer.rb +2 -1
  115. data/lib/rbcurse/listkeys.rb +1 -1
  116. data/lib/rbcurse/listscrollable.rb +72 -7
  117. data/lib/rbcurse/rbasiclistbox.rb +64 -12
  118. data/lib/rbcurse/rchangeevent.rb +0 -1
  119. data/lib/rbcurse/rcombo.rb +54 -59
  120. data/lib/rbcurse/rcommandwindow.rb +46 -10
  121. data/lib/rbcurse/rcontainer.rb +415 -0
  122. data/lib/rbcurse/rdialogs.rb +242 -165
  123. data/lib/rbcurse/rinputdataevent.rb +0 -1
  124. data/lib/rbcurse/rlistbox.rb +19 -9
  125. data/lib/rbcurse/rmessagebox.rb +1 -5
  126. data/lib/rbcurse/rmulticontainer.rb +64 -61
  127. data/lib/rbcurse/rmultitextview.rb +0 -2
  128. data/lib/rbcurse/rpopupmenu.rb +0 -2
  129. data/lib/rbcurse/rscrollform.rb +61 -12
  130. data/lib/rbcurse/rtabbedpane.rb +89 -73
  131. data/lib/rbcurse/rtabbedwindow.rb +53 -211
  132. data/lib/rbcurse/rtable.rb +0 -2
  133. data/lib/rbcurse/rtextarea.rb +14 -14
  134. data/lib/rbcurse/rtextview.rb +165 -50
  135. data/lib/rbcurse/rvimsplit.rb +15 -12
  136. data/lib/rbcurse/rwidget.rb +404 -150
  137. data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
  138. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
  139. data/lib/ver/ncurses.rb +1 -9
  140. data/lib/ver/rpad.rb +375 -0
  141. data/lib/ver/window.rb +262 -440
  142. metadata +73 -31
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- #require 'ncurses'
3
- require 'logger'
4
1
  module RubyCurses
5
2
  class TableCellRenderer
6
3
  #include DSL
@@ -51,7 +48,7 @@ module RubyCurses
51
48
  lablist << value
52
49
  end
53
50
  len = @display_length || value.length
54
- $log.debug "less ZERO #{@display_length} || #{value.length}, ri: #{row_index}" if len < 0
51
+ #$log.debug "less ZERO #{@display_length} || #{value.length}, ri: #{row_index}" if len < 0
55
52
  acolor = get_color $datacolor
56
53
  #acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil?
57
54
  _attr = Ncurses::A_NORMAL
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- #require 'ncurses'
3
- require 'logger'
4
1
  module RubyCurses
5
2
  class TableDateCellRenderer
6
3
  #include EventHandler
data/lib/ver/ncurses.rb CHANGED
@@ -13,14 +13,6 @@ module VER
13
13
  # If errors occur, initscr writes an appropriate error message to standard
14
14
  # error and exits; otherwise, a pointer is returned to stdscr.
15
15
  stdscr = Ncurses.initscr ## FFI
16
- #stdscr = FFI::NCurses.initscr
17
- # File.open('stdscrmethrbc', 'w'){|io|
18
- # io.puts '=' * 80
19
- # io.puts stdscr.class
20
- # io.puts(stdscr.public_methods)
21
- # io.puts '=' * 80
22
- # }
23
- #$g_stdscr = stdscr
24
16
 
25
17
  # Color.start if Ncurses.has_colors?
26
18
  Ncurses.start_color();
@@ -104,7 +96,7 @@ module VER
104
96
  Ncurses.nl
105
97
  Ncurses.endwin
106
98
  $ncurses_started = false
107
- puts "ncurses stopped"
99
+ #puts "curses over"
108
100
  ensure
109
101
  return unless error = @last_error
110
102
  log = Config[:logfile].value
data/lib/ver/rpad.rb ADDED
@@ -0,0 +1,375 @@
1
+ require 'ver/window'
2
+
3
+ # This contains pad and subwin.
4
+ #
5
+ # 1. IMHO, subwins and derwins are not very stable. Avoid using them. I've tinkered
6
+ # with them quite a bit and given them up.
7
+ # 2. Pads are quite okay, I tried something too complex, and copywin often can give
8
+ # errors, or seg faults. So i've steered away from the Pad class. I may try a simpler
9
+ # less clever pad approach to textview sometime again.
10
+
11
+ module VER
12
+ ##
13
+ # Pad
14
+ # This is EXPERIMENTAL
15
+ # A pad cannot be used interchangeable since some application functions such as wrefresh
16
+ # are illegal. Cannot expect the application to take care.
17
+ # Internally we can make it easier. Mostly a pad is used to map to one portion of the screen.
18
+ # So we allow that to be defined once. Then only start row and col of pad change.
19
+ # Maybe we should check pad coordinates so no errors
20
+ # Also check screen coordinates (if we know)
21
+ # We need padheight and padwidth only to ensure we don't keep recreating.
22
+ # Howevre, when comp's height increases, then decreases, pad height remains larger
23
+ # but we keep printing an extra row in copywin. so Pad needs to maintain comp height
24
+ # and padheight.
25
+ # @since 0.1.3
26
+ # NOTE used only by TabbedPane. If we rewrite without using it in 1.3.1 then scrap.
27
+ # 2011-11-8 Now the new simpler TabbedPane does not use pads.
28
+ # The aim o this class was to act as a replacement for window, making it seamless
29
+ # to use a pad instead
30
+ class Pad < VER::Window
31
+ # top and left correspond to screen's top and left wich will mostly be fixed
32
+ attr_accessor :top, :left
33
+ # start row and col correspond to pad's top and left which will change if scrolling
34
+ attr_accessor :pminrow, :pmincol
35
+ # screen's height and width, now it reflects components height and width
36
+ attr_accessor :sheight, :swidth
37
+ attr_reader :otherwin
38
+ # dimensions the pad was created with, used so we don't keep recreating pad, only if increase.
39
+ attr_reader :padheight, :padwidth
40
+ #attr_accessor :name # more for debugging log files. 2010-02-02 19:58
41
+ def initialize(height, width)
42
+ @visible = true
43
+ # do we set height and width ?? XXX
44
+ @window = Ncurses.newpad(height, width)
45
+ @padheight = height
46
+ @padwidth = width
47
+ @height = height
48
+ @width = width
49
+ @sheight = height
50
+ @swidth = width
51
+ init_vars
52
+ end
53
+ def init_vars
54
+ super
55
+ @top ||= 0; @left ||= 0
56
+ @pmincol ||= 0 # pad will print from this col
57
+ @pminrow ||= 0 # pad will print from this row
58
+ @window_type = :PAD
59
+ @name ||="#{self}"
60
+ $log.debug " PAD constructor #{self} , #{@window} "
61
+ end
62
+ #
63
+ # @param layout is a hash (@see Window.initialize)
64
+ def self.create_with_layout(layout)
65
+ @window = Pad.new(layout[:height], layout[:width])
66
+ @window.reset_layout(layout)
67
+ return @window
68
+ end
69
+ ##
70
+ # increases the pad size, since the widget may have been resized
71
+ # checks that one of ht or width has been increased
72
+ # destroys earlier pad and returns new one
73
+ # Updates sheight and swidth even if reduced so copywin works fine.
74
+ # @param [Fixnum] height to resize to
75
+ # @param [Fixnum] width to resize to
76
+ # @return [Pad]
77
+ # 2009-10-29 23:18
78
+ def resize(ht = 0, w = 0)
79
+ # update sheight and swidth even if reduced, so that pad doesn't overwrite.
80
+ @sheight = ht if ht > 0
81
+ @swidth = w if w > 0
82
+ return if ht < @padheight and w < @padwidth
83
+ @padheight = ht if ht > @padheight
84
+ @padwidth = w if w > @padwidth
85
+ destroy
86
+ $log.debug " L502 resize, creating newpad with #{@padheight} and #{@padwidth} "
87
+ @window = Ncurses.newpad(@padheight, @padwidth)
88
+ $log.debug " L502 resize created #{@window} "
89
+ return @window
90
+ end
91
+ ## used if pad and window are same size only
92
+ # creates a similar sized window
93
+ # assumes window is backed by this pad
94
+ # @param object of Window class
95
+ def self.create_for_window(win)
96
+ # get coordinates for win
97
+ @otherwin = win
98
+ smaxx = win.getmaxx()
99
+ smaxy = win.getmaxy()
100
+ top = win.getminx()
101
+ left = win.getminy()
102
+ sheight = win.height
103
+ swidth = win.width
104
+ # make pad based on size of window
105
+ window = Pad.create_with_layout(layout = { :height => sheight, :width => swidth, :top => top, :left => sleft })
106
+ window.sheight = sheight
107
+ window.swidth = swidth
108
+ return window
109
+
110
+ end
111
+ # top and left correspond to screen's top and left wich will mostly be fixed.
112
+ # In cases where the component may float around, as in Splitpanes second component
113
+ # this would be set using component's row and col.
114
+ def set_screen_row_col top, left=-1
115
+ @top = top
116
+ @left = left unless left < 0
117
+ end
118
+ alias :set_screen_pad_left :set_screen_row_col
119
+
120
+ ## added user setting screens max row and col (e.g splitpanes first component)
121
+ def set_screen_max_row_col mr, mc
122
+ $log.debug "#{@name} set_screen_max_row_col #{mr},#{mc}. earlier #{@screen_maxrow}, #{@screen_maxcol} "
123
+ # added || check on 2010-01-09 18:39 since crashing if mr > sh + top ..
124
+ # I removed the check, since it results in a blank area on screen since the
125
+ # widget has not expanded itself. Without the check it will crash on copywin so you
126
+ # should increase widget size or disallow calling this in this situation.
127
+ if mr > (@sheight + @top -1 -@pminrow)
128
+ $log.warn " ->>> ** set_screen_max_row_col #{mr} > #{@sheight} + #{@top} -1 - #{@pminrow} ** "
129
+ $log.warn " ->>> can result in error in copy_win or in some rows not displaying"
130
+ return # some situations actually require this ...
131
+ end unless mr.nil?
132
+ @screen_maxrow = mr unless mr.nil? # || mr > (@sheight + @top -1 -@pminrow)
133
+ @screen_maxcol = mc unless mc.nil?
134
+ end
135
+ # start row and col correspond to pad's top and left which will change if scrolling
136
+ # However, if we use this as a backing store for subwindows it could remain the same
137
+ def set_pad_top_left top, left=-1
138
+ $log.debug "#{@name} inside set_pad_top_left to #{top} #{left} earlier #{@pminrow}, #{@pmincol}"
139
+ @pminrow = top unless top < 0
140
+ @pmincol = left unless left < 0
141
+ end
142
+ # return screen max row which will be used for writing to window
143
+ # XXX what if user sets/overrides sheight
144
+ def smaxrow
145
+ #$log.debug " ... niside smaxrow #{@sheight} + #{@top} -1 "
146
+ #@sheight + @top -1
147
+ $log.debug "smr: #{@screen_maxrow} ... niside smaxrow #{@sheight} + #{@top} -1 - #{@pminrow}"
148
+ @screen_maxrow || @sheight + @top -1 -@pminrow
149
+ end
150
+ ##
151
+ # return screen max col which will be used for writing to window
152
+ def smaxcol
153
+ #$log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 "
154
+ #@swidth + @left -1
155
+ # $log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 - #{@pmincol} "
156
+ @screen_maxcol || @swidth + @left -1 - @pmincol
157
+ end
158
+ ##
159
+ # specify the window or subwin that the pad is writing to
160
+ # 2010-02-20 22:45 - actually since there are pad methods smaxrow used on otherwin
161
+ # therefor it can only be a Pad !! NOTE
162
+ def set_backing_window win
163
+ @otherwin = win
164
+ # XX should we extract the coordinates and use for printing ??
165
+ # or for setting maxrow and maxcol
166
+ end
167
+ # trying to make things as easy as possible
168
+ # returns -1 if error in prefresh
169
+ def wrefresh
170
+ $log.debug " inside pad's wrefresh #{@window}. minr,minc,top,left,smaxr,c: #{@pminrow}, #{@pmincol}, #{@top} #{@left} #{smaxrow()} #{smaxcol()} self: #{self.name} "
171
+
172
+ # caution, prefresh uses maxrow and maxcol not height and width
173
+ # so we have to add top and less one since we are zero based
174
+ ret = @window.prefresh(@pminrow, @pmincol, @top, @left, smaxrow(), smaxcol())
175
+ $log.warn " WREFRESH returns -1 ERROR - width or height must be exceeding " if ret == -1
176
+ @modified = false
177
+ return ret
178
+ end
179
+ ##
180
+ # copy the window to the pad (assumes we are writing onto win and keeping
181
+ # pad as backup
182
+ # also assuming only one win so, window not passed as param
183
+ # @return return value of copywin which should be 0 (-1 is ERR)
184
+ def copy_pad_to_win
185
+ $log.warn " DEPRECATED copy_pad_to_win" # CLEANUP
186
+ raise "DEPREC copy_pad_to_win deprecated. Will be removed. Let me know if it is needed"
187
+ # check that we don't exceed other windows height/maxrow
188
+ smr = smaxrow()
189
+ # SHIT, this means the otherwin has to be a Pad, cannot be a window
190
+ osw = @otherwin.width
191
+ osh = @otherwin.height
192
+ osh = @height if osh == 0 # root window has 0
193
+ osw = @width if osw == 0 # root window has 0
194
+ osmr = @otherwin.smaxrow() rescue osh # TRYING for windows
195
+ osmc = @otherwin.smaxcol() rescue osw
196
+ if smr >= osmr
197
+ $log.debug " adjusted smr from #{smr} to #{osmr} -1 causing issues in viewfooter"
198
+ smr = osmr-1 # XXX causing issues in viewport, wont print footer with this
199
+ end
200
+ if smr > @sheight + @top -1 -@pminrow # 2010-01-17 13:27
201
+ smr = @sheight + @top -1 -@pminrow
202
+ $log.debug " adjusted smr to #{smr} to prevent crash "
203
+ end
204
+ smc = smaxcol()
205
+ $log.debug " SMC original = #{smc} "
206
+ if smc >= osmc
207
+ smc = osmc-1
208
+ smc = @width # XXX ??? THIS WAS WORKING< but throwing error in viewport case
209
+ smc = [osmc-1, @width].min # yet another hack
210
+ $log.debug " SMC o-1 #{osmc-1} wdth #{@width}, smc #{smc} "
211
+ end
212
+ ### XXX commented out since it doesn't let a comp print fully if widget expanded (splitpane)
213
+ #smc = osw -1 if smc >= osw; # added 2009-11-02 17:01 for tabbedpanes
214
+
215
+ # dang, this is coming up a lot. 2010-01-16 20:34
216
+ # the second scrollpane was one row too large in testsplit3a.rb
217
+ if smr - @top > @padheight
218
+ $log.debug " fixing smr to padheight 2010-01-16 20:35 HOPE THIS DOESNT BREAK ANYTHING"
219
+ smr = @padheight
220
+ end
221
+ @pminrow = 0 if @pminrow < 0
222
+ @pmincol = 0 if @pmincol < 0
223
+ $log.debug " COPYING #{self.name} to #{@otherwin.name} "
224
+ $log.debug " calling copy pad #{@pminrow} #{@pmincol}, #{@top} #{@left}, #{smr} #{smc} self #{self.name} "
225
+ $log.debug " calling copy pad H: #{@height} W: #{@width}, PH #{@padheight} PW #{@padwidth} WIN:#{@window} "
226
+ # $log.debug " -otherwin target copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} OTHERWIN:#{@otherwin.name} "
227
+ ret="-"
228
+ #if ret == -1
229
+ #x XXX $log.debug " #{ret} otherwin copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} "
230
+ $log.debug " #{ret} otherwin copy pad H: #{osh} W: #{osw}"
231
+ if @top >= osh
232
+ $log.debug " #{ret} ERROR top exceeds other ht #{@top} H: #{osh} "
233
+ end
234
+ if @left >= osw
235
+ $log.debug " #{ret} ERROR left exceeds other wt #{@left} W: #{osw} "
236
+ end
237
+ if smr >= osh
238
+ $log.debug " #{ret} ERROR smrow exceeds other ht #{smr} H: #{osh} "
239
+ smr = osh() -1 # testing 2010-01-31 21:47 , again 2010-02-05 20:22
240
+ end
241
+ if smc >= osw
242
+ $log.debug " #{ret} ERROR smcol exceeds other wt #{smc} W: #{osw} "
243
+ end
244
+ if smc - @left > @padwidth
245
+ $log.debug " #{ret} ERROR smcol - left exceeds padwidth #{smc}- #{@left} PW: #{@padwidth} "
246
+ end
247
+ if smr - @top > @padheight
248
+ $log.debug " #{ret} ERROR smr - top exceeds padheight #{smr}- #{@top} PH: #{@padheight} "
249
+ end
250
+ ret = @window.copywin(@otherwin.get_window,@pminrow,@pmincol, @top, @left, smr, smc, 0)
251
+ $log.debug " copywin ret #{ret} "
252
+ # 2010-01-11 19:42 one more cause of -1 coming is that padheight (actual height which never
253
+ # changes unless pad increases) or padwidth is smaller than area being printed. Solution: increase
254
+ # buffer by increasing widgets w or h. smc - left should not exceed padwidth. smr-top should not
255
+ # exceed padheight
256
+ #end
257
+ @modified = false
258
+ return ret
259
+ end
260
+ # @deprecated
261
+ def copy_win_to_pad
262
+ $log.warn " DEPRECATED copy_win_to_pad" # CLEANUP 2011-09-29
263
+ raise "DEPREC copy_win_to_pad deprecated. Will be removed. Let me know if it is needed"
264
+ smr = smaxrow()
265
+ if smr >= @window.smaxrow()
266
+ smr = @window.smaxrow()-1
267
+ end
268
+ $log.debug " copy_win_to_pad #{@otherwin.name}, #{@window.name}, pminr:#{@pminrow} pminc:#{@pmincol} top:#{@top} left:#{@left} smr:#{smr} "
269
+ ret = @otherwin.copywin(@window.get_window,@pminrow,@pmincol, @top, @left, smr, smaxcol(), 1)
270
+ @modified = false
271
+ return ret
272
+ end
273
+ ##
274
+ #Used to overwrite the pad onto the screen window
275
+ # A window should have been specified as window to back (@see set_backing_window) or (@see create_with_window)
276
+ def overwrite_window
277
+ return @window.overwrite(@otherwin.get_window)
278
+ end
279
+
280
+ ##
281
+ # convenience method so that pad can use printstring but remove screen's row and col
282
+ # The absolute row and col will be taken into consideration when printing on screen.
283
+ #
284
+ # @param [Fixnum] row row to print on
285
+ # @param [Fixnum] col column to print on
286
+ # @param [String] value to print
287
+ # @param [Fixnum] color - color combination
288
+ # @param [Fixnum, nil] attrib defaults to NORMAL
289
+
290
+ # Pls remove the raise once the program is working, extra line can slow things down
291
+ # Keep it on when testing.
292
+ # If the raise is thrown, it means your object could be positioned higher than it should be,
293
+ # or at some point you have increased top, without increasing the objects row.
294
+ def printstring(row,col,value,color,attrib=Ncurses::A_NORMAL)
295
+ #$log.debug " pad printstring #{row} - #{@top} , #{col} - #{@left} "
296
+ raise "printstring row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
297
+ #$log.warn "printstring row < top, pls correct code #{row} #{@top} " if row < @top
298
+ super(row - @top, col - @left, value, color, attrib)
299
+ end # printstring
300
+ # convenience method so that pad can use print_border but remove screen's row and col
301
+ # Please note that this requires that buffer have latest top and left.
302
+ def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
303
+ $log.debug " pad printborder #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} "
304
+ raise "print_border: row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
305
+ #$log.warn "print_border: row < top, pls correct code #{row} #{@top} " if row < @top
306
+ super(row - @top, col - @left, height, width, color, att)
307
+ end
308
+ def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
309
+ $log.debug " pad printborder_only #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} "
310
+ raise "print_border row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
311
+ super(row - @top, col - @left, height, width, color, att)
312
+ end
313
+ # use in place of mvwhline if your widget could be using a pad or window
314
+ def rb_mvwhline row, col, char, width
315
+ super(row-@top, col-@left, char, width)
316
+ end
317
+ # use in place of mvwvline if your widget could be using a pad or window
318
+ def rb_mvwvline row, col, char, width
319
+ super(row-@top, col-@left, char, width)
320
+ end
321
+ # use in place of mvaddch if your widget could be using a pad or window
322
+ def rb_mvaddch row, col, char
323
+ super(row-@top, col-@left, char)
324
+ end
325
+ end # class Pad
326
+ #-------------------------------- deprecated stuff ------------------ #
327
+ ##
328
+ # added RK 2009-10-08 23:57 for tabbedpanes
329
+ # THIS IS EXPERIMENTAL -
330
+ # I have not called super in the initializer so any methods you try on subwin
331
+ # that exist in the superclass which use @window will bomb
332
+ # @since 0.1.3 REMOVE UNUSED.
333
+ # @deprecated
334
+ class SubWindow < VER::Window
335
+ attr_reader :width, :height, :top, :left
336
+ attr_accessor :layout
337
+ attr_reader :panel # XXX reader requires so he can del it in end
338
+ attr_reader :subwin #
339
+ attr_reader :parent #
340
+
341
+ def initialize(parent, layout)
342
+ @visible = true
343
+ reset_layout(layout)
344
+
345
+ @parent = parent
346
+ #@subwin = @parent.get_window().derwin(@height, @width, @top, @left)
347
+ @subwin = @parent.get_window().subwin(@height, @width, @top, @left)
348
+ $log.debug "SUBWIN init #{@height} #{@width} #{@top} #{@left} "
349
+ #$log.debug "SUBWIN init #{@subwin.getbegx} #{@subwin.getbegy} #{@top} #{@left} "
350
+ @panel = Ncurses::Panel.new_panel(@subwin)
351
+
352
+ @window = @subwin # makes more mthods available
353
+ init_vars
354
+
355
+ end
356
+ # no need really now
357
+ def reset_layout layout
358
+ @layout = layout # 2010-02-13 22:23
359
+ @height = layout[:height]
360
+ @width = layout[:width]
361
+ @top = layout[:top]
362
+ @left = layout[:left]
363
+ end
364
+ def _destroy
365
+ # typically the ensure block should have this
366
+ # or should window do it for all subwins, or would we want to wait that long ?
367
+ $log.debug "subwin destroy"
368
+
369
+ Ncurses::Panel.del_panel(panel.pointer) if !panel.nil? # FFI
370
+ #@window.delwin(@window) if !@window.nil? # added FFI 2011-09-7
371
+ delwin if !@window.nil? # added FFI 2011-09-7
372
+ end
373
+ end
374
+
375
+ end
data/lib/ver/window.rb CHANGED
@@ -1,5 +1,33 @@
1
+ # ----------------------------------------------------------------------------- #
2
+ # File: window.rb
3
+ # Description: A wrapper over window
4
+ # Author: rkumar http://github.com/rkumar/rbcurse/
5
+ # Date: Around for a long time
6
+ # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
7
+ # Last update: use ,,L
8
+ #
9
+ # == CHANGED
10
+ # removed Pad and Subwin to lib/ver/rpad.rb - hopefully I've seen the last of both
11
+ #
12
+ # == TODO
13
+ # strip and remove cruft. Now that I've stopped using pad, can we remove
14
+ # the prv_printstring nonsense.
15
+ # ----------------------------------------------------------------------------- #
16
+ #
1
17
  require 'ver/ncurses'
2
18
  require 'ver/panel'
19
+ require 'rbcurse/common/chunk'
20
+ # this is since often windows are declared with 0 height or width and this causes
21
+ # crashes in the most unlikely places. This prevceents me from having to write ternary
22
+ # e.g.
23
+ # @layout[:width].ifzero(FFI::NCurses::LINES-2)
24
+ class Fixnum
25
+ def ifzero v
26
+ return self if self != 0
27
+ return v
28
+ end
29
+ end
30
+
3
31
  module VER
4
32
  class Window
5
33
  attr_reader :width, :height, :top, :left
@@ -31,11 +59,17 @@ module VER
31
59
  @visible = true
32
60
  reset_layout(layout)
33
61
 
62
+ #$log.debug "XXX:WINDOW got h #{@height}, w #{@width}, t #{@top}, l #{@left} "
63
+
64
+ @height = FFI::NCurses.LINES if @height == 0 # 2011-11-14 added since tired of checking for zero
65
+ @width = FFI::NCurses.COLS if @width == 0
66
+
34
67
  @window = FFI::NCurses.newwin(@height, @width, @top, @left) # added FFI 2011-09-6
35
68
  @panel = Ncurses::Panel.new(@window) # added FFI 2011-09-6
36
69
  #$error_message_row = $status_message_row = Ncurses.LINES-1
37
70
  $error_message_row ||= Ncurses.LINES-1
38
71
  $error_message_col ||= 1 # ask (bottomline) uses 0 as default so you can have mismatch. XXX
72
+ $status_message ||= RubyCurses::Variable.new # in case not an App
39
73
  init_vars
40
74
 
41
75
 
@@ -187,30 +221,80 @@ module VER
187
221
  end
188
222
  FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name)
189
223
  end
224
+
225
+ # NOTE: many of these methods using width will not work since root windows width
226
+ # is 0
190
227
  def print(string, width = width)
191
228
  return unless visible?
192
- waddnstr(string.to_s, width) # changed 2011 dts
229
+ w = width == 0? Ncurses.COLS : width
230
+ waddnstr(string.to_s, w) # changed 2011 dts
193
231
  end
194
232
 
233
+ # NOTE: many of these methods using width will not work since root windows width
234
+ # is 0
195
235
  def print_yx(string, y = 0, x = 0)
196
- mvwaddnstr(y, x, string, width) # changed 2011 dts
236
+ w = width == 0? Ncurses.COLS : width
237
+ mvwaddnstr(y, x, string, w) # changed 2011 dts
197
238
  end
198
239
 
240
+ # NOTE: many of these methods using width will not work since root windows width
241
+ # is 0
199
242
  def print_empty_line
200
243
  return unless visible?
201
- printw(' ' * width)
244
+ w = width == 0? Ncurses.COLS : width
245
+ printw(' ' * w)
202
246
  end
203
247
 
248
+ # NOTE: many of these methods using width will not work since root windows width
249
+ # is 0
204
250
  def print_line(string)
205
- print(string.ljust(width))
251
+ w = width == 0? Ncurses.COLS : width
252
+ print(string.ljust(w))
206
253
  end
207
254
 
208
- # @unused, pls remove
209
- def show_colored_chunks(chunks)
255
+ # returns the actual width in case you've used a root window
256
+ # which returns a 0 for wid and ht
257
+ #
258
+ def actual_width
259
+ width == 0? Ncurses.COLS : width
260
+ end
261
+
262
+ #
263
+ # returns the actual ht in case you've used a root window
264
+ # which returns a 0 for wid and ht
265
+ #
266
+ def actual_height
267
+ height == 0? Ncurses.LINES : height
268
+ end
269
+
270
+ # NOTE: many of these methods using width will not work since root windows width
271
+ # is 0
272
+ # Previously this printed a chunk as a full line, I've modified it to print on
273
+ # one line. This can be used for running text.
274
+ def show_colored_chunks(chunks, defcolor = nil, defattr = nil)
210
275
  return unless visible?
211
- chunks.each do |color, chunk|
212
- color_set(color)
213
- print_line(chunk)
276
+ chunks.each do |chunk| #|color, chunk, attrib|
277
+ case chunk
278
+ when Chunks::Chunk
279
+ color = chunk.color
280
+ attrib = chunk.attrib
281
+ text = chunk.text
282
+ when Array
283
+ # for earlier demos that used an array
284
+ color = chunk[0]
285
+ attrib = chunk[2]
286
+ text = chunk[1]
287
+ end
288
+
289
+ color ||= defcolor
290
+ attrib ||= defattr
291
+
292
+ cc, bg = ColorMap.get_colors_for_pair color
293
+ $log.debug "XXX: CHUNK window #{text}, cp #{color} , attrib #{attrib}. #{cc}, #{bg} "
294
+ color_set(color,nil) if color
295
+ wattron(attrib) if attrib
296
+ print(text)
297
+ wattroff(attrib) if attrib
214
298
  end
215
299
  end
216
300
 
@@ -281,6 +365,7 @@ module VER
281
365
  return 27
282
366
  when 2 # basically a ALT-O, or alt-[ (79 or 91) this will be really slow since it waits for -1
283
367
  ch = 128 + @stack.last
368
+ $log.warn "XXX: WARN #{ch} CLEARING stack #{@stack} "
284
369
  @stack.clear
285
370
  return ch
286
371
  else
@@ -321,18 +406,20 @@ module VER
321
406
  # xterm-color
322
407
  case ch
323
408
  when 80
324
- ch = KEY_F1
409
+ ch = FFI::NCurses::KEY_F1
325
410
  when 81
326
- ch = KEY_F2
411
+ ch = FFI::NCurses::KEY_F2
327
412
  when 82
328
- ch = KEY_F3
413
+ ch = FFI::NCurses::KEY_F3
329
414
  when 83
330
- ch = KEY_F4
331
- #when 27 # another alt-char following Alt-Sh-O
415
+ ch = FFI::NCurses::KEY_F4
416
+ #when 27 # another alt-char following Alt-Sh-O
332
417
  else
418
+ ## iterm2 uses these for HOME END num keyboard keys
333
419
  @stack.clear
334
- @stack << ch
335
- return 128 + 79
420
+ #@stack << ch # earlier we pushed this but it could be of use
421
+ #return 128 + 79
422
+ return 128 + 79 + ch
336
423
 
337
424
  end
338
425
  @stack.clear
@@ -418,7 +505,11 @@ module VER
418
505
  def reset_layout(layout)
419
506
  case layout
420
507
  when Array
508
+ $log.error "NIL in window constructor" if layout.include? nil
509
+ raise ArgumentError, "Nil in window constructor" if layout.include? nil
421
510
  @height, @width, @top, @left = *layout
511
+ raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil?
512
+
422
513
  @layout = { :height => @height, :width => @width, :top => @top, :left => @top }
423
514
  when Hash
424
515
  @layout = layout
@@ -455,14 +546,18 @@ module VER
455
546
  # Ncurses panel
456
547
 
457
548
  def hide
549
+ #return unless visible? # added 2011-10-14 these 2 are not behaving properly
458
550
  Ncurses::Panel.hide_panel @panel.pointer
459
- Ncurses.refresh # wnoutrefresh
551
+ #Ncurses.refresh # wnoutrefresh
552
+ Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
460
553
  @visible = false
461
554
  end
462
555
 
463
556
  def show
557
+ #return if visible? # added 2011-10-14 these 2 are not behaving properly
464
558
  Ncurses::Panel.show_panel @panel.pointer
465
- Ncurses.refresh # wnoutrefresh
559
+ #Ncurses.refresh # wnoutrefresh
560
+ Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
466
561
  @visible = true
467
562
  end
468
563
 
@@ -474,25 +569,123 @@ module VER
474
569
  def visible?
475
570
  @visible
476
571
  end
572
+
477
573
  ##
478
- #added by rk 2008-11-29 18:48
479
- #to see if we can clean up from within
574
+ # destroy window, panel and any pads that were requested
575
+ #
480
576
  def destroy
481
577
  # typically the ensure block should have this
482
- # @panel = @window.panel if @window
483
- #Ncurses::Panel.del_panel(@panel) if !@panel.nil?
484
- #@window.delwin if !@window.nil?
578
+
485
579
  $log.debug "win destroy start"
486
580
 
487
- #@panel = @window.panel if @window
488
- # changed Ncurses::Panel to Ncurses::Panel on 2011-09-8 when moved to FFI
489
- Ncurses::Panel.del_panel(@panel.pointer) if !@panel.nil? # ADDED FFI pointer 2011-09-7
490
- #@window.delwin(@window) if !@window.nil? # added FFI 2011-09-7
491
- delwin() if !@window.nil? # added FFI 2011-09-7
581
+ Ncurses::Panel.del_panel(@panel.pointer) if @panel
582
+ delwin() if @window
492
583
  Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
584
+
585
+ # destroy any pads that were created by widgets using get_pad
586
+ @pads.each { |pad|
587
+ FFI::NCurses.delwin(pad) if pad
588
+ pad = nil
589
+ } if @pads
493
590
  $log.debug "win destroy end"
494
591
  end
592
+
593
+ #
594
+ # 2011-11-13 since 1.4.1
595
+ # Widgets can get window to create a pad for them. This way when the window
596
+ # is destroyed, it will delete all the pads. A widget wold not be able to do this.
597
+ # The destroy method of the widget will be called.
598
+ def get_pad content_row, content_cols
599
+ pad = FFI::NCurses.newpad(content_rows, content_cols)
600
+ @pads ||= []
601
+ @pads << pad
602
+ end
603
+
604
+ #
605
+ # Allows user to send data as normal string or chunks for printing
606
+ # An array is assumed to be a chunk containing color and attrib info
607
+ #
608
+ def printstring_or_chunks(r,c,content, color, att = Ncurses::A_NORMAL)
609
+ if content.is_a? String
610
+ printstring(r,c,content, color, att)
611
+ elsif content.is_a? Chunks::ChunkLine
612
+ $log.debug "XXX: using chunkline"
613
+ wmove r, c
614
+ a = get_attrib att
615
+ show_colored_chunks content, color, a
616
+ elsif content.is_a? Array
617
+ # several chunks in one row - NOTE Very experimental may change
618
+ if content[0].is_a? Array
619
+ $log.warn "XXX: WARNING outdated should send in a chunkline"
620
+ wmove r, c
621
+ a = get_attrib att
622
+ show_colored_chunks content, color, a
623
+ else
624
+ # a single row chunk - NOTE Very experimental may change
625
+ text = content[1].dup
626
+ printstring r, c, text, content[0] || color, content[2] || att
627
+ end
628
+ end
629
+ end
630
+ #
631
+ # prints a string formatted in our new experimental coloring format
632
+ # taken from tmux. Currently, since i have chunks workings, i convert
633
+ # to chunks and use the existing print function. This could change.
634
+ # An example of a formatted string is:
635
+ # s="#[fg=green]testing chunks #[fg=yellow, bg=red, bold]yellow #[reverse] reverseme \
636
+ # #[normal]normal#[bg = black]just yellow#[fg=blue],blue now #[underline] underlined text"
637
+ # Ideally I should push and pop colors which the shell does not do with ansi terminal sequences.
638
+ # That way i can have a line in red,
639
+ # with some word in yellow, and then the line continues in red.
640
+ #
641
+ def printstring_formatted(r,c,content, color, att = Ncurses::A_NORMAL)
642
+ att = get_attrib att unless att.is_a? Fixnum
643
+ chunkline = convert_to_chunk(content, color, att)
644
+ printstring_or_chunks r,c, chunkline, color, att
645
+ end # print
646
+ #
647
+ # print a formatted line right aligned
648
+ # c (col) is ignored and calculated based on width and unformatted string length
649
+ #
650
+ def printstring_formatted_right(r,c,content, color, att = Ncurses::A_NORMAL)
651
+ clean = content.gsub /#\[[^\]]*\]/,'' # clean out all markup
652
+ c = actual_width() - clean.length
653
+ printstring_formatted(r,c,content, color, att )
654
+ end
655
+
656
+ private
657
+ def get_default_color_parser
658
+ require 'rbcurse/common/colorparser'
659
+ @color_parser || DefaultColorParser.new
660
+ end
661
+ # supply with a color parser, if you supplied formatted text
662
+ public
663
+ def color_parser f
664
+ $log.debug "XXX: color_parser setting in window to #{f} "
665
+ if f == :tmux
666
+ @color_parser = get_default_color_parser()
667
+ else
668
+ @color_parser = f
669
+ end
670
+ end
671
+ #
672
+ # Takes a formatted string and converts the parsed parts to chunks.
673
+ #
674
+ # @param [String] takes the entire line or string and breaks into an array of chunks
675
+ # @yield chunk if block
676
+ # @return [ChunkLine] # [Array] array of chunks
677
+ # @since 1.4.1 2011-11-3 experimental, can change
678
+ public
679
+ def convert_to_chunk s, colorp=$datacolor, att=FFI::NCurses::A_NORMAL
680
+ unless @color_parser
681
+ @color_parser = get_default_color_parser()
682
+ @converter = Chunks::ColorParser.new @color_parser
683
+ end
684
+ @converter.convert_to_chunk s, colorp, att
685
+ end
686
+
495
687
  ##
688
+ # prints a string at row, col, with given color and attribute
496
689
  # added by rk 2008-11-29 19:01
497
690
  # I usually use this, not the others ones here
498
691
  # @param r - row
@@ -501,7 +694,10 @@ module VER
501
694
  # @param color - color pair
502
695
  # @ param att - ncurses attribute: normal, bold, reverse, blink,
503
696
  # underline
697
+ public
504
698
  def printstring(r,c,string, color, att = Ncurses::A_NORMAL)
699
+ raise "Nil passed to peintstring row:#{r}, col:#{c}, #{color} " if r.nil? || c.nil? || color.nil?
700
+ #raise "Zero or less passed to printstring row:#{r}, col:#{c} " if $log.debug? && (r <=0 || c <=0)
505
701
  prv_printstring(r,c,string, color, att )
506
702
  end
507
703
 
@@ -509,27 +705,28 @@ module VER
509
705
  def prv_printstring(r,c,string, color, att = Ncurses::A_NORMAL)
510
706
 
511
707
  #$log.debug " #{@name} inside window printstring r #{r} c #{c} #{string} "
512
- att = Ncurses::A_NORMAL if att.nil?
513
- case att.to_s.downcase
514
- when 'normal'
708
+ if att.nil?
515
709
  att = Ncurses::A_NORMAL
516
- when 'underline'
517
- att = Ncurses::A_UNDERLINE
518
- when 'bold'
519
- att = Ncurses::A_BOLD
520
- when 'blink'
521
- att = Ncurses::A_BLINK # unlikely to work
522
- when 'reverse'
523
- att = Ncurses::A_REVERSE
710
+ else
711
+ att = get_attrib att
524
712
  end
713
+ #att = att.downcase.to_sym if att.is_a? String
714
+ #case att
715
+ #when :normal
716
+ #att = Ncurses::A_NORMAL
717
+ #when :underline
718
+ #att = Ncurses::A_UNDERLINE
719
+ #when :bold
720
+ #att = Ncurses::A_BOLD
721
+ #when :reverse
722
+ #att = Ncurses::A_REVERSE
723
+ #when :dim
724
+ #att = Ncurses::A_DIM
725
+ #when :blink
726
+ #att = Ncurses::A_BLINK # unlikely to work
727
+ #end
525
728
 
526
729
  wattron(Ncurses.COLOR_PAIR(color) | att)
527
- # we should not print beyond window coordinates
528
- # trying out on 2009-01-03 19:29
529
- #width = Ncurses.COLS
530
- # the next line won't ensure we don't write outside some bounds like table
531
- #string = string[0..(width-c)] if c + string.length > width
532
- #$log.debug "PRINT len:#{string.length}, #{Ncurses.COLS}, #{r}, #{c} w: #{@window} "
533
730
  mvwprintw(r, c, "%s", :string, string);
534
731
  wattroff(Ncurses.COLOR_PAIR(color) | att)
535
732
  end
@@ -581,6 +778,20 @@ module VER
581
778
  ##
582
779
  # NOTE : FOR MESSAGEBOXES ONLY !!!!
583
780
  def print_border_mb row, col, height, width, color, attr
781
+ # the next is for xterm-256
782
+ att = get_attrib attr
783
+ len = width
784
+ len = Ncurses.COLS-0 if len == 0
785
+ # print a bar across the screen
786
+ #attron(Ncurses.COLOR_PAIR(color) | att)
787
+ # this works for newmessagebox but not for old one.
788
+ # Even now in some cases some black shows through, if the widget is printing spaces
789
+ # such as field or textview on a messagebox.
790
+ (row-1).upto(row+height-1) do |r|
791
+ mvwhline(r, col, 1, len)
792
+ end
793
+ #attroff(Ncurses.COLOR_PAIR(color) | att)
794
+
584
795
  mvwaddch row, col, Ncurses::ACS_ULCORNER
585
796
  mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6)
586
797
  mvwaddch row, col+width-5, Ncurses::ACS_URCORNER
@@ -604,9 +815,9 @@ module VER
604
815
  # 2009-11-02 00:45 made att nil for blanking out
605
816
  # FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view
606
817
  # when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53
818
+ ww=width-2
607
819
  (row+1).upto(row+height-1) do |r|
608
- #printstring( r, col+1," "*(width-2) , $datacolor, nil)
609
- prv_printstring( r, col+1," "*(width-2) , $datacolor, nil)
820
+ prv_printstring( r, col+1," "*ww , color, att)
610
821
  end
611
822
  prv_print_border_only row, col, height, width, color, att
612
823
  end
@@ -620,18 +831,10 @@ module VER
620
831
  #+ to print border over what's been done.
621
832
  # XXX this reduces 1 from width but not height !!! FIXME
622
833
  def prv_print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
623
- att ||= Ncurses::A_NORMAL
624
- case att.to_s.downcase
625
- when 'normal'
834
+ if att.nil?
626
835
  att = Ncurses::A_NORMAL
627
- when 'underline'
628
- att = Ncurses::A_UNDERLINE
629
- when 'bold'
630
- att = Ncurses::A_BOLD
631
- when 'blink'
632
- att = Ncurses::A_BLINK # unlikely to work
633
- when 'reverse'
634
- att = Ncurses::A_REVERSE
836
+ else
837
+ att = get_attrib att
635
838
  end
636
839
  wattron(Ncurses.COLOR_PAIR(color) | att)
637
840
  mvwaddch row, col, Ncurses::ACS_ULCORNER
@@ -645,27 +848,6 @@ module VER
645
848
  mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1)
646
849
  wattroff(Ncurses.COLOR_PAIR(color) | att)
647
850
  end
648
- # added RK 2009-10-08 23:57 for tabbedpanes
649
- # THIS IS EXPERIMENTAL - XXX CLEANUP REMOVE
650
- # Acco to most sources, derwin and subwin are not thoroughly tested, avoid usage
651
- # subwin moving and resizing not functioning.
652
- def derwin(layout)
653
- $log.debug " #{self} EXP: returning a subwin in derwin"
654
- v = VER::SubWindow.new(self, layout)
655
- $log.debug " #{self} EXP: returning a subwin in derwin: #{v} "
656
- return v
657
- end
658
- ## REMOVE CLEANUP UNUSED
659
- def _subwin(layout)
660
- t = @layout[:top]
661
- l = @layout[:left]
662
- layout[:top] = layout[:top] + t
663
- layout[:left] = layout[:left] + l
664
- $log.debug " #{self} EXP: returning a subwin in derwin. Adding #{t} and #{l} "
665
- v = VER::SubWindow.new(self, layout)
666
- $log.debug " #{self} EXP: returning a subwin in derwin: #{v} "
667
- return v
668
- end
669
851
  # This used to return an Ncurses window object, and you could call methods on it
670
852
  # Now it returns a FFI::NCurses.window pointer which you cannot call methods on.
671
853
  # You have to pass it to FFI::NCurses.<method>
@@ -696,365 +878,5 @@ module VER
696
878
  def_delegators :@bottomline, :ask, :say, :agree, :choose
697
879
  end
698
880
  end
699
- end
700
- #-------------------------------- deprecated stuff ------------------ #
701
- ##
702
- # added RK 2009-10-08 23:57 for tabbedpanes
703
- # THIS IS EXPERIMENTAL -
704
- # I have not called super in the initializer so any methods you try on subwin
705
- # that exist in the superclass which use @window will bomb
706
- # @since 0.1.3 REMOVE UNUSED.
707
- # @deprecated
708
- class SubWindow < VER::Window
709
- attr_reader :width, :height, :top, :left
710
- attr_accessor :layout
711
- attr_reader :panel # XXX reader requires so he can del it in end
712
- attr_reader :subwin #
713
- attr_reader :parent #
714
-
715
- def initialize(parent, layout)
716
- @visible = true
717
- reset_layout(layout)
718
-
719
- @parent = parent
720
- #@subwin = @parent.get_window().derwin(@height, @width, @top, @left)
721
- @subwin = @parent.get_window().subwin(@height, @width, @top, @left)
722
- $log.debug "SUBWIN init #{@height} #{@width} #{@top} #{@left} "
723
- #$log.debug "SUBWIN init #{@subwin.getbegx} #{@subwin.getbegy} #{@top} #{@left} "
724
- @panel = Ncurses::Panel.new_panel(@subwin)
725
-
726
- @window = @subwin # makes more mthods available
727
- init_vars
728
-
729
- end
730
- # no need really now
731
- def reset_layout layout
732
- @layout = layout # 2010-02-13 22:23
733
- @height = layout[:height]
734
- @width = layout[:width]
735
- @top = layout[:top]
736
- @left = layout[:left]
737
- end
738
- def _destroy
739
- # typically the ensure block should have this
740
- # or should window do it for all subwins, or would we want to wait that long ?
741
- $log.debug "subwin destroy"
742
-
743
- Ncurses::Panel.del_panel(panel.pointer) if !panel.nil? # FFI
744
- #@window.delwin(@window) if !@window.nil? # added FFI 2011-09-7
745
- delwin if !@window.nil? # added FFI 2011-09-7
746
- end
747
- end
748
-
749
- ##
750
- # Pad
751
- # This is EXPERIMENTAL
752
- # A pad cannot be used interchangeable since some application functions such as wrefresh
753
- # are illegal. Cannot expect the application to take care.
754
- # Internally we can make it easier. Mostly a pad is used to map to one portion of the screen.
755
- # So we allow that to be defined once. Then only start row and col of pad change.
756
- # Maybe we should check pad coordinates so no errors
757
- # Also check screen coordinates (if we know)
758
- # We need padheight and padwidth only to ensure we don't keep recreating.
759
- # Howevre, when comp's height increases, then decreases, pad height remains larger
760
- # but we keep printing an extra row in copywin. so Pad needs to maintain comp height
761
- # and padheight.
762
- # @since 0.1.3
763
- # NOTE used only by TabbedPane. If we rewrite without using it in 1.3.1 then scrap.
764
- class Pad < VER::Window
765
- # top and left correspond to screen's top and left wich will mostly be fixed
766
- attr_accessor :top, :left
767
- # start row and col correspond to pad's top and left which will change if scrolling
768
- attr_accessor :pminrow, :pmincol
769
- # screen's height and width, now it reflects components height and width
770
- attr_accessor :sheight, :swidth
771
- attr_reader :otherwin
772
- # dimensions the pad was created with, used so we don't keep recreating pad, only if increase.
773
- attr_reader :padheight, :padwidth
774
- #attr_accessor :name # more for debugging log files. 2010-02-02 19:58
775
- def initialize(height, width)
776
- @visible = true
777
- # do we set height and width ?? XXX
778
- @window = Ncurses.newpad(height, width)
779
- @padheight = height
780
- @padwidth = width
781
- @height = height
782
- @width = width
783
- @sheight = height
784
- @swidth = width
785
- init_vars
786
- end
787
- def init_vars
788
- super
789
- @top ||= 0; @left ||= 0
790
- @pmincol ||= 0 # pad will print from this col
791
- @pminrow ||= 0 # pad will print from this row
792
- @window_type = :PAD
793
- @name ||="#{self}"
794
- $log.debug " PAD constructor #{self} , #{@window} "
795
- end
796
- #
797
- # @param layout is a hash (@see Window.initialize)
798
- def self.create_with_layout(layout)
799
- @window = Pad.new(layout[:height], layout[:width])
800
- @window.reset_layout(layout)
801
- return @window
802
- end
803
- ##
804
- # increases the pad size, since the widget may have been resized
805
- # checks that one of ht or width has been increased
806
- # destroys earlier pad and returns new one
807
- # Updates sheight and swidth even if reduced so copywin works fine.
808
- # @param [Fixnum] height to resize to
809
- # @param [Fixnum] width to resize to
810
- # @return [Pad]
811
- # 2009-10-29 23:18
812
- def resize(ht = 0, w = 0)
813
- # update sheight and swidth even if reduced, so that pad doesn't overwrite.
814
- @sheight = ht if ht > 0
815
- @swidth = w if w > 0
816
- return if ht < @padheight and w < @padwidth
817
- @padheight = ht if ht > @padheight
818
- @padwidth = w if w > @padwidth
819
- destroy
820
- $log.debug " L502 resize, creating newpad with #{@padheight} and #{@padwidth} "
821
- @window = Ncurses.newpad(@padheight, @padwidth)
822
- $log.debug " L502 resize created #{@window} "
823
- return @window
824
- end
825
- ## used if pad and window are same size only
826
- # creates a similar sized window
827
- # assumes window is backed by this pad
828
- # @param object of Window class
829
- def self.create_for_window(win)
830
- # get coordinates for win
831
- @otherwin = win
832
- smaxx = win.getmaxx()
833
- smaxy = win.getmaxy()
834
- top = win.getminx()
835
- left = win.getminy()
836
- sheight = win.height
837
- swidth = win.width
838
- # make pad based on size of window
839
- window = Pad.create_with_layout(layout = { :height => sheight, :width => swidth, :top => top, :left => sleft })
840
- window.sheight = sheight
841
- window.swidth = swidth
842
- return window
843
-
844
- end
845
- # top and left correspond to screen's top and left wich will mostly be fixed.
846
- # In cases where the component may float around, as in Splitpanes second component
847
- # this would be set using component's row and col.
848
- def set_screen_row_col top, left=-1
849
- @top = top
850
- @left = left unless left < 0
851
- end
852
- alias :set_screen_pad_left :set_screen_row_col
853
-
854
- ## added user setting screens max row and col (e.g splitpanes first component)
855
- def set_screen_max_row_col mr, mc
856
- $log.debug "#{@name} set_screen_max_row_col #{mr},#{mc}. earlier #{@screen_maxrow}, #{@screen_maxcol} "
857
- # added || check on 2010-01-09 18:39 since crashing if mr > sh + top ..
858
- # I removed the check, since it results in a blank area on screen since the
859
- # widget has not expanded itself. Without the check it will crash on copywin so you
860
- # should increase widget size or disallow calling this in this situation.
861
- if mr > (@sheight + @top -1 -@pminrow)
862
- $log.warn " ->>> ** set_screen_max_row_col #{mr} > #{@sheight} + #{@top} -1 - #{@pminrow} ** "
863
- $log.warn " ->>> can result in error in copy_win or in some rows not displaying"
864
- return # some situations actually require this ...
865
- end unless mr.nil?
866
- @screen_maxrow = mr unless mr.nil? # || mr > (@sheight + @top -1 -@pminrow)
867
- @screen_maxcol = mc unless mc.nil?
868
- end
869
- # start row and col correspond to pad's top and left which will change if scrolling
870
- # However, if we use this as a backing store for subwindows it could remain the same
871
- def set_pad_top_left top, left=-1
872
- $log.debug "#{@name} inside set_pad_top_left to #{top} #{left} earlier #{@pminrow}, #{@pmincol}"
873
- @pminrow = top unless top < 0
874
- @pmincol = left unless left < 0
875
- end
876
- # return screen max row which will be used for writing to window
877
- # XXX what if user sets/overrides sheight
878
- def smaxrow
879
- #$log.debug " ... niside smaxrow #{@sheight} + #{@top} -1 "
880
- #@sheight + @top -1
881
- $log.debug "smr: #{@screen_maxrow} ... niside smaxrow #{@sheight} + #{@top} -1 - #{@pminrow}"
882
- @screen_maxrow || @sheight + @top -1 -@pminrow
883
- end
884
- ##
885
- # return screen max col which will be used for writing to window
886
- def smaxcol
887
- #$log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 "
888
- #@swidth + @left -1
889
- # $log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 - #{@pmincol} "
890
- @screen_maxcol || @swidth + @left -1 - @pmincol
891
- end
892
- ##
893
- # specify the window or subwin that the pad is writing to
894
- # 2010-02-20 22:45 - actually since there are pad methods smaxrow used on otherwin
895
- # therefor it can only be a Pad !! NOTE
896
- def set_backing_window win
897
- @otherwin = win
898
- # XX should we extract the coordinates and use for printing ??
899
- # or for setting maxrow and maxcol
900
- end
901
- # trying to make things as easy as possible
902
- # returns -1 if error in prefresh
903
- def wrefresh
904
- $log.debug " inside pad's wrefresh #{@window}. minr,minc,top,left,smaxr,c: #{@pminrow}, #{@pmincol}, #{@top} #{@left} #{smaxrow()} #{smaxcol()} self: #{self.name} "
905
-
906
- # caution, prefresh uses maxrow and maxcol not height and width
907
- # so we have to add top and less one since we are zero based
908
- ret = @window.prefresh(@pminrow, @pmincol, @top, @left, smaxrow(), smaxcol())
909
- $log.warn " WREFRESH returns -1 ERROR - width or height must be exceeding " if ret == -1
910
- @modified = false
911
- return ret
912
- end
913
- ##
914
- # copy the window to the pad (assumes we are writing onto win and keeping
915
- # pad as backup
916
- # also assuming only one win so, window not passed as param
917
- # @return return value of copywin which should be 0 (-1 is ERR)
918
- def copy_pad_to_win
919
- $log.warn " DEPRECATED copy_pad_to_win" # CLEANUP
920
- raise "DEPREC copy_pad_to_win deprecated. Will be removed. Let me know if it is needed"
921
- # check that we don't exceed other windows height/maxrow
922
- smr = smaxrow()
923
- # SHIT, this means the otherwin has to be a Pad, cannot be a window
924
- osw = @otherwin.width
925
- osh = @otherwin.height
926
- osh = @height if osh == 0 # root window has 0
927
- osw = @width if osw == 0 # root window has 0
928
- osmr = @otherwin.smaxrow() rescue osh # TRYING for windows
929
- osmc = @otherwin.smaxcol() rescue osw
930
- if smr >= osmr
931
- $log.debug " adjusted smr from #{smr} to #{osmr} -1 causing issues in viewfooter"
932
- smr = osmr-1 # XXX causing issues in viewport, wont print footer with this
933
- end
934
- if smr > @sheight + @top -1 -@pminrow # 2010-01-17 13:27
935
- smr = @sheight + @top -1 -@pminrow
936
- $log.debug " adjusted smr to #{smr} to prevent crash "
937
- end
938
- smc = smaxcol()
939
- $log.debug " SMC original = #{smc} "
940
- if smc >= osmc
941
- smc = osmc-1
942
- smc = @width # XXX ??? THIS WAS WORKING< but throwing error in viewport case
943
- smc = [osmc-1, @width].min # yet another hack
944
- $log.debug " SMC o-1 #{osmc-1} wdth #{@width}, smc #{smc} "
945
- end
946
- ### XXX commented out since it doesn't let a comp print fully if widget expanded (splitpane)
947
- #smc = osw -1 if smc >= osw; # added 2009-11-02 17:01 for tabbedpanes
948
-
949
- # dang, this is coming up a lot. 2010-01-16 20:34
950
- # the second scrollpane was one row too large in testsplit3a.rb
951
- if smr - @top > @padheight
952
- $log.debug " fixing smr to padheight 2010-01-16 20:35 HOPE THIS DOESNT BREAK ANYTHING"
953
- smr = @padheight
954
- end
955
- @pminrow = 0 if @pminrow < 0
956
- @pmincol = 0 if @pmincol < 0
957
- $log.debug " COPYING #{self.name} to #{@otherwin.name} "
958
- $log.debug " calling copy pad #{@pminrow} #{@pmincol}, #{@top} #{@left}, #{smr} #{smc} self #{self.name} "
959
- $log.debug " calling copy pad H: #{@height} W: #{@width}, PH #{@padheight} PW #{@padwidth} WIN:#{@window} "
960
- # $log.debug " -otherwin target copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} OTHERWIN:#{@otherwin.name} "
961
- ret="-"
962
- #if ret == -1
963
- #x XXX $log.debug " #{ret} otherwin copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} "
964
- $log.debug " #{ret} otherwin copy pad H: #{osh} W: #{osw}"
965
- if @top >= osh
966
- $log.debug " #{ret} ERROR top exceeds other ht #{@top} H: #{osh} "
967
- end
968
- if @left >= osw
969
- $log.debug " #{ret} ERROR left exceeds other wt #{@left} W: #{osw} "
970
- end
971
- if smr >= osh
972
- $log.debug " #{ret} ERROR smrow exceeds other ht #{smr} H: #{osh} "
973
- smr = osh() -1 # testing 2010-01-31 21:47 , again 2010-02-05 20:22
974
- end
975
- if smc >= osw
976
- $log.debug " #{ret} ERROR smcol exceeds other wt #{smc} W: #{osw} "
977
- end
978
- if smc - @left > @padwidth
979
- $log.debug " #{ret} ERROR smcol - left exceeds padwidth #{smc}- #{@left} PW: #{@padwidth} "
980
- end
981
- if smr - @top > @padheight
982
- $log.debug " #{ret} ERROR smr - top exceeds padheight #{smr}- #{@top} PH: #{@padheight} "
983
- end
984
- ret = @window.copywin(@otherwin.get_window,@pminrow,@pmincol, @top, @left, smr, smc, 0)
985
- $log.debug " copywin ret #{ret} "
986
- # 2010-01-11 19:42 one more cause of -1 coming is that padheight (actual height which never
987
- # changes unless pad increases) or padwidth is smaller than area being printed. Solution: increase
988
- # buffer by increasing widgets w or h. smc - left should not exceed padwidth. smr-top should not
989
- # exceed padheight
990
- #end
991
- @modified = false
992
- return ret
993
- end
994
- # @deprecated
995
- def copy_win_to_pad
996
- $log.warn " DEPRECATED copy_win_to_pad" # CLEANUP 2011-09-29
997
- raise "DEPREC copy_win_to_pad deprecated. Will be removed. Let me know if it is needed"
998
- smr = smaxrow()
999
- if smr >= @window.smaxrow()
1000
- smr = @window.smaxrow()-1
1001
- end
1002
- $log.debug " copy_win_to_pad #{@otherwin.name}, #{@window.name}, pminr:#{@pminrow} pminc:#{@pmincol} top:#{@top} left:#{@left} smr:#{smr} "
1003
- ret = @otherwin.copywin(@window.get_window,@pminrow,@pmincol, @top, @left, smr, smaxcol(), 1)
1004
- @modified = false
1005
- return ret
1006
- end
1007
- ##
1008
- #Used to overwrite the pad onto the screen window
1009
- # A window should have been specified as window to back (@see set_backing_window) or (@see create_with_window)
1010
- def overwrite_window
1011
- return @window.overwrite(@otherwin.get_window)
1012
- end
1013
-
1014
- ##
1015
- # convenience method so that pad can use printstring but remove screen's row and col
1016
- # The absolute row and col will be taken into consideration when printing on screen.
1017
- #
1018
- # @param [Fixnum] row row to print on
1019
- # @param [Fixnum] col column to print on
1020
- # @param [String] value to print
1021
- # @param [Fixnum] color - color combination
1022
- # @param [Fixnum, nil] attrib defaults to NORMAL
1023
-
1024
- # Pls remove the raise once the program is working, extra line can slow things down
1025
- # Keep it on when testing.
1026
- # If the raise is thrown, it means your object could be positioned higher than it should be,
1027
- # or at some point you have increased top, without increasing the objects row.
1028
- def printstring(row,col,value,color,attrib=Ncurses::A_NORMAL)
1029
- #$log.debug " pad printstring #{row} - #{@top} , #{col} - #{@left} "
1030
- raise "printstring row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
1031
- #$log.warn "printstring row < top, pls correct code #{row} #{@top} " if row < @top
1032
- super(row - @top, col - @left, value, color, attrib)
1033
- end # printstring
1034
- # convenience method so that pad can use print_border but remove screen's row and col
1035
- # Please note that this requires that buffer have latest top and left.
1036
- def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
1037
- $log.debug " pad printborder #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} "
1038
- raise "print_border: row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
1039
- #$log.warn "print_border: row < top, pls correct code #{row} #{@top} " if row < @top
1040
- super(row - @top, col - @left, height, width, color, att)
1041
- end
1042
- def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
1043
- $log.debug " pad printborder_only #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} "
1044
- raise "print_border row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left
1045
- super(row - @top, col - @left, height, width, color, att)
1046
- end
1047
- # use in place of mvwhline if your widget could be using a pad or window
1048
- def rb_mvwhline row, col, char, width
1049
- super(row-@top, col-@left, char, width)
1050
- end
1051
- # use in place of mvwvline if your widget could be using a pad or window
1052
- def rb_mvwvline row, col, char, width
1053
- super(row-@top, col-@left, char, width)
1054
- end
1055
- # use in place of mvaddch if your widget could be using a pad or window
1056
- def rb_mvaddch row, col, char
1057
- super(row-@top, col-@left, char)
1058
- end
1059
- end # class Pad
881
+ end
1060
882
  end