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.
- data/NOTES +68 -0
- data/README.markdown +73 -330
- data/TODO2.txt +2 -2
- data/VERSION +1 -1
- data/examples/abasiclist.rb +8 -2
- data/examples/alpmenu.rb +1 -1
- data/examples/app.rb +1 -24
- data/examples/appdirtree.rb +1 -1
- data/examples/appemail.rb +8 -14
- data/examples/appemaillb.rb +2 -2
- data/examples/appgcompose.rb +7 -5
- data/examples/common/file.rb +40 -0
- data/examples/{rmail.rb → common/rmail.rb} +0 -0
- data/examples/data/README.markdown +9 -0
- data/examples/data/brew.txt +38 -0
- data/examples/data/color.2 +37 -0
- data/examples/data/gemlist.txt +60 -0
- data/examples/data/lotr.txt +12 -0
- data/examples/data/ports.txt +136 -0
- data/examples/data/tasks.txt +27 -0
- data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +49 -14
- data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
- data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
- data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
- data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
- data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
- data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
- data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
- data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
- data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
- data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
- data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
- data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
- data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
- data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
- data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
- data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
- data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
- data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
- data/examples/dirtree.rb +17 -7
- data/examples/experimental/resultsetdemo.rb +280 -0
- data/examples/experimental/testmform.rb +35 -0
- data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
- data/examples/experimental/teststackflow.rb +111 -0
- data/examples/menu1.rb +1 -0
- data/examples/multispl.rb +4 -4
- data/examples/newmessagebox.rb +130 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +0 -3
- data/examples/qdfilechooser.rb +0 -3
- data/examples/rfe.rb +134 -18
- data/examples/rfe_renderer.rb +48 -2
- data/examples/sqlc.rb +2 -1
- data/examples/sqlm.rb +0 -2
- data/examples/table1.rb +1 -7
- data/examples/term2.rb +4 -1
- data/examples/test1.rb +0 -5
- data/examples/test2.rb +42 -31
- data/examples/testapp2.rb +8 -1
- data/examples/testchars.rb +0 -4
- data/examples/testcombo.rb +5 -9
- data/examples/testkeypress.rb +0 -3
- data/examples/testmenu.rb +0 -4
- data/examples/testmulticomp.rb +3 -5
- data/examples/testmulticontainer.rb +94 -0
- data/examples/testtable.rb +0 -5
- data/examples/testtabp.rb +16 -18
- data/examples/testtodo.rb +1 -5
- data/examples/testwsshortcuts.rb +64 -0
- data/examples/testwsshortcuts2.rb +126 -0
- data/examples/viewtodo.rb +1 -4
- data/lib/rbcurse.rb +1 -1
- data/lib/rbcurse/app.rb +92 -69
- data/lib/rbcurse/applicationheader.rb +46 -6
- data/lib/rbcurse/celleditor.rb +1 -9
- data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
- data/lib/rbcurse/common/ansiparser.rb +117 -0
- data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
- data/lib/rbcurse/common/basestack.rb +407 -0
- data/lib/rbcurse/common/bordertitle.rb +41 -0
- data/lib/rbcurse/common/chunk.rb +177 -0
- data/lib/rbcurse/common/colorparser.rb +71 -0
- data/lib/rbcurse/common/keydefs.rb +30 -0
- data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
- data/lib/rbcurse/deprecated/README.markdown +12 -0
- data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
- data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
- data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
- data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
- data/lib/rbcurse/experimental/README.markdown +14 -0
- data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
- data/lib/rbcurse/experimental/stackflow.rb +478 -0
- data/lib/rbcurse/extras/bottomline.rb +85 -16
- data/lib/rbcurse/extras/box.rb +58 -0
- data/lib/rbcurse/extras/directorylist.rb +1 -1
- data/lib/rbcurse/extras/horizlist.rb +203 -0
- data/lib/rbcurse/extras/listselectable.rb +8 -0
- data/lib/rbcurse/extras/multiform.rb +330 -0
- data/lib/rbcurse/extras/multilinelabel.rb +142 -0
- data/lib/rbcurse/extras/newmessagebox.rb +328 -0
- data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
- data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
- data/lib/rbcurse/extras/padreader.rb +189 -0
- data/lib/rbcurse/extras/rcomboedit.rb +256 -0
- data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
- data/lib/rbcurse/extras/statusline.rb +44 -6
- data/lib/rbcurse/extras/tabularwidget.rb +141 -104
- data/lib/rbcurse/extras/textpad.rb +516 -0
- data/lib/rbcurse/extras/viewer.rb +2 -0
- data/lib/rbcurse/io.rb +120 -3
- data/lib/rbcurse/listcellrenderer.rb +2 -1
- data/lib/rbcurse/listkeys.rb +1 -1
- data/lib/rbcurse/listscrollable.rb +72 -7
- data/lib/rbcurse/rbasiclistbox.rb +64 -12
- data/lib/rbcurse/rchangeevent.rb +0 -1
- data/lib/rbcurse/rcombo.rb +54 -59
- data/lib/rbcurse/rcommandwindow.rb +46 -10
- data/lib/rbcurse/rcontainer.rb +415 -0
- data/lib/rbcurse/rdialogs.rb +242 -165
- data/lib/rbcurse/rinputdataevent.rb +0 -1
- data/lib/rbcurse/rlistbox.rb +19 -9
- data/lib/rbcurse/rmessagebox.rb +1 -5
- data/lib/rbcurse/rmulticontainer.rb +64 -61
- data/lib/rbcurse/rmultitextview.rb +0 -2
- data/lib/rbcurse/rpopupmenu.rb +0 -2
- data/lib/rbcurse/rscrollform.rb +61 -12
- data/lib/rbcurse/rtabbedpane.rb +89 -73
- data/lib/rbcurse/rtabbedwindow.rb +53 -211
- data/lib/rbcurse/rtable.rb +0 -2
- data/lib/rbcurse/rtextarea.rb +14 -14
- data/lib/rbcurse/rtextview.rb +165 -50
- data/lib/rbcurse/rvimsplit.rb +15 -12
- data/lib/rbcurse/rwidget.rb +404 -150
- data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
- data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
- data/lib/ver/ncurses.rb +1 -9
- data/lib/ver/rpad.rb +375 -0
- data/lib/ver/window.rb +262 -440
- metadata +73 -31
@@ -310,6 +310,13 @@ module RubyCurses
|
|
310
310
|
# q.change_proc = Proc.new {|str| Dir.glob(str +"*") }
|
311
311
|
#
|
312
312
|
attr_accessor :change_proc
|
313
|
+
#
|
314
|
+
# Called when any control-key is pressed, one that we are not handling
|
315
|
+
#
|
316
|
+
# q.key_handler_proc = Proc.new {|ch| xxxx) }
|
317
|
+
#
|
318
|
+
attr_accessor :key_handler_proc
|
319
|
+
|
313
320
|
#
|
314
321
|
# text to be shown if user presses M-h
|
315
322
|
#
|
@@ -966,15 +973,17 @@ module RubyCurses
|
|
966
973
|
end
|
967
974
|
def ask(question, answer_type=String, &details)
|
968
975
|
$log.debug "XXXX inside ask win #{@window} "
|
969
|
-
#@window.show #unless @window.visible?
|
970
976
|
@window ||= _create_footer_window
|
977
|
+
#@window.show #unless @window.visible?
|
971
978
|
|
972
979
|
@question ||= Question.new(question, answer_type, &details)
|
973
980
|
say(@question) #unless @question.echo == true
|
974
981
|
|
975
982
|
@completion_proc = @question.completion_proc
|
976
983
|
@change_proc = @question.change_proc
|
984
|
+
@key_handler_proc = @question.key_handler_proc
|
977
985
|
@default = @question.default
|
986
|
+
$log.debug "XXX: ASK RBGETS got default: #{@default} "
|
978
987
|
@helptext = @question.helptext
|
979
988
|
@answer_type = @question.answer_type
|
980
989
|
if @question.answer_type.is_a? Array
|
@@ -1037,7 +1046,8 @@ module RubyCurses
|
|
1037
1046
|
return nil
|
1038
1047
|
ensure
|
1039
1048
|
@question = nil # Reset Question object.
|
1040
|
-
|
1049
|
+
$log.debug "XXX: HIDE B AT ENSURE OF ASK"
|
1050
|
+
hide_bottomline # assuming this method made it visible, not sure if this is called.
|
1041
1051
|
end
|
1042
1052
|
end
|
1043
1053
|
#
|
@@ -1045,14 +1055,22 @@ module RubyCurses
|
|
1045
1055
|
# Call this if you find the window persists after using some method from here
|
1046
1056
|
# usually say or ask.
|
1047
1057
|
#
|
1058
|
+
# NOTE: after callign this you must call window.show. Otherwise, next time
|
1059
|
+
# you call this, it will not hide.
|
1060
|
+
#
|
1048
1061
|
# @param [int, float] time to sleep before hiding window.
|
1049
1062
|
#
|
1050
1063
|
def hide wait=nil
|
1051
1064
|
if @window
|
1065
|
+
$log.debug "XXX: HIDE BOTTOMLINE INSIDE"
|
1052
1066
|
sleep(wait) if wait
|
1053
|
-
@window.
|
1054
|
-
|
1067
|
+
#if @window.visible?
|
1068
|
+
#@window.hide # THIS HAS SUDDENLY STOPPED WORKING
|
1069
|
+
@window.destroy
|
1070
|
+
@window = nil
|
1071
|
+
#@window.wrefresh
|
1055
1072
|
#Ncurses::Panel.update_panels
|
1073
|
+
#end
|
1056
1074
|
end
|
1057
1075
|
end
|
1058
1076
|
alias :hide_bottomline :hide
|
@@ -1081,7 +1099,7 @@ module RubyCurses
|
|
1081
1099
|
#
|
1082
1100
|
def say statement, config={}
|
1083
1101
|
@window ||= _create_footer_window
|
1084
|
-
#@window.show unless @window.visible?
|
1102
|
+
#@window.show #unless @window.visible?
|
1085
1103
|
$log.debug "XXX: inside say win #{@window} !"
|
1086
1104
|
case statement
|
1087
1105
|
when Question
|
@@ -1109,11 +1127,25 @@ module RubyCurses
|
|
1109
1127
|
#
|
1110
1128
|
def say_with_pause statement, config={}
|
1111
1129
|
@window ||= _create_footer_window
|
1130
|
+
#@window.show #unless @window.visible? # 2011-10-14 23:52:52
|
1112
1131
|
say statement, config
|
1113
1132
|
@window.wrefresh
|
1114
1133
|
Ncurses::Panel.update_panels
|
1115
1134
|
ch=@window.getchar()
|
1116
|
-
|
1135
|
+
hide_bottomline
|
1136
|
+
end
|
1137
|
+
# since say does not leave the screen, it is not exactly recommended
|
1138
|
+
# as it will hide what's below. It's better to call pause, or this, which
|
1139
|
+
# will quickly go off. If the message is not important enough to ask for a pause,
|
1140
|
+
# the will flicker on screen, but not for too long.
|
1141
|
+
def say_with_wait statement, config={}
|
1142
|
+
@window ||= _create_footer_window
|
1143
|
+
#@window.show #unless @window.visible? # 2011-10-14 23:52:59
|
1144
|
+
say statement, config
|
1145
|
+
@window.wrefresh
|
1146
|
+
Ncurses::Panel.update_panels
|
1147
|
+
sleep 0.5
|
1148
|
+
hide_bottomline
|
1117
1149
|
end
|
1118
1150
|
# A helper method for sending the output stream and error and repeat
|
1119
1151
|
# of the question.
|
@@ -1166,6 +1198,7 @@ module RubyCurses
|
|
1166
1198
|
ins_mode = false
|
1167
1199
|
oldstr = nil # for tab completion, origal word entered by user
|
1168
1200
|
default = @default || ""
|
1201
|
+
$log.debug "XXX: RBGETS got default: #{@default} "
|
1169
1202
|
if @default && @history
|
1170
1203
|
if !@history.include?(default)
|
1171
1204
|
@history_list.push default
|
@@ -1248,12 +1281,6 @@ module RubyCurses
|
|
1248
1281
|
when ?\C-k.getbyte(0) # delete forward
|
1249
1282
|
@delete_buffer = str.slice!(curpos..-1) #rescue next
|
1250
1283
|
clear_line len+maxlen+1, @prompt_length
|
1251
|
-
#when ?\C-u.getbyte(0) # clear entire line
|
1252
|
-
#@delete_buffer = str
|
1253
|
-
#str = ""
|
1254
|
-
#curpos = 0
|
1255
|
-
#clear_line len+maxlen+1, @prompt_length
|
1256
|
-
#len = @prompt_length
|
1257
1284
|
when ?\C-u.getbyte(0) # delete to the left of cursor till start of line
|
1258
1285
|
@delete_buffer = str.slice!(0..curpos-1) #rescue next
|
1259
1286
|
curpos = 0
|
@@ -1324,7 +1351,15 @@ module RubyCurses
|
|
1324
1351
|
end
|
1325
1352
|
end
|
1326
1353
|
when ?\C-a.getbyte(0) .. ?\C-z.getbyte(0)
|
1327
|
-
|
1354
|
+
# here' swhere i wish i could pass stuff back without closing
|
1355
|
+
# I'd like the user to be able to scroll list or do something based on
|
1356
|
+
# control or other keys
|
1357
|
+
if @key_handler_proc # added 2011-11-3 7:38 PM
|
1358
|
+
@key_handler_proc.call(ch)
|
1359
|
+
next
|
1360
|
+
else
|
1361
|
+
Ncurses.beep
|
1362
|
+
end
|
1328
1363
|
when KEY_UP
|
1329
1364
|
if @history && !@history.empty?
|
1330
1365
|
olen = str.length
|
@@ -1339,6 +1374,15 @@ module RubyCurses
|
|
1339
1374
|
curpos = str.length
|
1340
1375
|
len += str.length - olen
|
1341
1376
|
clear_line len+maxlen+1, @prompt_length
|
1377
|
+
else # try to pick up default, seems we don't get it 2011-10-14
|
1378
|
+
if @default
|
1379
|
+
olen = str.length
|
1380
|
+
str = @default
|
1381
|
+
str = str.dup
|
1382
|
+
curpos = str.length
|
1383
|
+
len += str.length - olen
|
1384
|
+
clear_line len+maxlen+1, @prompt_length
|
1385
|
+
end
|
1342
1386
|
end
|
1343
1387
|
when KEY_DOWN
|
1344
1388
|
if @history && !@history.empty?
|
@@ -1441,6 +1485,7 @@ module RubyCurses
|
|
1441
1485
|
|
1442
1486
|
#if @question.character.nil?
|
1443
1487
|
# if @question.echo == true #and @question.limit.nil?
|
1488
|
+
$log.debug "XXX: before RBGETS got default: #{@default} "
|
1444
1489
|
ret, str = rbgetstr
|
1445
1490
|
if ret == 0
|
1446
1491
|
return @question.change_case(@question.remove_whitespace(str))
|
@@ -1524,6 +1569,7 @@ module RubyCurses
|
|
1524
1569
|
#
|
1525
1570
|
def choose list1, config={}
|
1526
1571
|
dirlist = true
|
1572
|
+
start = 0
|
1527
1573
|
case list1
|
1528
1574
|
when NilClass
|
1529
1575
|
#list1 = Dir.glob("*")
|
@@ -1547,7 +1593,9 @@ module RubyCurses
|
|
1547
1593
|
rc.display_menu list1
|
1548
1594
|
# earlier wmove bombed, now move is (window.rb 121)
|
1549
1595
|
str = ask(prompt) { |q| q.change_proc = Proc.new { |str| w.wmove(1,1) ; w.wclrtobot;
|
1550
|
-
|
1596
|
+
|
1597
|
+
l = list1.select{|e| e.index(str)==0} ; # select those starting with str
|
1598
|
+
|
1551
1599
|
if (l.size == 0 || str[-1]=='/') && dirlist
|
1552
1600
|
# used to help complete directories so we can drill up and down
|
1553
1601
|
#l = Dir.glob(str+"*")
|
@@ -1555,14 +1603,35 @@ module RubyCurses
|
|
1555
1603
|
end
|
1556
1604
|
rc.display_menu l;
|
1557
1605
|
l
|
1558
|
-
}
|
1606
|
+
}
|
1607
|
+
q.key_handler_proc = Proc.new { |ch|
|
1608
|
+
# this is not very good since it does not respect above list which is filtered
|
1609
|
+
# # need to clear the screen before printing - FIXME
|
1610
|
+
case ch
|
1611
|
+
when ?\C-n.getbyte(0)
|
1612
|
+
start += 2 if start < list1.length - 2
|
1613
|
+
|
1614
|
+
w.wmove(1,1) ; w.wclrtobot;
|
1615
|
+
rc.display_menu list1, :startindex => start
|
1616
|
+
when ?\C-p.getbyte(0)
|
1617
|
+
start -= 2 if start > 2
|
1618
|
+
w.wmove(1,1) ; w.wclrtobot;
|
1619
|
+
rc.display_menu list1, :startindex => start
|
1620
|
+
else
|
1621
|
+
alert "unhalderlind by jey "
|
1622
|
+
end
|
1623
|
+
|
1624
|
+
}
|
1625
|
+
}
|
1559
1626
|
# need some validation here that its in the list TODO
|
1560
1627
|
ensure
|
1561
1628
|
rc.destroy
|
1562
1629
|
rc = nil
|
1630
|
+
$log.debug "XXX: HIDE B IN ENSURE"
|
1563
1631
|
hide_bottomline # since we called ask() we need to close bottomline
|
1564
1632
|
end
|
1565
|
-
|
1633
|
+
$log.debug "XXX: HIDE B AT END OF ASK"
|
1634
|
+
#hide_bottomline # since we called ask() we need to close bottomline
|
1566
1635
|
return str
|
1567
1636
|
end
|
1568
1637
|
def display_text_interactive text, config={}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# ------------------------------------------------------------ #
|
2
|
+
# File: box.rb
|
3
|
+
# Description: draws a box around some group of items
|
4
|
+
# Author: rkumar http://github.com/rkumar/rbcurse/
|
5
|
+
# Date: 06.11.11 - 18:22
|
6
|
+
# Last update: 06.11.11 - 19:53
|
7
|
+
# ------------------------------------------------------------ #
|
8
|
+
#
|
9
|
+
require 'rbcurse'
|
10
|
+
require 'rbcurse/common/bordertitle'
|
11
|
+
include RubyCurses
|
12
|
+
#include RubyCurses::BorderTitle
|
13
|
+
|
14
|
+
# @example
|
15
|
+
#
|
16
|
+
# At a later stage, we will integrate this with lists and tables, so it will happen automatically.
|
17
|
+
#
|
18
|
+
# @since 1.4.1 UNTESTED
|
19
|
+
module RubyCurses
|
20
|
+
class Box < Widget
|
21
|
+
|
22
|
+
include BorderTitle
|
23
|
+
|
24
|
+
# margin for placing widgets inside
|
25
|
+
# This is not used inside here, but is used by stacks.
|
26
|
+
# @see widgetshortcuts.rb
|
27
|
+
dsl_accessor :margin_left, :margin_top
|
28
|
+
|
29
|
+
def initialize form, config={}, &block
|
30
|
+
|
31
|
+
bordertitle_init
|
32
|
+
super
|
33
|
+
@window = form.window if @form
|
34
|
+
@editable = false
|
35
|
+
@focusable = false
|
36
|
+
#@height += 1 # for that silly -1 that happens
|
37
|
+
@repaint_required = true
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# repaint the scrollbar
|
42
|
+
def repaint
|
43
|
+
return unless @repaint_required
|
44
|
+
bc = $datacolor
|
45
|
+
bordercolor = @border_color || bc
|
46
|
+
borderatt = @border_attrib || Ncurses::A_NORMAL
|
47
|
+
@window.print_border row, col, height, width, bordercolor, borderatt
|
48
|
+
#print_borders
|
49
|
+
print_title
|
50
|
+
@repaint_required = false
|
51
|
+
end
|
52
|
+
##
|
53
|
+
##
|
54
|
+
# ADD HERE
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if __FILE__ == $PROGRAM_NAME
|
58
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'rbcurse'
|
2
|
+
|
3
|
+
# This is a horizontal scroller, to scroll a list of options much like
|
4
|
+
# vim often does on the statusline. I'd like to use it for scrolling
|
5
|
+
# menus or buttons like on TabbedPanes to avoid another Form.
|
6
|
+
|
7
|
+
# You may bind to the ENTER_ROW event to chagne some data elsewhere,
|
8
|
+
# or the PRESS event. In this case, PRESS will refer to pressing the
|
9
|
+
# space bar or ENTER. There is <em>no</em> LIST_SELECTION event for that.
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
module RubyCurses
|
14
|
+
|
15
|
+
# Horizontal list scrolling and selection.
|
16
|
+
#
|
17
|
+
# == Example
|
18
|
+
# require 'rbcurse/extras/horizlist'
|
19
|
+
# require 'fileutils'
|
20
|
+
# l = HorizList.new @form, :row => 5, :col => 5, :width => 80
|
21
|
+
# list = Dir.glob("*")
|
22
|
+
# l.list(list)
|
23
|
+
|
24
|
+
class HorizList < Widget
|
25
|
+
|
26
|
+
def initialize form, config={}, &block
|
27
|
+
super
|
28
|
+
@_events.push(*[:ENTER_ROW, :LEAVE_ROW, :PRESS])
|
29
|
+
@focusable = true
|
30
|
+
init_vars
|
31
|
+
@list = []
|
32
|
+
@toprow = 0
|
33
|
+
|
34
|
+
# last printed index
|
35
|
+
@last_index = 0
|
36
|
+
|
37
|
+
# item on which cursor is
|
38
|
+
@current_index = 0
|
39
|
+
end
|
40
|
+
def init_vars
|
41
|
+
end
|
42
|
+
# alias :text :getvalue # NEXT VERSION
|
43
|
+
|
44
|
+
def map_keys
|
45
|
+
@keys_mapped = true
|
46
|
+
bind_keys([KEY_RIGHT, ?l, ?.], :next_item)
|
47
|
+
bind_keys([KEY_LEFT, ?h,?,], :previous_item)
|
48
|
+
bind_keys([10,13,32]){ fire_action_event }
|
49
|
+
bind_keys([?\M-l,?>, KEY_DOWN], :scroll_right)
|
50
|
+
bind_keys([?\M-h,?<, KEY_UP], :scroll_left)
|
51
|
+
end
|
52
|
+
def list(strings)
|
53
|
+
@list = strings
|
54
|
+
end
|
55
|
+
def add item
|
56
|
+
@list << item
|
57
|
+
end
|
58
|
+
def repaint
|
59
|
+
return unless @repaint_required
|
60
|
+
@window ||= @form.window
|
61
|
+
$log.debug "XXX:HORIZ REPAINT Ci #{@current_index}, TR #{@toprow} "
|
62
|
+
$status_message.value = " #{@current_index}, TR #{@toprow} "
|
63
|
+
@window.printstring @row, @col, " "* @width, @color_pair || $reversecolor
|
64
|
+
c = @col + 1
|
65
|
+
t = @toprow
|
66
|
+
@list.each_with_index { |e, i|
|
67
|
+
next if i < t # sucks for large lists
|
68
|
+
break if c + e.length >= @width + @col
|
69
|
+
att = @attrib || FFI::NCurses::A_NORMAL
|
70
|
+
if i == @current_index
|
71
|
+
att = FFI::NCurses::A_REVERSE if i == @current_index
|
72
|
+
acolor = @focussed_color_pair || get_color($datacolor,'green', 'white')
|
73
|
+
else
|
74
|
+
acolor = @color_pair
|
75
|
+
end
|
76
|
+
@window.printstring @row, c, e, acolor || $reversecolor, att
|
77
|
+
c += e.length + 2
|
78
|
+
@last_index = i
|
79
|
+
break if c >= @width + @col
|
80
|
+
}
|
81
|
+
@repaint_required = false
|
82
|
+
end
|
83
|
+
def handle_key ch
|
84
|
+
map_keys unless @keys_mapped
|
85
|
+
ret = process_key ch, self
|
86
|
+
@multiplier = 0
|
87
|
+
return :UNHANDLED if ret == :UNHANDLED
|
88
|
+
end
|
89
|
+
def previous_item num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
|
90
|
+
|
91
|
+
return :NO_PREVIOUS_ROW if @current_index == 0
|
92
|
+
@old_toprow = @toprow
|
93
|
+
@oldrow = @current_index
|
94
|
+
@current_index -= num
|
95
|
+
@current_index = 0 if @current_index < 0
|
96
|
+
bounds_check
|
97
|
+
$multiplier = 0
|
98
|
+
if @current_index < @toprow
|
99
|
+
@toprow = @current_index
|
100
|
+
end
|
101
|
+
@toprow = 0 if @toprow < 0
|
102
|
+
@repaint_required = true
|
103
|
+
end
|
104
|
+
def next_item num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
|
105
|
+
rc = row_count
|
106
|
+
return :NO_NEXT_ROW if @current_index == rc-1 # changed 2011-10-5 so process can do something
|
107
|
+
@old_toprow = @toprow
|
108
|
+
@oldrow = @current_index
|
109
|
+
@current_index += num
|
110
|
+
@current_index = rc - 1 if @current_index >= rc
|
111
|
+
@toprow = @current_index if @current_index > @last_index
|
112
|
+
bounds_check
|
113
|
+
$multiplier = 0
|
114
|
+
@repaint_required = true
|
115
|
+
end
|
116
|
+
def scroll_right
|
117
|
+
rc = row_count
|
118
|
+
return :NO_NEXT_ROW if @current_index == rc-1 # changed 2011-10-5 so process can do something
|
119
|
+
@old_toprow = @toprow
|
120
|
+
@oldrow = @current_index
|
121
|
+
|
122
|
+
@current_index = @last_index + 1
|
123
|
+
|
124
|
+
@current_index = rc - 1 if @current_index >= rc
|
125
|
+
@toprow = @current_index if @current_index > @last_index
|
126
|
+
bounds_check
|
127
|
+
$multiplier = 0
|
128
|
+
@repaint_required = true
|
129
|
+
end
|
130
|
+
def scroll_left
|
131
|
+
return :NO_PREVIOUS_ROW if @current_index == 0
|
132
|
+
@old_toprow = @toprow
|
133
|
+
@oldrow = @current_index
|
134
|
+
@current_index = @toprow - 4
|
135
|
+
@current_index = 0 if @current_index < 0
|
136
|
+
bounds_check
|
137
|
+
$multiplier = 0
|
138
|
+
if @current_index < @toprow
|
139
|
+
@toprow = @current_index
|
140
|
+
end
|
141
|
+
@toprow = 0 if @toprow < 0
|
142
|
+
@repaint_required = true
|
143
|
+
end
|
144
|
+
def row_count; @list.size; end
|
145
|
+
def bounds_check
|
146
|
+
@row_changed = false
|
147
|
+
if @oldrow != @current_index
|
148
|
+
on_leave_row @oldrow if respond_to? :on_leave_row # to be defined by widget that has included this
|
149
|
+
on_enter_row @current_index if respond_to? :on_enter_row # to be defined by widget that has included this
|
150
|
+
set_form_row
|
151
|
+
@row_changed = true
|
152
|
+
end
|
153
|
+
if @old_toprow != @toprow # only if scrolling has happened should we repaint
|
154
|
+
@repaint_required = true
|
155
|
+
@widget_scrolled = true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
def on_enter
|
159
|
+
if @list.nil? || @list.size == 0
|
160
|
+
Ncurses.beep
|
161
|
+
return :UNHANDLED
|
162
|
+
end
|
163
|
+
super
|
164
|
+
on_enter_row @current_index
|
165
|
+
set_form_row
|
166
|
+
true
|
167
|
+
end
|
168
|
+
def on_enter_row arow
|
169
|
+
fire_handler :ENTER_ROW, self
|
170
|
+
@repaint_required = true
|
171
|
+
end
|
172
|
+
def on_leave_row arow
|
173
|
+
fire_handler :LEAVE_ROW, self
|
174
|
+
end
|
175
|
+
def fire_action_event
|
176
|
+
require 'rbcurse/ractionevent'
|
177
|
+
fire_handler :PRESS, ActionEvent.new(self, :PRESS, text)
|
178
|
+
end
|
179
|
+
def current_value
|
180
|
+
@list[@current_index]
|
181
|
+
end
|
182
|
+
alias :text :current_value
|
183
|
+
##
|
184
|
+
end # class
|
185
|
+
end # module
|
186
|
+
if __FILE__ == $PROGRAM_NAME
|
187
|
+
require 'rbcurse/app'
|
188
|
+
|
189
|
+
App.new do
|
190
|
+
require 'rbcurse/extras/horizlist'
|
191
|
+
require 'fileutils'
|
192
|
+
l = HorizList.new @form, :row => 5, :col => 5, :width => 80
|
193
|
+
list = Dir.glob("*")
|
194
|
+
l.list(list)
|
195
|
+
l.bind(:PRESS){ |eve| alert "You pressed #{eve.text} " }
|
196
|
+
sl = status_line
|
197
|
+
sl.command do
|
198
|
+
" Status: #{$status_message} "
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
end
|