rbcurse 0.1.3 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +126 -0
- data/Manifest.txt +53 -20
- data/README.markdown +423 -0
- data/Rakefile +3 -1
- data/examples/keytest.rb +177 -0
- data/examples/mpad2.rb +156 -0
- data/examples/newtesttabp.rb +121 -0
- data/examples/rfe.rb +48 -10
- data/examples/rfe_renderer.rb +4 -4
- data/examples/rvimsplit.rb +376 -0
- data/examples/sqlc.rb +97 -106
- data/examples/sqlm.rb +446 -0
- data/examples/test1.rb +4 -4
- data/examples/test2.rb +12 -12
- data/examples/testchars.rb +140 -0
- data/examples/testkeypress.rb +9 -4
- data/examples/testmulticomp.rb +72 -0
- data/examples/testscroller.rb +136 -0
- data/examples/testscrolllb.rb +86 -0
- data/examples/testscrollp.rb +87 -0
- data/examples/testscrollta.rb +80 -0
- data/examples/testscrolltable.rb +166 -0
- data/examples/testsplit.rb +87 -0
- data/examples/testsplit2.rb +123 -0
- data/examples/testsplit3.rb +215 -0
- data/examples/testsplit3_1.rb +244 -0
- data/examples/testsplit3a.rb +215 -0
- data/examples/testsplit3b.rb +237 -0
- data/examples/testsplitta.rb +148 -0
- data/examples/testsplittv.rb +142 -0
- data/examples/testsplittvv.rb +144 -0
- data/examples/testtable.rb +1 -1
- data/examples/testtabp.rb +3 -2
- data/examples/testtestw.rb +69 -0
- data/examples/testtodo.rb +5 -3
- data/examples/testtpane.rb +203 -0
- data/examples/testtpane2.rb +145 -0
- data/examples/testtpanetable.rb +199 -0
- data/examples/viewtodo.rb +5 -3
- data/lib/rbcurse.rb +1 -1
- data/lib/rbcurse/celleditor.rb +2 -2
- data/lib/rbcurse/colormap.rb +5 -5
- data/lib/rbcurse/defaultlistselectionmodel.rb +3 -3
- data/lib/rbcurse/io.rb +663 -0
- data/lib/rbcurse/listeditable.rb +306 -0
- data/lib/rbcurse/listkeys.rb +15 -15
- data/lib/rbcurse/listscrollable.rb +168 -27
- data/lib/rbcurse/mapper.rb +35 -13
- data/lib/rbcurse/rchangeevent.rb +28 -0
- data/lib/rbcurse/rform.rb +845 -0
- data/lib/rbcurse/rlistbox.rb +144 -34
- data/lib/rbcurse/rmessagebox.rb +10 -5
- data/lib/rbcurse/rmulticontainer.rb +325 -0
- data/lib/rbcurse/rmultitextview.rb +306 -0
- data/lib/rbcurse/rscrollform.rb +369 -0
- data/lib/rbcurse/rscrollpane.rb +511 -0
- data/lib/rbcurse/rsplitpane.rb +820 -0
- data/lib/rbcurse/rtabbedpane.rb +737 -109
- data/lib/rbcurse/rtabbedwindow.rb +326 -0
- data/lib/rbcurse/rtable.rb +220 -64
- data/lib/rbcurse/rtextarea.rb +340 -181
- data/lib/rbcurse/rtextview.rb +237 -101
- data/lib/rbcurse/rviewport.rb +203 -0
- data/lib/rbcurse/rwidget.rb +919 -95
- data/lib/rbcurse/scrollable.rb +7 -7
- data/lib/rbcurse/selectable.rb +4 -4
- data/lib/rbcurse/table/tablecellrenderer.rb +3 -0
- data/lib/rbcurse/undomanager.rb +181 -0
- data/lib/rbcurse/vieditable.rb +100 -0
- data/lib/ver/window.rb +471 -21
- metadata +66 -22
- data/README.txt +0 -312
- data/examples/testd.db +0 -0
- data/examples/todocsv.csv +0 -28
data/examples/rfe.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
#####################################################
|
2
|
+
# This is a sample program demonstrating a 2 pane file explorer using
|
3
|
+
# rbcurse's widgets.
|
4
|
+
# I have used a listbox here, perhaps a Table would be more configurable
|
5
|
+
# than a listbox.
|
6
|
+
#
|
7
|
+
# Copyright rkumar 2009, 2010 under Ruby License.
|
8
|
+
#
|
9
|
+
####################################################
|
1
10
|
require 'rubygems'
|
2
11
|
require 'ncurses'
|
3
12
|
require 'logger'
|
@@ -10,6 +19,7 @@ require 'rbcurse/keylabelprinter'
|
|
10
19
|
require 'rbcurse/applicationheader'
|
11
20
|
require 'rbcurse/action'
|
12
21
|
require 'fileutils'
|
22
|
+
require 'yaml' ## added for 1.9
|
13
23
|
#$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
|
14
24
|
|
15
25
|
# TODO
|
@@ -160,9 +170,9 @@ class FileExplorer
|
|
160
170
|
def readable_file_size(size, precision)
|
161
171
|
case
|
162
172
|
#when size == 1 : "1 B"
|
163
|
-
when size < KILO_SIZE
|
164
|
-
when size < MEGA_SIZE
|
165
|
-
when size < GIGA_SIZE
|
173
|
+
when size < KILO_SIZE then "%d B" % size
|
174
|
+
when size < MEGA_SIZE then "%.#{precision}f K" % (size / KILO_SIZE)
|
175
|
+
when size < GIGA_SIZE then "%.#{precision}f M" % (size / MEGA_SIZE)
|
166
176
|
else "%.#{precision}f G" % (size / GIGA_SIZE)
|
167
177
|
end
|
168
178
|
end
|
@@ -285,13 +295,13 @@ class RFe
|
|
285
295
|
status_row = RubyCurses::Label.new @form, {'text' => "", :row => Ncurses.LINES-4, :col => 0, :display_length=>Ncurses.COLS-2}
|
286
296
|
@status_row = status_row
|
287
297
|
colb = Ncurses.COLS/2
|
288
|
-
ht = Ncurses.LINES -
|
298
|
+
ht = Ncurses.LINES - 5
|
289
299
|
wid = Ncurses.COLS/2 - 0
|
290
300
|
@trash_path = File.expand_path("~/.Trash")
|
291
301
|
@trash_exists = File.directory? @trash_path
|
292
302
|
$log.debug " trash_path #{@trash_path}, #{@trash_exists}"
|
293
|
-
@lista = FileExplorer.new @form, self, row=
|
294
|
-
@listb = FileExplorer.new @form, self, row=
|
303
|
+
@lista = FileExplorer.new @form, self, row=1, col=1, ht, wid
|
304
|
+
@listb = FileExplorer.new @form, self, row=1, col=colb, ht, wid
|
295
305
|
|
296
306
|
init_vars
|
297
307
|
end
|
@@ -306,6 +316,7 @@ class RFe
|
|
306
316
|
end
|
307
317
|
end
|
308
318
|
@config ||={}
|
319
|
+
@stopping = false
|
309
320
|
end
|
310
321
|
def save_config
|
311
322
|
@config["last_dirs"]=[@lista.current_dir(),@listb.current_dir()]
|
@@ -480,7 +491,7 @@ class RFe
|
|
480
491
|
@v_window.wrefresh
|
481
492
|
Ncurses::Panel.update_panels
|
482
493
|
begin
|
483
|
-
while((ch = @v_window.getchar()) != ?\C-q )
|
494
|
+
while((ch = @v_window.getchar()) != ?\C-q.getbyte(0) )
|
484
495
|
break if ch == KEY_F3
|
485
496
|
@v_form.handle_key ch
|
486
497
|
@v_form.repaint
|
@@ -497,6 +508,9 @@ class RFe
|
|
497
508
|
when '.tgz','.gz'
|
498
509
|
cmd = "tar -ztvf #{fp}"
|
499
510
|
content = %x[#{cmd}]
|
511
|
+
when '.zip'
|
512
|
+
cmd = "unzip -l #{fp}"
|
513
|
+
content = %x[#{cmd}]
|
500
514
|
else
|
501
515
|
content = File.open(fp,"r").readlines
|
502
516
|
end
|
@@ -611,6 +625,9 @@ class RFe
|
|
611
625
|
$log.debug " edit #{fp}"
|
612
626
|
shell_out "/opt/local/bin/vim #{fp}"
|
613
627
|
end
|
628
|
+
def stopping?
|
629
|
+
@stopping
|
630
|
+
end
|
614
631
|
def draw_screens
|
615
632
|
lasta = lastb = nil
|
616
633
|
if !@config["last_dirs"].nil?
|
@@ -623,6 +640,26 @@ class RFe
|
|
623
640
|
# @form.bind_key(?\M-x){
|
624
641
|
# @current_list.mark_block
|
625
642
|
# }
|
643
|
+
# i am just testing out double key bindings
|
644
|
+
@form.bind_key([?\C-w,?v]){
|
645
|
+
@status_row.text = "got C-w, v"
|
646
|
+
$log.debug " Got C-w v "
|
647
|
+
view()
|
648
|
+
}
|
649
|
+
@form.bind_key([?\C-w,?e]){
|
650
|
+
@status_row.text = "got C-w, e"
|
651
|
+
$log.debug " Got C-w e "
|
652
|
+
edit()
|
653
|
+
}
|
654
|
+
# bind dd to delete file
|
655
|
+
# actually this should be in listbox, and we should listen for row delete and then call opt_file
|
656
|
+
@form.bind_key([?d,?d]){
|
657
|
+
opt_file 'd'
|
658
|
+
}
|
659
|
+
@form.bind_key([?q,?q]){
|
660
|
+
@stopping = true
|
661
|
+
}
|
662
|
+
# this won't work since the listbox will consume the d first
|
626
663
|
@form.bind_key(?@){
|
627
664
|
@current_list.change_dir File.expand_path("~/")
|
628
665
|
}
|
@@ -633,7 +670,7 @@ class RFe
|
|
633
670
|
@klp.mode :file
|
634
671
|
@klp.repaint
|
635
672
|
## FIXME chr could fail !!
|
636
|
-
while((ch = @window.getchar()) != ?\C-c )
|
673
|
+
while((ch = @window.getchar()) != ?\C-c.getbyte(0) )
|
637
674
|
if "cmdsuvrex".index(ch.chr) == nil
|
638
675
|
Ncurses.beep
|
639
676
|
else
|
@@ -648,7 +685,7 @@ class RFe
|
|
648
685
|
@klp.repaint
|
649
686
|
keys = @klp.get_current_keys
|
650
687
|
## FIXME chr could fail !!
|
651
|
-
while((ch = @window.getchar()) != ?\C-c )
|
688
|
+
while((ch = @window.getchar()) != ?\C-c.getbyte(0) )
|
652
689
|
if !keys.include?(ch.chr)
|
653
690
|
Ncurses.beep
|
654
691
|
else
|
@@ -704,7 +741,8 @@ class RFe
|
|
704
741
|
@window.wrefresh
|
705
742
|
Ncurses::Panel.update_panels
|
706
743
|
begin
|
707
|
-
|
744
|
+
## qq stops program, but only if M-v (vim mode)
|
745
|
+
while(!stopping? && (ch = @window.getchar()) != ?\C-q.getbyte(0) )
|
708
746
|
s = keycode_tos ch
|
709
747
|
status_row.text = "Pressed #{ch} , #{s}"
|
710
748
|
@form.handle_key(ch)
|
data/examples/rfe_renderer.rb
CHANGED
@@ -47,10 +47,10 @@ module RubyCurses
|
|
47
47
|
# Return the file size with a readable style.
|
48
48
|
def readable_file_size(size, precision)
|
49
49
|
case
|
50
|
-
#when size == 1
|
51
|
-
when size < KILO_SIZE
|
52
|
-
when size < MEGA_SIZE
|
53
|
-
when size < GIGA_SIZE
|
50
|
+
#when size == 1 then "1 B"
|
51
|
+
when size < KILO_SIZE then "%d B" % size
|
52
|
+
when size < MEGA_SIZE then "%.#{precision}f K" % (size / KILO_SIZE)
|
53
|
+
when size < GIGA_SIZE then "%.#{precision}f M" % (size / MEGA_SIZE)
|
54
54
|
else "%.#{precision}f G" % (size / GIGA_SIZE)
|
55
55
|
end
|
56
56
|
end
|
@@ -0,0 +1,376 @@
|
|
1
|
+
# this is a test program,
|
2
|
+
# testing out if subwins can help in splitpanes
|
3
|
+
# derwins, although easy to use flunk movement and resizing
|
4
|
+
# So i've changed Window to use subwins, so top and left are maintained
|
5
|
+
# We need to create events for resizing so refreshing window can be done.
|
6
|
+
#
|
7
|
+
# FIXME - resizing, divider change
|
8
|
+
# FIXME - left top 2 splits are not expanding to full height. check in draw box mode
|
9
|
+
# TODO = when resixing a split, if the other one has been split, its children need to be resized.
|
10
|
+
#
|
11
|
+
#$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
|
12
|
+
require 'rubygems'
|
13
|
+
require 'ncurses'
|
14
|
+
require 'logger'
|
15
|
+
require 'rbcurse'
|
16
|
+
|
17
|
+
class Split
|
18
|
+
def initialize type, first, second, win
|
19
|
+
@c1 = first
|
20
|
+
@c2 = second
|
21
|
+
@type = type # :VERTICAL or :HORIZONTAL
|
22
|
+
@parent = win # needed to draw divider on
|
23
|
+
end
|
24
|
+
def first_win; @c1; end
|
25
|
+
def second_win; @c2; end
|
26
|
+
def divider_location y,x
|
27
|
+
@y = y
|
28
|
+
@x = x
|
29
|
+
end
|
30
|
+
|
31
|
+
# change the size of a split
|
32
|
+
# still to redo the line etc.
|
33
|
+
def increase comp, units=1
|
34
|
+
$log.debug " increase got #{comp}, #{comp.class}, #{units} "
|
35
|
+
if @type == :HORIZONTAL
|
36
|
+
if comp == @c1
|
37
|
+
else
|
38
|
+
comp = @c1
|
39
|
+
units *= -1
|
40
|
+
end
|
41
|
+
other = @c2
|
42
|
+
#comp.wclear
|
43
|
+
#other.wclear
|
44
|
+
#comp.wrefresh
|
45
|
+
#other.wrefresh
|
46
|
+
# increase h
|
47
|
+
layout = comp.layout
|
48
|
+
$log.debug " layout #{layout} "
|
49
|
+
h = layout[:height]
|
50
|
+
w = layout[:width]
|
51
|
+
top = layout[:top]
|
52
|
+
left = layout[:left]
|
53
|
+
$log.debug "H1 ht change #{h} , #{h} + #{units} "
|
54
|
+
layout[:height]= h + units
|
55
|
+
divloc = h + units + 1
|
56
|
+
comp.resize_with(layout)
|
57
|
+
# decrease second, and push inc top
|
58
|
+
layout = other.layout
|
59
|
+
h = layout[:height]
|
60
|
+
w = layout[:width]
|
61
|
+
top = layout[:top]
|
62
|
+
left = layout[:left]
|
63
|
+
h = layout[:height]
|
64
|
+
top = layout[:top]
|
65
|
+
layout[:top] = top + units
|
66
|
+
layout[:height] = h- units
|
67
|
+
$log.debug "H1 c2 ht change #{h} , #{h} - #{units}, top #{top} + #{units} "
|
68
|
+
other.resize_with(layout)
|
69
|
+
h = @parent.height
|
70
|
+
w = @parent.width
|
71
|
+
#@parent.mvwhline( divloc, 0, ACS_HLINE, w+2)
|
72
|
+
@y += units
|
73
|
+
#@parent.werase #wclear
|
74
|
+
@parent.wclear
|
75
|
+
# FIXME double line printing ??? after tabbing or hitting a key
|
76
|
+
@parent.mvwhline( @y, 0, ACS_HLINE, w)
|
77
|
+
comp.wrefresh
|
78
|
+
other.wrefresh
|
79
|
+
@parent.wrefresh
|
80
|
+
# do wnoutrefresh and doupdate
|
81
|
+
return
|
82
|
+
end
|
83
|
+
if @type == :VERTICAL
|
84
|
+
if comp == @c1
|
85
|
+
else
|
86
|
+
units *= -1
|
87
|
+
comp = @c1
|
88
|
+
end
|
89
|
+
other = @c2
|
90
|
+
# increase w
|
91
|
+
layout = comp.layout
|
92
|
+
h = layout[:width]
|
93
|
+
layout[:width]= h + units
|
94
|
+
$log.debug "V1 ht change #{h} , #{h} + #{units} "
|
95
|
+
comp.resize_with(layout)
|
96
|
+
# decrease second, and push inc top
|
97
|
+
layout = other.layout
|
98
|
+
h = layout[:width]
|
99
|
+
top = layout[:left]
|
100
|
+
layout[:left] = top + units
|
101
|
+
layout[:width] = h - units
|
102
|
+
$log.debug "V c2 ht change #{h} , #{h} - #{units}, top #{top} + #{units} "
|
103
|
+
other.resize_with(layout)
|
104
|
+
# TODO add line here
|
105
|
+
comp.wclear
|
106
|
+
other.wclear
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
class VimSplit
|
113
|
+
def initialize window, lay
|
114
|
+
# array of window, to delete later
|
115
|
+
@wins = []
|
116
|
+
# mapping of a subwin and its Split, so i can resize
|
117
|
+
@splits = {}
|
118
|
+
|
119
|
+
# hash of windows and component attached
|
120
|
+
@win_comp = {}
|
121
|
+
@children = {} # parent and children array, since we have not designed this properly
|
122
|
+
# only those windows that can be focused, child windows when split, parent is invisible
|
123
|
+
@focusables = []
|
124
|
+
# main window
|
125
|
+
@window = window
|
126
|
+
@splouter = @window._subwin(lay)
|
127
|
+
# (0..@splouter.height).each {|i| @splouter.highlight_line($reversecolor,i,0,@splouter.width)}
|
128
|
+
@wins << @splouter
|
129
|
+
#@focusables << @splouter
|
130
|
+
@splouter.box(0,0)
|
131
|
+
@draw_boxes = false
|
132
|
+
|
133
|
+
@str = "" # dummy
|
134
|
+
end
|
135
|
+
def self.color_window win, color=$datacolor
|
136
|
+
(0..win.height).each {|i| win.highlight_line(color,i,0,win.width)}
|
137
|
+
end
|
138
|
+
# focussed component
|
139
|
+
def current
|
140
|
+
@current || _switch_split
|
141
|
+
end
|
142
|
+
# when we make the first split we want to keep the borders. AFter that we always want to start with zero
|
143
|
+
# so the window we split is "consumed".
|
144
|
+
def get_offset
|
145
|
+
if @wins.length == 1
|
146
|
+
return 1
|
147
|
+
end
|
148
|
+
0
|
149
|
+
end
|
150
|
+
def get_win; @splouter; end
|
151
|
+
|
152
|
+
# splits horizontally at centre
|
153
|
+
# We need to give an initial weight or location for divider
|
154
|
+
def split_h win
|
155
|
+
h = win.height
|
156
|
+
w = win.width
|
157
|
+
off = get_offset()
|
158
|
+
#lay1 = { :height => h/2-0, :width => w-2, :top => 0, :left => off }
|
159
|
+
#lay2 = { :height => h/2-1, :width => w-2, :top => h/2+1, :left => 1 }
|
160
|
+
lay1 = { :height => h/2-0, :width => w-2, :top => off, :left => off }
|
161
|
+
lay2 = { :height => h/2-1, :width => w-2, :top => h/2+1, :left => off }
|
162
|
+
split1 = win._subwin(lay1)
|
163
|
+
split2 = win._subwin(lay2)
|
164
|
+
win.mvwhline( h/2, 0, ACS_HLINE, w+2)
|
165
|
+
|
166
|
+
if @draw_boxes
|
167
|
+
split1.box(0,0)
|
168
|
+
split2.box(0,0)
|
169
|
+
end
|
170
|
+
# if a window is split, then tab doesn't go there, it goes to its two subwins
|
171
|
+
@focusables.delete win
|
172
|
+
@wins << split1
|
173
|
+
@wins << split2
|
174
|
+
@focusables << split1 << split2
|
175
|
+
spl = Split.new :HORIZONTAL, split1, split2, win
|
176
|
+
spl.divider_location(h/2,0)
|
177
|
+
@splits[split1] = spl
|
178
|
+
@splits[split2] = spl
|
179
|
+
@children[win] = [ split1, split2 ]
|
180
|
+
#return split1, split2
|
181
|
+
return spl
|
182
|
+
end
|
183
|
+
def split_v win
|
184
|
+
h = win.height
|
185
|
+
w = win.width
|
186
|
+
off = get_offset()
|
187
|
+
lay1 = { :height => h-2, :width => w/2-1, :top => off, :left => off }
|
188
|
+
lay2 = { :height => h-2, :width => w/2-1, :top => off, :left => w/2+1 }
|
189
|
+
split1 = win._subwin(lay1)
|
190
|
+
split2 = win._subwin(lay2)
|
191
|
+
win.mvwvline( 0, w/2, ACS_VLINE, h+2)
|
192
|
+
if @draw_boxes
|
193
|
+
split1.box(0,0)
|
194
|
+
split2.box(0,0)
|
195
|
+
end
|
196
|
+
@focusables.delete win
|
197
|
+
@wins << split1
|
198
|
+
@wins << split2
|
199
|
+
@focusables << split1 << split2
|
200
|
+
spl = Split.new :VERTICAL, split1, split2, win
|
201
|
+
spl.divider_location(0,h/2)
|
202
|
+
@splits[split1] = spl
|
203
|
+
@splits[split2] = spl
|
204
|
+
@children[win] = [ split1, split2 ]
|
205
|
+
#return split1, split2
|
206
|
+
return spl
|
207
|
+
end
|
208
|
+
def set_focus_on split
|
209
|
+
raise "Given split not focusable" if @focusables.index.nil?
|
210
|
+
# actually we can take it's split and keep going down till first. But we don;t have a tree
|
211
|
+
@current = split
|
212
|
+
end
|
213
|
+
|
214
|
+
def destroy
|
215
|
+
@wins.each {|w| w.destroy}
|
216
|
+
super
|
217
|
+
end
|
218
|
+
## attach a component to a window/split, so that all keys to that win go to the window
|
219
|
+
# create the comp without a form.
|
220
|
+
def attach win, comp
|
221
|
+
# i need to set the window to win.
|
222
|
+
comp.override_graphic(win) # i think XXX
|
223
|
+
@win_comp[win] = comp
|
224
|
+
end
|
225
|
+
def _switch_split
|
226
|
+
index = @focusables.index @current
|
227
|
+
index ||= 0
|
228
|
+
index+=1
|
229
|
+
if index >= @focusables.length
|
230
|
+
index = 0
|
231
|
+
end
|
232
|
+
@current = @focusables.at index
|
233
|
+
@current.wmove 0,0
|
234
|
+
@current.wrefresh
|
235
|
+
@current
|
236
|
+
end
|
237
|
+
def handle_key ch
|
238
|
+
case ch
|
239
|
+
when 9
|
240
|
+
_switch_split
|
241
|
+
return 0
|
242
|
+
#when 32..126
|
243
|
+
#char = ch.chr
|
244
|
+
#@str << char
|
245
|
+
#@current.printstring 0,0, @str, 0
|
246
|
+
#@current.wrefresh
|
247
|
+
#when 330, 127
|
248
|
+
#@str = @str[0..-2]
|
249
|
+
##@current.wclear # casuses a flash
|
250
|
+
#@current.printstring 0,0, @str, 0
|
251
|
+
#@current.wrefresh
|
252
|
+
#when 10,13
|
253
|
+
#@str << "\n"
|
254
|
+
when ?\M-v.getbyte(0)
|
255
|
+
# allow user to split but this does not give the user programmatic control over the splits ??
|
256
|
+
# unless we call some events
|
257
|
+
split_v @current
|
258
|
+
@current.wrefresh
|
259
|
+
set_focus_on @focusables.last
|
260
|
+
@window.wrefresh
|
261
|
+
when ?\M-h.getbyte(0)
|
262
|
+
split_h @current
|
263
|
+
@current.wrefresh
|
264
|
+
set_focus_on @focusables.last
|
265
|
+
@window.wrefresh
|
266
|
+
when ?\M-+.getbyte(0)
|
267
|
+
spl = @splits[@current]
|
268
|
+
spl.increase(@current)
|
269
|
+
when ?\M--.getbyte(0)
|
270
|
+
spl = @splits[@current]
|
271
|
+
spl.increase(@current,-1)
|
272
|
+
else
|
273
|
+
comp = @win_comp[@current]
|
274
|
+
ret = :UNHANDLED
|
275
|
+
ret = comp.handle_key(ch) unless comp.nil?
|
276
|
+
return ret
|
277
|
+
end
|
278
|
+
ret = :UNHANDLED
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
class TestSubwin
|
283
|
+
def initialize
|
284
|
+
acolor = $reversecolor
|
285
|
+
end
|
286
|
+
def run
|
287
|
+
@window = VER::Window.root_window
|
288
|
+
|
289
|
+
h = 20; w = 75; t = 3; l = 4
|
290
|
+
@layoutouter = { :height => h, :width => w, :top => t, :left => l }
|
291
|
+
|
292
|
+
@vim = VimSplit.new @window, @layoutouter
|
293
|
+
@splouter = @vim.get_win
|
294
|
+
spl = @vim.split_v @splouter
|
295
|
+
@splleft = spl.first_win
|
296
|
+
@splright = spl.second_win
|
297
|
+
spl = @vim.split_h @splleft
|
298
|
+
@splleft1 = spl.first_win
|
299
|
+
@splleft2 = spl.second_win
|
300
|
+
@vim.split_h @splright
|
301
|
+
@vim.split_v @splleft1
|
302
|
+
|
303
|
+
@window.printstring(1,10,"Ncurses Subwindow test - splitpanes emulation using subwin",0)
|
304
|
+
@splouter.printstring(0,2, " Outer ", 0)
|
305
|
+
@splleft.printstring(0,2, "-Left ", 0)
|
306
|
+
@splleft1.printstring(0,1, "Top ", 0)
|
307
|
+
@splleft2.printstring(0,1, "Bottom ", 0)
|
308
|
+
#@vim.set_focus_on @splleft1
|
309
|
+
|
310
|
+
@window.printstring(2,10,"q to quit",2)
|
311
|
+
#
|
312
|
+
@form = Form.new @window
|
313
|
+
@help = "q to quit. "
|
314
|
+
RubyCurses::Label.new @form, {'text' => @help, "row" => 1, "col" => 2, "color" => "yellow"}
|
315
|
+
@form.repaint
|
316
|
+
@window.wrefresh
|
317
|
+
Ncurses::Panel.update_panels
|
318
|
+
ctr = 0
|
319
|
+
row = 2
|
320
|
+
str = "Hello"
|
321
|
+
buffers = {}
|
322
|
+
while((ch = @window.getchar()) != KEY_F1 )
|
323
|
+
ret = @vim.handle_key ch
|
324
|
+
if ret == :UNHANDLED
|
325
|
+
curr = @vim.current
|
326
|
+
buff = buffers[curr]
|
327
|
+
if buff.nil?
|
328
|
+
buff ||= ""
|
329
|
+
buffers[curr] = buff
|
330
|
+
end
|
331
|
+
case ch
|
332
|
+
when 32..126
|
333
|
+
char = ch.chr
|
334
|
+
buff << char
|
335
|
+
curr.printstring 0,0, buff, 0
|
336
|
+
curr.wrefresh
|
337
|
+
when 330, 127
|
338
|
+
buff = buff[0..-2]
|
339
|
+
buffers[curr] = buff
|
340
|
+
#@current.wclear # casuses a flash
|
341
|
+
curr.printstring 0,0, buff, 0
|
342
|
+
curr.clrtobot
|
343
|
+
curr.wrefresh
|
344
|
+
when 10,13
|
345
|
+
buff << "\n"
|
346
|
+
curr.printstring 0,0, buff, 0
|
347
|
+
curr.wrefresh
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
@window.destroy
|
354
|
+
|
355
|
+
end
|
356
|
+
end
|
357
|
+
if $0 == __FILE__
|
358
|
+
include RubyCurses
|
359
|
+
include RubyCurses::Utils
|
360
|
+
# Initialize curses
|
361
|
+
begin
|
362
|
+
# XXX update with new color and kb
|
363
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
364
|
+
$log = Logger.new("view.log")
|
365
|
+
$log.level = Logger::DEBUG
|
366
|
+
n = TestSubwin.new
|
367
|
+
n.run
|
368
|
+
rescue => ex
|
369
|
+
ensure
|
370
|
+
VER::stop_ncurses
|
371
|
+
p ex if ex
|
372
|
+
p(ex.backtrace.join("\n")) if ex
|
373
|
+
$log.debug( ex) if ex
|
374
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
375
|
+
end
|
376
|
+
end
|