rbcurse 1.4.1 → 1.5.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +31 -0
- data/README.markdown +69 -11
- data/VERSION +1 -1
- data/lib/rbcurse.rb +5 -5
- metadata +10 -198
- data/Makefile +0 -21
- data/Manifest.txt +0 -91
- data/TODO +0 -372
- data/TODO2.txt +0 -118
- data/examples/README.txt +0 -67
- data/examples/abasiclist.rb +0 -33
- data/examples/alpmenu.rb +0 -42
- data/examples/app.rb +0 -859
- data/examples/app.sample +0 -10
- data/examples/appdirtree.rb +0 -75
- data/examples/appemail.rb +0 -191
- data/examples/appemaillb.rb +0 -308
- data/examples/appgcompose.rb +0 -315
- data/examples/atree.rb +0 -64
- data/examples/common/file.rb +0 -40
- data/examples/common/rmail.rb +0 -257
- data/examples/data.txt +0 -683
- data/examples/data/README.markdown +0 -9
- data/examples/data/brew.txt +0 -38
- data/examples/data/color.2 +0 -37
- data/examples/data/gemlist.txt +0 -60
- data/examples/data/lotr.txt +0 -12
- data/examples/data/ports.txt +0 -136
- data/examples/data/tasks.txt +0 -27
- data/examples/data/todocsv.csv +0 -28
- data/examples/data/unix1.txt +0 -21
- data/examples/data/unix2.txt +0 -11
- data/examples/dbdemo.rb +0 -495
- data/examples/deprecated/appgmail.rb +0 -952
- data/examples/deprecated/splitp.rb +0 -56
- data/examples/deprecated/testscrolllb.rb +0 -86
- data/examples/deprecated/testscrollp.rb +0 -88
- data/examples/deprecated/testscrollta.rb +0 -80
- data/examples/deprecated/testscrolltable.rb +0 -165
- data/examples/deprecated/testsplit.rb +0 -87
- data/examples/deprecated/testsplit2.rb +0 -123
- data/examples/deprecated/testsplit3.rb +0 -215
- data/examples/deprecated/testsplit3_1.rb +0 -244
- data/examples/deprecated/testsplit3a.rb +0 -215
- data/examples/deprecated/testsplit3b.rb +0 -237
- data/examples/deprecated/testsplitta.rb +0 -148
- data/examples/deprecated/testsplittv.rb +0 -142
- data/examples/deprecated/testsplittvv.rb +0 -144
- data/examples/deprecated/testtpane.rb +0 -215
- data/examples/deprecated/testtpane2.rb +0 -145
- data/examples/deprecated/testtpanetable.rb +0 -203
- data/examples/dirtree.rb +0 -88
- data/examples/experimental/resultsetdemo.rb +0 -280
- data/examples/experimental/testmform.rb +0 -35
- data/examples/experimental/testscroller.rb +0 -117
- data/examples/experimental/teststackflow.rb +0 -111
- data/examples/menu1.rb +0 -112
- data/examples/multispl.rb +0 -86
- data/examples/newmessagebox.rb +0 -130
- data/examples/newtabbedwindow.rb +0 -100
- data/examples/newtesttabp.rb +0 -121
- data/examples/qdfilechooser.rb +0 -68
- data/examples/rfe.rb +0 -1195
- data/examples/rfe_renderer.rb +0 -121
- data/examples/sqlc.rb +0 -454
- data/examples/sqlm.rb +0 -437
- data/examples/sqlt.rb +0 -408
- data/examples/status.txt +0 -68
- data/examples/table1.rb +0 -24
- data/examples/term2.rb +0 -84
- data/examples/test1.rb +0 -239
- data/examples/test2.rb +0 -674
- data/examples/testapp.rb +0 -44
- data/examples/testapp2.rb +0 -58
- data/examples/testchars.rb +0 -137
- data/examples/testcombo.rb +0 -91
- data/examples/testkeypress.rb +0 -66
- data/examples/testlistbox.rb +0 -113
- data/examples/testmenu.rb +0 -101
- data/examples/testmulticomp.rb +0 -70
- data/examples/testmulticontainer.rb +0 -94
- data/examples/testmultispl.rb +0 -199
- data/examples/testree.rb +0 -106
- data/examples/testtable.rb +0 -263
- data/examples/testtabp.rb +0 -107
- data/examples/testtodo.rb +0 -584
- data/examples/testvimsplit.rb +0 -112
- data/examples/testwsshortcuts.rb +0 -64
- data/examples/testwsshortcuts2.rb +0 -126
- data/examples/todo.db +0 -0
- data/examples/todo.yml +0 -191
- data/examples/viewtodo.rb +0 -574
- data/lib/rbcurse/action.rb +0 -40
- data/lib/rbcurse/app.rb +0 -1374
- data/lib/rbcurse/applicationheader.rb +0 -102
- data/lib/rbcurse/celleditor.rb +0 -112
- data/lib/rbcurse/checkboxcellrenderer.rb +0 -57
- data/lib/rbcurse/colormap.rb +0 -159
- data/lib/rbcurse/comboboxcellrenderer.rb +0 -30
- data/lib/rbcurse/common/ansiparser.rb +0 -117
- data/lib/rbcurse/common/appmethods.rb +0 -112
- data/lib/rbcurse/common/basestack.rb +0 -407
- data/lib/rbcurse/common/bordertitle.rb +0 -41
- data/lib/rbcurse/common/chunk.rb +0 -177
- data/lib/rbcurse/common/colorparser.rb +0 -71
- data/lib/rbcurse/common/keydefs.rb +0 -30
- data/lib/rbcurse/common/widgetshortcuts.rb +0 -302
- data/lib/rbcurse/defaultlistselectionmodel.rb +0 -79
- data/lib/rbcurse/deprecated/README.markdown +0 -12
- data/lib/rbcurse/deprecated/rscrollpane.rb +0 -512
- data/lib/rbcurse/deprecated/rsplitpane.rb +0 -894
- data/lib/rbcurse/deprecated/rsplitpane2.rb +0 -1009
- data/lib/rbcurse/deprecated/rviewport.rb +0 -204
- data/lib/rbcurse/experimental/README.markdown +0 -14
- data/lib/rbcurse/experimental/resultsettextview.rb +0 -585
- data/lib/rbcurse/experimental/stackflow.rb +0 -478
- data/lib/rbcurse/extras/bottomline.rb +0 -1850
- data/lib/rbcurse/extras/box.rb +0 -58
- data/lib/rbcurse/extras/directorylist.rb +0 -467
- data/lib/rbcurse/extras/directorytree.rb +0 -69
- data/lib/rbcurse/extras/divider.rb +0 -310
- data/lib/rbcurse/extras/focusmanager.rb +0 -31
- data/lib/rbcurse/extras/horizlist.rb +0 -203
- data/lib/rbcurse/extras/listselectable.rb +0 -264
- data/lib/rbcurse/extras/masterdetail.rb +0 -166
- data/lib/rbcurse/extras/menutree.rb +0 -63
- data/lib/rbcurse/extras/multiform.rb +0 -330
- data/lib/rbcurse/extras/multilinelabel.rb +0 -142
- data/lib/rbcurse/extras/newmessagebox.rb +0 -328
- data/lib/rbcurse/extras/newtabbedpane.rb +0 -612
- data/lib/rbcurse/extras/newtabbedwindow.rb +0 -68
- data/lib/rbcurse/extras/padreader.rb +0 -189
- data/lib/rbcurse/extras/rcomboedit.rb +0 -256
- data/lib/rbcurse/extras/resultsetbrowser.rb +0 -281
- data/lib/rbcurse/extras/rlink.rb +0 -27
- data/lib/rbcurse/extras/rmenulink.rb +0 -21
- data/lib/rbcurse/extras/scrollbar.rb +0 -143
- data/lib/rbcurse/extras/statusline.rb +0 -94
- data/lib/rbcurse/extras/stdscrwindow.rb +0 -309
- data/lib/rbcurse/extras/tableextended.rb +0 -40
- data/lib/rbcurse/extras/tabular.rb +0 -264
- data/lib/rbcurse/extras/tabularwidget.rb +0 -1150
- data/lib/rbcurse/extras/textpad.rb +0 -516
- data/lib/rbcurse/extras/viewer.rb +0 -136
- data/lib/rbcurse/io.rb +0 -850
- data/lib/rbcurse/keylabelprinter.rb +0 -178
- data/lib/rbcurse/listcellrenderer.rb +0 -140
- data/lib/rbcurse/listeditable.rb +0 -310
- data/lib/rbcurse/listkeys.rb +0 -37
- data/lib/rbcurse/listscrollable.rb +0 -564
- data/lib/rbcurse/listselectable.rb +0 -142
- data/lib/rbcurse/mapper.rb +0 -130
- data/lib/rbcurse/orderedhash.rb +0 -77
- data/lib/rbcurse/ractionevent.rb +0 -67
- data/lib/rbcurse/rbasiclistbox.rb +0 -768
- data/lib/rbcurse/rchangeevent.rb +0 -27
- data/lib/rbcurse/rcombo.rb +0 -238
- data/lib/rbcurse/rcommandwindow.rb +0 -587
- data/lib/rbcurse/rcontainer.rb +0 -415
- data/lib/rbcurse/rdialogs.rb +0 -451
- data/lib/rbcurse/rinputdataevent.rb +0 -47
- data/lib/rbcurse/rlistbox.rb +0 -1196
- data/lib/rbcurse/rmenu.rb +0 -939
- data/lib/rbcurse/rmessagebox.rb +0 -348
- data/lib/rbcurse/rmulticontainer.rb +0 -304
- data/lib/rbcurse/rmultisplit.rb +0 -722
- data/lib/rbcurse/rmultitextview.rb +0 -306
- data/lib/rbcurse/rpopupmenu.rb +0 -755
- data/lib/rbcurse/rprogress.rb +0 -118
- data/lib/rbcurse/rscrollform.rb +0 -418
- data/lib/rbcurse/rtabbedpane.rb +0 -1158
- data/lib/rbcurse/rtabbedwindow.rb +0 -167
- data/lib/rbcurse/rtable.rb +0 -1718
- data/lib/rbcurse/rtextarea.rb +0 -920
- data/lib/rbcurse/rtextview.rb +0 -761
- data/lib/rbcurse/rtree.rb +0 -780
- data/lib/rbcurse/rvimsplit.rb +0 -763
- data/lib/rbcurse/rwidget.rb +0 -2915
- data/lib/rbcurse/scrollable.rb +0 -301
- data/lib/rbcurse/table/tablecellrenderer.rb +0 -86
- data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -98
- data/lib/rbcurse/tree/treecellrenderer.rb +0 -150
- data/lib/rbcurse/tree/treemodel.rb +0 -428
- data/lib/rbcurse/undomanager.rb +0 -188
- data/lib/rbcurse/vieditable.rb +0 -144
- data/lib/ver/keyboard.rb +0 -150
- data/lib/ver/keyboard2.rb +0 -170
- data/lib/ver/ncurses.rb +0 -218
- data/lib/ver/panel.rb +0 -162
- data/lib/ver/rpad.rb +0 -375
- data/lib/ver/window.rb +0 -882
- data/test/test_rbcurse.rb +0 -0
data/lib/ver/rpad.rb
DELETED
@@ -1,375 +0,0 @@
|
|
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
DELETED
@@ -1,882 +0,0 @@
|
|
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
|
-
#
|
17
|
-
require 'ver/ncurses'
|
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
|
-
|
31
|
-
module VER
|
32
|
-
class Window
|
33
|
-
attr_reader :width, :height, :top, :left
|
34
|
-
attr_accessor :layout # hash containing hwtl
|
35
|
-
attr_reader :panel # reader requires so he can del it in end
|
36
|
-
attr_reader :window_type # window or pad to distinguish 2009-11-02 23:11
|
37
|
-
attr_accessor :name # more for debugging log files. 2010-02-02 19:58
|
38
|
-
attr_accessor :modified # has it been modified and may need a refresh
|
39
|
-
attr_reader :bottomline # experimental here 2010-11-03 22:19
|
40
|
-
|
41
|
-
# @param [Array, Hash] window coordinates (ht, w, top, left)
|
42
|
-
# or
|
43
|
-
# @param [int, int, int, int] window coordinates (ht, w, top, left)
|
44
|
-
# 2011-09-21 allowing array, or 4 ints, in addition to hash @since 1.3.1
|
45
|
-
def initialize(*args)
|
46
|
-
|
47
|
-
case args.size
|
48
|
-
when 1
|
49
|
-
case args[0]
|
50
|
-
when Array, Hash
|
51
|
-
layout = args[0]
|
52
|
-
else
|
53
|
-
raise ArgumentError, "Window expects 4 ints, array of 4 ints, or Hash in constructor"
|
54
|
-
end
|
55
|
-
when 4
|
56
|
-
layout = { :height => args[0], :width => args[1], :top => args[2], :left => args[3] }
|
57
|
-
end
|
58
|
-
|
59
|
-
@visible = true
|
60
|
-
reset_layout(layout)
|
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
|
-
|
67
|
-
@window = FFI::NCurses.newwin(@height, @width, @top, @left) # added FFI 2011-09-6
|
68
|
-
@panel = Ncurses::Panel.new(@window) # added FFI 2011-09-6
|
69
|
-
#$error_message_row = $status_message_row = Ncurses.LINES-1
|
70
|
-
$error_message_row ||= Ncurses.LINES-1
|
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
|
73
|
-
init_vars
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
def init_vars
|
78
|
-
@window_type = :WINDOW
|
79
|
-
Ncurses::keypad(@window, true)
|
80
|
-
@stack = []
|
81
|
-
@name ||="#{self}"
|
82
|
-
@modified = true
|
83
|
-
$catch_alt_digits ||= false # is this where is should put globals ? 2010-03-14 14:00 XXX
|
84
|
-
#init_bottomline # bottomline to creates its own window 2011-10-8
|
85
|
-
end
|
86
|
-
##
|
87
|
-
# this is an alternative constructor
|
88
|
-
def self.root_window(layout = { :height => 0, :width => 0, :top => 0, :left => 0 })
|
89
|
-
#VER::start_ncurses
|
90
|
-
@layout = layout
|
91
|
-
@window = Window.new(@layout)
|
92
|
-
@window.name = "Window::ROOTW"
|
93
|
-
@window.wrefresh
|
94
|
-
Ncurses::Panel.update_panels
|
95
|
-
return @window
|
96
|
-
end
|
97
|
-
# 2009-10-13 12:24
|
98
|
-
# not used as yet
|
99
|
-
# this is an alternative constructor
|
100
|
-
# created if you don't want to create a hash first
|
101
|
-
# 2011-09-21 V1.3.1 You can now send an array to Window constructor
|
102
|
-
def self.create_window(h=0, w=0, t=0, l=0)
|
103
|
-
layout = { :height => h, :width => w, :top => t, :left => l }
|
104
|
-
@window = Window.new(layout)
|
105
|
-
return @window
|
106
|
-
end
|
107
|
-
|
108
|
-
def resize_with(layout)
|
109
|
-
$log.debug " DARN ! This awready duz a resize!! if h or w or even top or left changed!!! XXX"
|
110
|
-
reset_layout(layout)
|
111
|
-
#@window.wresize(height, width)
|
112
|
-
wresize(height, width)
|
113
|
-
#FFI::NCurses.wresize(@window,height, width)
|
114
|
-
# this is dicey since we often change top and left in pads only for panning !! XXX
|
115
|
-
#@window.mvwin(top, left)
|
116
|
-
mvwin(top, left)
|
117
|
-
#FFI::NCurses.mvwin(@window, top, left)
|
118
|
-
end
|
119
|
-
|
120
|
-
%w[width height top left].each do |side|
|
121
|
-
eval(
|
122
|
-
"def #{side}=(n)
|
123
|
-
return if n == #{side}
|
124
|
-
@layout[:#{side}] = n
|
125
|
-
resize_with @layout
|
126
|
-
end"
|
127
|
-
)
|
128
|
-
end
|
129
|
-
# ADDED DUE TO FFI
|
130
|
-
def wrefresh
|
131
|
-
Ncurses.wrefresh(@window)
|
132
|
-
end
|
133
|
-
def delwin # 2011-09-7
|
134
|
-
Ncurses.delwin(@window)
|
135
|
-
end
|
136
|
-
def attron *args
|
137
|
-
FFI::NCurses.wattron @window, *args
|
138
|
-
end
|
139
|
-
def attroff *args
|
140
|
-
FFI::NCurses.wattroff @window, *args
|
141
|
-
end
|
142
|
-
#
|
143
|
-
# ## END FFI
|
144
|
-
|
145
|
-
def resize
|
146
|
-
resize_with(@layout)
|
147
|
-
end
|
148
|
-
|
149
|
-
# Ncurses
|
150
|
-
|
151
|
-
def pos
|
152
|
-
return y, x
|
153
|
-
end
|
154
|
-
|
155
|
-
def y
|
156
|
-
Ncurses.getcury(@window)
|
157
|
-
end
|
158
|
-
|
159
|
-
def x
|
160
|
-
Ncurses.getcurx(@window)
|
161
|
-
end
|
162
|
-
|
163
|
-
def x=(n) move(y, n) end
|
164
|
-
def y=(n) move(n, x) end
|
165
|
-
|
166
|
-
#def move(y, x)
|
167
|
-
#return unless @visible
|
168
|
-
## Log.debug([y, x] => caller[0,4])
|
169
|
-
##@window.wmove(y, x) # bombing since ffi-ncurses 0.4.0 (maybe it was never called
|
170
|
-
##earlier. was crashing in appemail.rb testchoose.
|
171
|
-
#wmove y,x # can alias it
|
172
|
-
#end
|
173
|
-
# since include FFI is taking over, i need to force it here. not going into
|
174
|
-
# method_missing
|
175
|
-
def wmove y,x
|
176
|
-
#Ncurses.wmove @window, y, x
|
177
|
-
FFI::NCurses.wmove @window, y, x
|
178
|
-
end
|
179
|
-
alias :move :wmove
|
180
|
-
|
181
|
-
# while moving from ncurses-ruby to FFI need to pass window pointer
|
182
|
-
# for w methods as well as mvw - NOT COMING HERE due to include FFI
|
183
|
-
def OLDmethod_missing(meth, *args)
|
184
|
-
$log.debug " WWWW method missing #{meth} "
|
185
|
-
if meth[0,1]=="w" || meth[0,3] == "mvw"
|
186
|
-
$log.debug " WWWW method missing #{meth} adding window in call "
|
187
|
-
#return @window.send(meth, @window, *args)
|
188
|
-
return FFI::NCurses.send(meth, @window, *args)
|
189
|
-
else
|
190
|
-
end
|
191
|
-
if @window
|
192
|
-
if @window.respond_to? meth
|
193
|
-
@window.send(meth, *args)
|
194
|
-
else
|
195
|
-
FFI::NCurses.send( meth, *args)
|
196
|
-
end
|
197
|
-
else
|
198
|
-
FFI::NCurses.send( meth, *args)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def method_missing(name, *args)
|
203
|
-
name = name.to_s
|
204
|
-
if (name[0,2] == "mv")
|
205
|
-
test_name = name.dup
|
206
|
-
test_name[2,0] = "w" # insert "w" after"mv"
|
207
|
-
if (FFI::NCurses.respond_to?(test_name))
|
208
|
-
return FFI::NCurses.send(test_name, @window, *args)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
test_name = "w" + name
|
212
|
-
if (FFI::NCurses.respond_to?(test_name))
|
213
|
-
return FFI::NCurses.send(test_name, @window, *args)
|
214
|
-
end
|
215
|
-
FFI::NCurses.send(name, @window, *args)
|
216
|
-
end
|
217
|
-
def respond_to?(name)
|
218
|
-
name = name.to_s
|
219
|
-
if (name[0,2] == "mv" && FFI::NCurses.respond_to?("mvw" + name[2..-1]))
|
220
|
-
return true
|
221
|
-
end
|
222
|
-
FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name)
|
223
|
-
end
|
224
|
-
|
225
|
-
# NOTE: many of these methods using width will not work since root windows width
|
226
|
-
# is 0
|
227
|
-
def print(string, width = width)
|
228
|
-
return unless visible?
|
229
|
-
w = width == 0? Ncurses.COLS : width
|
230
|
-
waddnstr(string.to_s, w) # changed 2011 dts
|
231
|
-
end
|
232
|
-
|
233
|
-
# NOTE: many of these methods using width will not work since root windows width
|
234
|
-
# is 0
|
235
|
-
def print_yx(string, y = 0, x = 0)
|
236
|
-
w = width == 0? Ncurses.COLS : width
|
237
|
-
mvwaddnstr(y, x, string, w) # changed 2011 dts
|
238
|
-
end
|
239
|
-
|
240
|
-
# NOTE: many of these methods using width will not work since root windows width
|
241
|
-
# is 0
|
242
|
-
def print_empty_line
|
243
|
-
return unless visible?
|
244
|
-
w = width == 0? Ncurses.COLS : width
|
245
|
-
printw(' ' * w)
|
246
|
-
end
|
247
|
-
|
248
|
-
# NOTE: many of these methods using width will not work since root windows width
|
249
|
-
# is 0
|
250
|
-
def print_line(string)
|
251
|
-
w = width == 0? Ncurses.COLS : width
|
252
|
-
print(string.ljust(w))
|
253
|
-
end
|
254
|
-
|
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)
|
275
|
-
return unless visible?
|
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
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def puts(*strings)
|
302
|
-
print(strings.join("\n") << "\n")
|
303
|
-
end
|
304
|
-
|
305
|
-
def _refresh
|
306
|
-
return unless visible?
|
307
|
-
@window.refresh
|
308
|
-
end
|
309
|
-
|
310
|
-
def wnoutrefresh
|
311
|
-
return unless visible?
|
312
|
-
@window.wnoutrefresh
|
313
|
-
end
|
314
|
-
|
315
|
-
def color=(color)
|
316
|
-
@color = color
|
317
|
-
@window.color_set(color, nil)
|
318
|
-
end
|
319
|
-
|
320
|
-
def highlight_line(color, y, x, max)
|
321
|
-
@window.mvchgat(y, x, max, Ncurses::A_NORMAL, color, nil)
|
322
|
-
end
|
323
|
-
|
324
|
-
def ungetch(ch)
|
325
|
-
Ncurses.ungetch(ch)
|
326
|
-
end
|
327
|
-
|
328
|
-
def getch
|
329
|
-
#c = @window.getch
|
330
|
-
c = Ncurses.getch
|
331
|
-
#if c == Ncurses::KEY_RESIZE
|
332
|
-
|
333
|
-
rescue Interrupt => ex
|
334
|
-
3 # is C-c
|
335
|
-
end
|
336
|
-
|
337
|
-
# 2011-09-23 @since 1.3.1
|
338
|
-
# Added more combinations here. These 2 are just indicative
|
339
|
-
SPECIAL_KEYS = {
|
340
|
-
[27, 79, 50, 81] => 20014, # 'F14',
|
341
|
-
[27, 79, 50, 82] => 20015 # 'F15',
|
342
|
-
}
|
343
|
-
|
344
|
-
# returns control, alt, alt+ctrl, alt+control+shift, F1 .. etc
|
345
|
-
# ALT combinations also send a 27 before the actual key
|
346
|
-
# Please test with above combinations before using on your terminal
|
347
|
-
# added by rkumar 2008-12-12 23:07
|
348
|
-
# 2011-09-23 Redone Control-left, right, and Shift-F5..F10.
|
349
|
-
# Checking for quick press of Alt-Sh-O followed by Alt or printable char
|
350
|
-
# Checking for quick press of Alt-[ followed by Alt or printable char
|
351
|
-
# I attempted keeping a hash of combination arrays but it fails in the above
|
352
|
-
# 2 cases, so abandoned.
|
353
|
-
def getchar
|
354
|
-
while 1
|
355
|
-
ch = getch
|
356
|
-
$log.debug "window getchar() GOT: #{ch}" if ch != -1
|
357
|
-
sf = @stack.first
|
358
|
-
if ch == -1
|
359
|
-
# the returns escape 27 if no key followed it, so its SLOW if you want only esc
|
360
|
-
if @stack.first == 27
|
361
|
-
#$log.debug " -1 stack sizze #{@stack.size}: #{@stack.inspect}, ch #{ch}"
|
362
|
-
case @stack.size
|
363
|
-
when 1
|
364
|
-
@stack.clear
|
365
|
-
return 27
|
366
|
-
when 2 # basically a ALT-O, or alt-[ (79 or 91) this will be really slow since it waits for -1
|
367
|
-
ch = 128 + @stack.last
|
368
|
-
$log.warn "XXX: WARN #{ch} CLEARING stack #{@stack} "
|
369
|
-
@stack.clear
|
370
|
-
return ch
|
371
|
-
else
|
372
|
-
# check up a hash of special keys
|
373
|
-
ret = SPECIAL_KEYS(@stack)
|
374
|
-
return ret if ret
|
375
|
-
$log.warn "INVALID UNKNOWN KEY: SHOULD NOT COME HERE getchar():#{@stack}"
|
376
|
-
end
|
377
|
-
end
|
378
|
-
# possibly a 49 left over from M3-1
|
379
|
-
unless @stack.empty?
|
380
|
-
if @stack.size == 1
|
381
|
-
@stack.clear
|
382
|
-
return sf
|
383
|
-
end
|
384
|
-
$log.warn "something on stack getchar(): #{@stack} "
|
385
|
-
end
|
386
|
-
# comemnt after testing keys since this will be called a lot, even stack.clear is called a lot
|
387
|
-
$log.warn "ERROR CLEARING STACK WITH STUFF ON IT getchar():#{@stack}" if ($log.debug? && !@stack.empty?)
|
388
|
-
@stack.clear
|
389
|
-
next
|
390
|
-
end # -1
|
391
|
-
# this is the ALT combination
|
392
|
-
if @stack.first == 27
|
393
|
-
# experimental. 2 escapes in quick succession to make exit faster
|
394
|
-
if @stack.size == 1 && ch == 27
|
395
|
-
@stack.clear
|
396
|
-
return ch
|
397
|
-
end
|
398
|
-
# possible F1..F3 on xterm-color
|
399
|
-
if ch == 79 || ch == 91
|
400
|
-
#$log.debug " got 27, #{ch}, waiting for one more"
|
401
|
-
@stack << ch
|
402
|
-
next
|
403
|
-
end
|
404
|
-
#$log.debug "stack SIZE #{@stack.size}, #{@stack.inspect}, ch: #{ch}"
|
405
|
-
if @stack == [27,79]
|
406
|
-
# xterm-color
|
407
|
-
case ch
|
408
|
-
when 80
|
409
|
-
ch = FFI::NCurses::KEY_F1
|
410
|
-
when 81
|
411
|
-
ch = FFI::NCurses::KEY_F2
|
412
|
-
when 82
|
413
|
-
ch = FFI::NCurses::KEY_F3
|
414
|
-
when 83
|
415
|
-
ch = FFI::NCurses::KEY_F4
|
416
|
-
#when 27 # another alt-char following Alt-Sh-O
|
417
|
-
else
|
418
|
-
## iterm2 uses these for HOME END num keyboard keys
|
419
|
-
@stack.clear
|
420
|
-
#@stack << ch # earlier we pushed this but it could be of use
|
421
|
-
#return 128 + 79
|
422
|
-
return 128 + 79 + ch
|
423
|
-
|
424
|
-
end
|
425
|
-
@stack.clear
|
426
|
-
return ch
|
427
|
-
elsif @stack == [27, 91]
|
428
|
-
# XXX 27, 91 also is Alt-[
|
429
|
-
if ch == 90
|
430
|
-
@stack.clear
|
431
|
-
return KEY_BTAB # backtab
|
432
|
-
elsif ch == 53 || ch == 50 || ch == 51
|
433
|
-
# control left, right and shift function
|
434
|
-
@stack << ch
|
435
|
-
next
|
436
|
-
elsif ch == 27 # another alt-char immediately after Alt-[
|
437
|
-
$log.debug "getchar in 27, will return 128+91 " if $log.debug?
|
438
|
-
@stack.clear
|
439
|
-
@stack << ch
|
440
|
-
return 128 + 91
|
441
|
-
else
|
442
|
-
$log.debug "getchar in other, will return 128+91: #{ch} " if $log.debug?
|
443
|
-
# other cases Alt-[ followed by some char or key - merge with previous
|
444
|
-
@stack.clear
|
445
|
-
@stack << ch
|
446
|
-
return 128 + 91
|
447
|
-
end
|
448
|
-
elsif @stack == [27, 91, 53]
|
449
|
-
if ch == 68
|
450
|
-
@stack.clear
|
451
|
-
return C_LEFT # control-left
|
452
|
-
elsif ch == 67
|
453
|
-
@stack.clear
|
454
|
-
return C_RIGHT # -control-rt
|
455
|
-
end
|
456
|
-
elsif @stack == [27, 91, 51]
|
457
|
-
if ch == 49 && getch()== 126
|
458
|
-
@stack.clear
|
459
|
-
return 20009 # sh_f9
|
460
|
-
end
|
461
|
-
elsif @stack == [27, 91, 50]
|
462
|
-
if ch == 50 && getch()== 126
|
463
|
-
@stack.clear
|
464
|
-
return 20010 # sh-F10
|
465
|
-
end
|
466
|
-
if ch == 57 && getch()== 126
|
467
|
-
@stack.clear
|
468
|
-
return 20008 # sh-F8
|
469
|
-
elsif ch == 56 && getch()== 126
|
470
|
-
@stack.clear
|
471
|
-
return 20007 # sh-F7
|
472
|
-
elsif ch == 54 && getch()== 126
|
473
|
-
@stack.clear
|
474
|
-
return 20006 # sh-F6
|
475
|
-
elsif ch == 53 && getch()== 126
|
476
|
-
@stack.clear
|
477
|
-
return 20005 # sh-F5
|
478
|
-
end
|
479
|
-
end
|
480
|
-
# the usual Meta combos. (alt) - this is screwing it up, just return it in some way
|
481
|
-
ch = 128 + ch
|
482
|
-
@stack.clear
|
483
|
-
return ch
|
484
|
-
end # stack.first == 27
|
485
|
-
# append a 27 to stack, actually one can use a flag too
|
486
|
-
if ch == 27
|
487
|
-
@stack << 27
|
488
|
-
next
|
489
|
-
end
|
490
|
-
return ch
|
491
|
-
end # while
|
492
|
-
end # def
|
493
|
-
|
494
|
-
# doesn't seem to work, clears first line, not both
|
495
|
-
def clear
|
496
|
-
# return unless visible?
|
497
|
-
move 0, 0
|
498
|
-
puts *Array.new(height){ ' ' * (width - 1) }
|
499
|
-
end
|
500
|
-
|
501
|
-
# setup and reset
|
502
|
-
|
503
|
-
## allow user to send an array
|
504
|
-
# I am tired of the hash layout (taken from ver).
|
505
|
-
def reset_layout(layout)
|
506
|
-
case layout
|
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
|
510
|
-
@height, @width, @top, @left = *layout
|
511
|
-
raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil?
|
512
|
-
|
513
|
-
@layout = { :height => @height, :width => @width, :top => @top, :left => @top }
|
514
|
-
when Hash
|
515
|
-
@layout = layout
|
516
|
-
|
517
|
-
[:height, :width, :top, :left].each do |name|
|
518
|
-
instance_variable_set("@#{name}", layout_value(name))
|
519
|
-
end
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
# removed ref to default_for since giving error in FFI 2011-09-8
|
524
|
-
def layout_value(name)
|
525
|
-
value = @layout[name]
|
526
|
-
default = default_for(name)
|
527
|
-
|
528
|
-
value = value.call(default) if value.respond_to?(:call)
|
529
|
-
return (value || default).to_i
|
530
|
-
end
|
531
|
-
|
532
|
-
# this gives error since stdscr is only a pointer at this time
|
533
|
-
def default_for(name)
|
534
|
-
case name
|
535
|
-
when :height, :top
|
536
|
-
#Ncurses.stdscr.getmaxy(stdscr)
|
537
|
-
FFI::NCurses.LINES
|
538
|
-
when :width, :left
|
539
|
-
#Ncurses.stdscr.getmaxx(stdscr)
|
540
|
-
FFI::NCurses.COLS
|
541
|
-
else
|
542
|
-
0
|
543
|
-
end
|
544
|
-
end
|
545
|
-
|
546
|
-
# Ncurses panel
|
547
|
-
|
548
|
-
def hide
|
549
|
-
#return unless visible? # added 2011-10-14 these 2 are not behaving properly
|
550
|
-
Ncurses::Panel.hide_panel @panel.pointer
|
551
|
-
#Ncurses.refresh # wnoutrefresh
|
552
|
-
Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
|
553
|
-
@visible = false
|
554
|
-
end
|
555
|
-
|
556
|
-
def show
|
557
|
-
#return if visible? # added 2011-10-14 these 2 are not behaving properly
|
558
|
-
Ncurses::Panel.show_panel @panel.pointer
|
559
|
-
#Ncurses.refresh # wnoutrefresh
|
560
|
-
Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
|
561
|
-
@visible = true
|
562
|
-
end
|
563
|
-
|
564
|
-
def on_top
|
565
|
-
Ncurses::Panel.top_panel @panel.pointer
|
566
|
-
wnoutrefresh
|
567
|
-
end
|
568
|
-
|
569
|
-
def visible?
|
570
|
-
@visible
|
571
|
-
end
|
572
|
-
|
573
|
-
##
|
574
|
-
# destroy window, panel and any pads that were requested
|
575
|
-
#
|
576
|
-
def destroy
|
577
|
-
# typically the ensure block should have this
|
578
|
-
|
579
|
-
$log.debug "win destroy start"
|
580
|
-
|
581
|
-
Ncurses::Panel.del_panel(@panel.pointer) if @panel
|
582
|
-
delwin() if @window
|
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
|
590
|
-
$log.debug "win destroy end"
|
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
|
-
|
687
|
-
##
|
688
|
-
# prints a string at row, col, with given color and attribute
|
689
|
-
# added by rk 2008-11-29 19:01
|
690
|
-
# I usually use this, not the others ones here
|
691
|
-
# @param r - row
|
692
|
-
# @param c - col
|
693
|
-
# @param string - text to print
|
694
|
-
# @param color - color pair
|
695
|
-
# @ param att - ncurses attribute: normal, bold, reverse, blink,
|
696
|
-
# underline
|
697
|
-
public
|
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)
|
701
|
-
prv_printstring(r,c,string, color, att )
|
702
|
-
end
|
703
|
-
|
704
|
-
## name changed from printstring to prv_prinstring
|
705
|
-
def prv_printstring(r,c,string, color, att = Ncurses::A_NORMAL)
|
706
|
-
|
707
|
-
#$log.debug " #{@name} inside window printstring r #{r} c #{c} #{string} "
|
708
|
-
if att.nil?
|
709
|
-
att = Ncurses::A_NORMAL
|
710
|
-
else
|
711
|
-
att = get_attrib att
|
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
|
728
|
-
|
729
|
-
wattron(Ncurses.COLOR_PAIR(color) | att)
|
730
|
-
mvwprintw(r, c, "%s", :string, string);
|
731
|
-
wattroff(Ncurses.COLOR_PAIR(color) | att)
|
732
|
-
end
|
733
|
-
# @deprecated
|
734
|
-
def print_error_message text=$error_message.get_value
|
735
|
-
alert text
|
736
|
-
end
|
737
|
-
# added by rk 2008-11-29 19:01
|
738
|
-
# @deprecated. use global method of same name in rdialog
|
739
|
-
def print_status_message text=$status_message
|
740
|
-
#VER::print_status_message text
|
741
|
-
alert text
|
742
|
-
end
|
743
|
-
# added by rk 2008-11-29 19:01
|
744
|
-
# Since these methods write directly to window they are not advised
|
745
|
-
# since clearing previous message we don't know how much to clear.
|
746
|
-
# Best to map error_message to a label.
|
747
|
-
# 2010-09-13 00:22 WE should not use these any longer.
|
748
|
-
# Application should create a label and map a Variable named
|
749
|
-
# $errormessage to it. We should only update the Variable
|
750
|
-
def DEPRECATED_print_error_message text=$error_message.get_value
|
751
|
-
r = $error_message_row || Ncurses.LINES-1
|
752
|
-
c = $error_message_col || (Ncurses.COLS-text.length)/2
|
753
|
-
|
754
|
-
$log.debug "got ERROR MESSAGE #{text} row #{r} "
|
755
|
-
clear_error r, $datacolor
|
756
|
-
printstring r, c, text, color = $promptcolor
|
757
|
-
$error_message_clear_pending = true
|
758
|
-
end
|
759
|
-
# added by rk 2008-11-29 19:01
|
760
|
-
# @deprecated. use global method of same name
|
761
|
-
def DEPRECATED_print_status_message text=$status_message
|
762
|
-
r = $status_message_row || Ncurses.LINES-1
|
763
|
-
clear_error r, $datacolor
|
764
|
-
# print it in centre
|
765
|
-
printstring r, (Ncurses.COLS-text.length)/2, text, color = $promptcolor
|
766
|
-
end
|
767
|
-
# Clear error message printed
|
768
|
-
# I am not only clearing if something was printed. This is since
|
769
|
-
# certain small forms like TabbedForm top form throw an error on printstring.
|
770
|
-
# @deprecated
|
771
|
-
def clear_error r = $error_message_row, color = $datacolor
|
772
|
-
return unless $error_message_clear_pending
|
773
|
-
c = $error_message_col || (Ncurses.COLS-text.length)/2
|
774
|
-
sz = $error_message_size || Ncurses.COLS
|
775
|
-
printstring(r, c, "%-*s" % [sz, " "], color)
|
776
|
-
$error_message_clear_pending = false
|
777
|
-
end
|
778
|
-
##
|
779
|
-
# NOTE : FOR MESSAGEBOXES ONLY !!!!
|
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
|
-
|
795
|
-
mvwaddch row, col, Ncurses::ACS_ULCORNER
|
796
|
-
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6)
|
797
|
-
mvwaddch row, col+width-5, Ncurses::ACS_URCORNER
|
798
|
-
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-4)
|
799
|
-
|
800
|
-
mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER
|
801
|
-
mvwhline(row+height-3, col+1, Ncurses::ACS_HLINE, width-6)
|
802
|
-
mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER
|
803
|
-
mvwvline( row+1, col+width-5, Ncurses::ACS_VLINE, height-4)
|
804
|
-
end
|
805
|
-
##
|
806
|
-
# prints a border around a widget, CLEARING the area.
|
807
|
-
# If calling with a pad, you would typically use 0,0, h-1, w-1.
|
808
|
-
def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
|
809
|
-
raise "height needs to be supplied." if height.nil?
|
810
|
-
raise "width needs to be supplied." if width.nil?
|
811
|
-
att ||= Ncurses::A_NORMAL
|
812
|
-
|
813
|
-
$log.debug " inside window print_border r #{row} c #{col} h #{height} w #{width} "
|
814
|
-
|
815
|
-
# 2009-11-02 00:45 made att nil for blanking out
|
816
|
-
# FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view
|
817
|
-
# when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53
|
818
|
-
ww=width-2
|
819
|
-
(row+1).upto(row+height-1) do |r|
|
820
|
-
prv_printstring( r, col+1," "*ww , color, att)
|
821
|
-
end
|
822
|
-
prv_print_border_only row, col, height, width, color, att
|
823
|
-
end
|
824
|
-
def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
|
825
|
-
prv_print_border_only row, col, height, width, color, att
|
826
|
-
end
|
827
|
-
|
828
|
-
|
829
|
-
## print just the border, no cleanup
|
830
|
-
#+ Earlier, we would clean up. Now in some cases, i'd like
|
831
|
-
#+ to print border over what's been done.
|
832
|
-
# XXX this reduces 1 from width but not height !!! FIXME
|
833
|
-
def prv_print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL
|
834
|
-
if att.nil?
|
835
|
-
att = Ncurses::A_NORMAL
|
836
|
-
else
|
837
|
-
att = get_attrib att
|
838
|
-
end
|
839
|
-
wattron(Ncurses.COLOR_PAIR(color) | att)
|
840
|
-
mvwaddch row, col, Ncurses::ACS_ULCORNER
|
841
|
-
mvwhline( row, col+1, Ncurses::ACS_HLINE, width-2)
|
842
|
-
mvwaddch row, col+width-1, Ncurses::ACS_URCORNER
|
843
|
-
mvwvline( row+1, col, Ncurses::ACS_VLINE, height-1)
|
844
|
-
|
845
|
-
mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER
|
846
|
-
mvwhline(row+height-0, col+1, Ncurses::ACS_HLINE, width-2)
|
847
|
-
mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER
|
848
|
-
mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1)
|
849
|
-
wattroff(Ncurses.COLOR_PAIR(color) | att)
|
850
|
-
end
|
851
|
-
# This used to return an Ncurses window object, and you could call methods on it
|
852
|
-
# Now it returns a FFI::NCurses.window pointer which you cannot call methods on.
|
853
|
-
# You have to pass it to FFI::NCurses.<method>
|
854
|
-
def get_window; @window; end
|
855
|
-
def to_s; @name || self; end
|
856
|
-
# use in place of mvwhline if your widget could be using a pad or window
|
857
|
-
def rb_mvwhline row, col, char, width
|
858
|
-
mvwhline row, col, char, width
|
859
|
-
end
|
860
|
-
# use in place of mvwvline if your widget could be using a pad or window
|
861
|
-
def rb_mvwvline row, col, char, width
|
862
|
-
mvwvline row, col, char, width
|
863
|
-
end
|
864
|
-
# use in place of mvaddch if your widget could be using a pad or window
|
865
|
-
def rb_mvaddch row, col, char
|
866
|
-
mvaddch row, col, char
|
867
|
-
end
|
868
|
-
# experimentally
|
869
|
-
# Add a bottomline to window when creating root_window
|
870
|
-
# this way its available even when App is not used.
|
871
|
-
def init_bottomline
|
872
|
-
unless @bottomline
|
873
|
-
require 'forwardable'
|
874
|
-
require 'rbcurse/extras/bottomline'
|
875
|
-
@bottomline = RubyCurses::Bottomline.new self, $error_message_row
|
876
|
-
@bottomline.name = "window.rb"
|
877
|
-
extend Forwardable
|
878
|
-
def_delegators :@bottomline, :ask, :say, :agree, :choose
|
879
|
-
end
|
880
|
-
end
|
881
|
-
end
|
882
|
-
end
|