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/examples/rfe_renderer.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
module RubyCurses
|
2
|
-
|
3
|
-
##
|
4
|
-
# This is a basic list cell renderer that will render the to_s value of anything.
|
5
|
-
# Using alignment one can use for numbers too.
|
6
|
-
# However, for booleans it will print true and false. If editing, you may want checkboxes
|
7
|
-
class RfeRenderer < ListCellRenderer
|
8
|
-
def initialize text="", config={}, &block
|
9
|
-
super
|
10
|
-
@orig_bgcolor = @bgcolor
|
11
|
-
@orig_color = @color
|
12
|
-
@orig_attr = @attr
|
13
|
-
# we need to refer to file types, executable, dir, link, otherwise we'll go crazy
|
14
|
-
@color_hash = {
|
15
|
-
'.rb' => [get_color($datacolor, 'red', 'black'), 0],
|
16
|
-
'.txt' => [get_color($datacolor, 'white', 'black'), 0],
|
17
|
-
'.gemspec' => [get_color($datacolor, 'yellow', 'black'), 0],
|
18
|
-
'.gem' => [get_color($datacolor, 'yellow', 'black'), 0],
|
19
|
-
'.c' => [get_color($datacolor, 'green', 'black'), 0],
|
20
|
-
'.py' => [get_color($datacolor, 'green', 'black'), 0],
|
21
|
-
'.tgz' => [get_color($datacolor, 'red', 'black'), get_attrib('bold')],
|
22
|
-
'.gz' => [get_color($datacolor, 'red', 'black'), 0],
|
23
|
-
'.zip' => [get_color($datacolor, 'red', 'black'), 0],
|
24
|
-
'.jar' => [get_color($datacolor, 'red', 'black'), 0],
|
25
|
-
'.html' => [get_color($datacolor, 'green', 'black'), get_attrib('reverse')],
|
26
|
-
"" => [get_color($datacolor, 'yellow', 'black'), get_attrib('bold')],
|
27
|
-
'.jpg' => [get_color($datacolor, 'magenta', 'black'), 0],
|
28
|
-
'.png' => [get_color($datacolor, 'magenta', 'black'), 0],
|
29
|
-
'.sh' => [get_color($datacolor, 'red', 'black'), 0],
|
30
|
-
'.mp3' => [get_color($datacolor, 'cyan', 'blue'), 0],
|
31
|
-
'.bak' => [get_color($datacolor, 'magenta', 'black'), 0],
|
32
|
-
'.tmp' => [get_color($datacolor, 'black', 'blue'), 0],
|
33
|
-
'.pl' => [get_color($datacolor, 'green', 'black'), 0],
|
34
|
-
'.java' => [get_color($datacolor, 'cyan', 'blue'), 0],
|
35
|
-
'.class' => [get_color($datacolor, 'magenta', 'black'), 0],
|
36
|
-
'.pyc' => [get_color($datacolor, 'magenta', 'black'), 0],
|
37
|
-
'.o' => [get_color($datacolor, 'magenta', 'black'), 0],
|
38
|
-
'.a' => [get_color($datacolor, 'magenta', 'black'), 0],
|
39
|
-
'.lib' => [get_color($datacolor, 'magenta', 'black'), 0]
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
# override parent method to set color_pair and attr for different kind of files
|
44
|
-
def select_colors focussed, selected
|
45
|
-
ext = File.extname(@path)
|
46
|
-
c = @color_hash[ext]
|
47
|
-
c = [$datacolor, FFI::NCurses::A_NORMAL] unless c
|
48
|
-
if File.directory? @path
|
49
|
-
c = [get_color($datacolor, 'blue', 'black'), FFI::NCurses::A_BOLD]
|
50
|
-
end
|
51
|
-
@color_pair, @attr = *c
|
52
|
-
if selected
|
53
|
-
#@attr = FFI::NCurses::A_UNDERLINE | FFI::NCurses::A_BOLD # UL not avaible on screen
|
54
|
-
@attr = FFI::NCurses::A_REVERSE | FFI::NCurses::A_BOLD
|
55
|
-
@color_pair = $datacolor
|
56
|
-
end
|
57
|
-
if focussed
|
58
|
-
@attr = FFI::NCurses::A_REVERSE # | FFI::NCurses::A_BOLD
|
59
|
-
end
|
60
|
-
end
|
61
|
-
#
|
62
|
-
def repaint graphic, r=@row,c=@col, row_index=-1, value=@text, focussed=false, selected=false
|
63
|
-
|
64
|
-
@bgcolor = @orig_bgcolor
|
65
|
-
@color = @orig_color
|
66
|
-
@row_attr = @orig_attr
|
67
|
-
# XXX ouch, when we delete from list, must delete from here too.
|
68
|
-
value = @parent.entries[row_index]
|
69
|
-
if value[0,1]=="/"
|
70
|
-
path = value.dup
|
71
|
-
else
|
72
|
-
path = @parent.cur_dir()+"/"+value
|
73
|
-
end
|
74
|
-
@path = path # i need it in select_color
|
75
|
-
begin
|
76
|
-
stat = File.stat(path)
|
77
|
-
if File.directory? path
|
78
|
-
@row_attr = Ncurses::A_BOLD
|
79
|
-
#@color = 'yellow'
|
80
|
-
end
|
81
|
-
value = format_string(value, path, stat)
|
82
|
-
super
|
83
|
-
|
84
|
-
rescue => err
|
85
|
-
$log.debug " rfe_renderer: #{err}"
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
GIGA_SIZE = 1073741824.0
|
90
|
-
MEGA_SIZE = 1048576.0
|
91
|
-
KILO_SIZE = 1024.0
|
92
|
-
|
93
|
-
# Return the file size with a readable style.
|
94
|
-
def readable_file_size(size, precision)
|
95
|
-
case
|
96
|
-
#when size == 1 then "1 B"
|
97
|
-
when size < KILO_SIZE then "%d B" % size
|
98
|
-
when size < MEGA_SIZE then "%.#{precision}f K" % (size / KILO_SIZE)
|
99
|
-
when size < GIGA_SIZE then "%.#{precision}f M" % (size / MEGA_SIZE)
|
100
|
-
else "%.#{precision}f G" % (size / GIGA_SIZE)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
def date_format t
|
104
|
-
t.strftime "%Y/%m/%d"
|
105
|
-
end
|
106
|
-
def format_string fn, path,stat
|
107
|
-
max_len = 30
|
108
|
-
f = fn.dup
|
109
|
-
if File.directory? path
|
110
|
-
#"%-*s\t(dir)" % [max_len,f]
|
111
|
-
#f = "/"+f # disallows search on keypress
|
112
|
-
f = "/"+f
|
113
|
-
end
|
114
|
-
if f.size > max_len
|
115
|
-
f = f[0..max_len-1]
|
116
|
-
end
|
117
|
-
"%-*s %10s %s" % [max_len,f, readable_file_size(stat.size,1), date_format(stat.mtime)]
|
118
|
-
end
|
119
|
-
# ADD HERE
|
120
|
-
end
|
121
|
-
end
|
data/examples/sqlc.rb
DELETED
@@ -1,454 +0,0 @@
|
|
1
|
-
## rkumar, 2009
|
2
|
-
#
|
3
|
-
#DEPRECATED. See sqlm.rb or sqlt.rb in which i use a TabularWidget instead of Table.
|
4
|
-
#AVOID USING TabbedPane till its rewritten 1.3.2 or so.
|
5
|
-
|
6
|
-
#
|
7
|
-
############ WARNING ##############################################################
|
8
|
-
# TabbedPanes seem to have stopped displaying at some points
|
9
|
-
# after moving to FFI-Ncurses. And i've not been able to locate the point.
|
10
|
-
# This is one subtle difference between ncurses and ffi-ncurses.
|
11
|
-
# So i will scrap this and do a fresh clean rewrite of TabbedPane class.
|
12
|
-
# OKAY I've got them fixed.
|
13
|
-
#
|
14
|
-
###################################################################################
|
15
|
-
# Sample demo of various widgets and their interaction.
|
16
|
-
# This is a simple sql client which allows table / column selection, construction
|
17
|
-
# of SQL queries, and multiple resultsets.
|
18
|
-
# Use C-q to quit, Alt-Tab to move out of Table to next field.
|
19
|
-
# Please see bind_key statements in this app for some key bindings in table.
|
20
|
-
# There are also key bindings in tabbedpanes and textarea's that will help alot.
|
21
|
-
# This demo uses a tabbedpane so we can have the results of many sql statements and not
|
22
|
-
# need to keep reissuing. Its better to use a multitextview or multicontainer
|
23
|
-
# than a tabbedpane for such use.
|
24
|
-
#
|
25
|
-
require 'logger'
|
26
|
-
require 'sqlite3'
|
27
|
-
require 'rbcurse'
|
28
|
-
require 'rbcurse/rcombo'
|
29
|
-
require 'rbcurse/rtextarea'
|
30
|
-
require 'rbcurse/rtable'
|
31
|
-
#require 'rbcurse/table/tablecellrenderer'
|
32
|
-
#require 'rbcurse/comboboxcellrenderer'
|
33
|
-
#require 'rbcurse/keylabelprinter'
|
34
|
-
require 'rbcurse/applicationheader'
|
35
|
-
require 'rbcurse/action' # not used here
|
36
|
-
require 'rbcurse/rtabbedpane'
|
37
|
-
|
38
|
-
# pls get testd.db from
|
39
|
-
# http://www.benegal.org/files/screen/testd.db
|
40
|
-
# or put some other sqlite3 db name there.
|
41
|
-
# or create using sqlite3 testd.db < data.txt
|
42
|
-
|
43
|
-
## must give me @content, @columns, @datatypes (opt)
|
44
|
-
class Datasource
|
45
|
-
# attr_reader :field_length # specified by user, length of row in display table
|
46
|
-
attr_accessor :columns # names of columns in array
|
47
|
-
attr_accessor :datatypes # array of datatyps of columns required to align: int, real, float, smallint
|
48
|
-
attr_accessor :content # 2 dim data
|
49
|
-
attr_accessor :user_columns # columnnames provided by user, overrides what is generated for display
|
50
|
-
# attr_reader :sqlstring # specified by user
|
51
|
-
|
52
|
-
# constructor
|
53
|
-
def initialize(config={}, &block)
|
54
|
-
@content = []
|
55
|
-
@columns = nil # actual db columnnames -- needed to figure out datatypes
|
56
|
-
@user_columns = nil # user specified db columnnames, overrides what may be provided
|
57
|
-
@datatypes = nil
|
58
|
-
# @rows = nil
|
59
|
-
# @sqlstring = nil
|
60
|
-
# @command = nil
|
61
|
-
|
62
|
-
instance_eval(&block) if block_given?
|
63
|
-
end
|
64
|
-
def connect dbname
|
65
|
-
raise " #{dbname} does not exist. Please fetch from http://www.benegal.org/files/screen/testd.db" if !File.exists?(dbname)
|
66
|
-
@db = SQLite3::Database.new(dbname)
|
67
|
-
end
|
68
|
-
# get columns and datatypes, prefetch
|
69
|
-
def get_data command
|
70
|
-
@columns, *rows = @db.execute2(command)
|
71
|
-
$log.debug "XXX COLUMNS #{command} : #{@columns.count}: #{@columns} "
|
72
|
-
@content = rows
|
73
|
-
return nil if @content.nil? or @content[0].nil?
|
74
|
-
@datatypes = @content[0].types #if @datatypes.nil?
|
75
|
-
@command = command
|
76
|
-
return @content
|
77
|
-
end
|
78
|
-
def get_metadata table
|
79
|
-
get_data "select * from #{table} limit 1"
|
80
|
-
return @columns
|
81
|
-
end
|
82
|
-
##
|
83
|
-
# returns columns_widths, and updates that variable
|
84
|
-
def estimate_column_widths tablewidth, columns
|
85
|
-
colwidths = {}
|
86
|
-
min_column_width = (tablewidth/columns.length) -1
|
87
|
-
$log.debug("min: #{min_column_width}, #{tablewidth}")
|
88
|
-
@content.each_with_index do |row, cix|
|
89
|
-
break if cix >= 20
|
90
|
-
row.each_index do |ix|
|
91
|
-
col = row[ix]
|
92
|
-
colwidths[ix] ||= 0
|
93
|
-
colwidths[ix] = [colwidths[ix], col.length].max
|
94
|
-
end
|
95
|
-
end
|
96
|
-
total = 0
|
97
|
-
colwidths.each_pair do |k,v|
|
98
|
-
name = columns[k.to_i]
|
99
|
-
colwidths[name] = v
|
100
|
-
total += v
|
101
|
-
end
|
102
|
-
colwidths["__TOTAL__"] = total
|
103
|
-
column_widths = colwidths
|
104
|
-
@max_data_widths = column_widths.dup
|
105
|
-
|
106
|
-
columns.each_with_index do | col, i|
|
107
|
-
if @datatypes[i].match(/(real|int)/) != nil
|
108
|
-
wid = column_widths[i]
|
109
|
-
# cw = [column_widths[i], [8,min_column_width].min].max
|
110
|
-
$log.debug("XXX #{wid}. #{columns[i].length}")
|
111
|
-
cw = [wid, columns[i].length].max
|
112
|
-
$log.debug("int #{col} #{column_widths[i]}, #{cw}")
|
113
|
-
elsif @datatypes[i].match(/(date)/) != nil
|
114
|
-
cw = [column_widths[i], [12,min_column_width].min].max
|
115
|
-
#cw = [12,min_column_width].min
|
116
|
-
$log.debug("date #{col} #{column_widths[i]}, #{cw}")
|
117
|
-
else
|
118
|
-
cw = [column_widths[i], min_column_width].max
|
119
|
-
if column_widths[i] <= col.length and col.length <= min_column_width
|
120
|
-
cw = col.length
|
121
|
-
end
|
122
|
-
$log.debug("else #{col} #{column_widths[i]}, #{col.length} #{cw}")
|
123
|
-
end
|
124
|
-
column_widths[i] = cw
|
125
|
-
total += cw
|
126
|
-
end
|
127
|
-
column_widths["__TOTAL__"] = total
|
128
|
-
$log.debug("Estimated col widths: #{column_widths.inspect}")
|
129
|
-
@column_widths = column_widths
|
130
|
-
return column_widths
|
131
|
-
end
|
132
|
-
|
133
|
-
# added to enable query form to allow movement into table only if
|
134
|
-
# there is data 2008-10-08 17:46
|
135
|
-
# returns number of rows fetched
|
136
|
-
def data_length
|
137
|
-
return @content.length
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
def get_key_labels
|
142
|
-
key_labels = [
|
143
|
-
['C-q', 'Exit'], nil,
|
144
|
-
['M-s', 'Save'], ['M-m', 'Move']
|
145
|
-
]
|
146
|
-
return key_labels
|
147
|
-
end
|
148
|
-
def get_key_labels_table
|
149
|
-
key_labels = [
|
150
|
-
['M-n','NewRow'], ['M-d','DelRow'],
|
151
|
-
['C-x','Select'], nil,
|
152
|
-
['M-0', 'Top'], ['M-9', 'End'],
|
153
|
-
['C-p', 'PgUp'], ['C-n', 'PgDn'],
|
154
|
-
['M-Tab','Nxt Fld'], ['Tab','Nxt Col'],
|
155
|
-
['+','Widen'], ['-','Narrow']
|
156
|
-
]
|
157
|
-
return key_labels
|
158
|
-
end
|
159
|
-
class Sqlc
|
160
|
-
def initialize
|
161
|
-
@window = VER::Window.root_window
|
162
|
-
$catch_alt_digits = false # we want to use Alt-1, 2 for tabs.
|
163
|
-
@form = Form.new @window
|
164
|
-
@tab_ctr = 0
|
165
|
-
|
166
|
-
@db = Datasource.new
|
167
|
-
@db.connect "testd.db"
|
168
|
-
end
|
169
|
-
def run
|
170
|
-
title = "rbcurse"
|
171
|
-
@header = ApplicationHeader.new @form, title, {:text2=>"Demo", :text_center=>"SQL Client using deprecated TabbedPane and Table (see sqlm.rb instead) "}
|
172
|
-
status_row = RubyCurses::Label.new @form, {'text' => "", :row => Ncurses.LINES-4, :col => 0, :display_length=>70}
|
173
|
-
@status_row = status_row
|
174
|
-
# setting ENTER across all objects on a form
|
175
|
-
@form.bind(:ENTER) {|f| status_row.text = f.help_text unless f.help_text.nil? }
|
176
|
-
r = 1; c = 1;
|
177
|
-
@data = [ ["No data"] ]
|
178
|
-
data = @data
|
179
|
-
colnames = %w[ Result ]
|
180
|
-
|
181
|
-
ta_ht = 5
|
182
|
-
t_width = 78
|
183
|
-
sqlarea = TextArea.new @form do
|
184
|
-
name "sqlarea"
|
185
|
-
row r
|
186
|
-
col c
|
187
|
-
width t_width
|
188
|
-
height ta_ht
|
189
|
-
title "Sql Query"
|
190
|
-
title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
191
|
-
help_text "Enter query and press Run or Meta-r"
|
192
|
-
end
|
193
|
-
sqlarea << "select * from contacts"
|
194
|
-
buttrow = r+ta_ht+1 #Ncurses.LINES-4
|
195
|
-
b_run = Button.new @form do
|
196
|
-
text "&Run"
|
197
|
-
row buttrow
|
198
|
-
col c
|
199
|
-
help_text "Run query"
|
200
|
-
end
|
201
|
-
## We use Action to create a button: to test out ampersand with MI and Button
|
202
|
-
b_clear = Button.new @form do
|
203
|
-
#action new_act
|
204
|
-
text "&Clear"
|
205
|
-
row buttrow
|
206
|
-
col c+10
|
207
|
-
help_text "Clear query entry box "
|
208
|
-
end
|
209
|
-
b_clear.command {
|
210
|
-
sqlarea.remove_all
|
211
|
-
sqlarea.focus
|
212
|
-
}
|
213
|
-
|
214
|
-
# using ampersand to set mnemonic
|
215
|
-
|
216
|
-
b_construct = Button.new @form do
|
217
|
-
text "Constr&uct"
|
218
|
-
row buttrow
|
219
|
-
col c+25
|
220
|
-
help_text "Select a table, select columns and press this to construct an SQL"
|
221
|
-
end
|
222
|
-
|
223
|
-
Button.button_layout [b_run, b_clear, b_construct], buttrow, startcol=5, cols=Ncurses.COLS-1, gap=5
|
224
|
-
|
225
|
-
@tp = create_tabbed_pane @form, buttrow, t_width, c
|
226
|
-
@tp.show
|
227
|
-
@data = data
|
228
|
-
|
229
|
-
b_run.command {
|
230
|
-
query = sqlarea.get_text
|
231
|
-
run_query query
|
232
|
-
}
|
233
|
-
#
|
234
|
-
## key bindings fo atable
|
235
|
-
# column widths
|
236
|
-
app = self
|
237
|
-
#atable.configure() do
|
238
|
-
##bind_key(330) { atable.remove_column(tcm.column(atable.focussed_col)) rescue "" }
|
239
|
-
#bind_key(?+) {
|
240
|
-
#acolumn = atable.column atable.focussed_col()
|
241
|
-
#w = acolumn.width + 1
|
242
|
-
#acolumn.width w
|
243
|
-
##atable.table_structure_changed
|
244
|
-
#}
|
245
|
-
#bind_key(?-) {
|
246
|
-
#acolumn = atable.column atable.focussed_col()
|
247
|
-
#w = acolumn.width - 1
|
248
|
-
#if w > 3
|
249
|
-
#acolumn.width w
|
250
|
-
##atable.table_structure_changed
|
251
|
-
#end
|
252
|
-
#}
|
253
|
-
## added new method on 2009-10-08 00:47
|
254
|
-
#bind_key(?=) {
|
255
|
-
#atable.size_columns_to_fit
|
256
|
-
#}
|
257
|
-
#bind_key(?>) {
|
258
|
-
#tcm = atable.get_table_column_model
|
259
|
-
#colcount = tcm.column_count-1
|
260
|
-
##atable.move_column sel_col.value, sel_col.value+1 unless sel_col.value == colcount
|
261
|
-
#col = atable.focussed_col
|
262
|
-
#atable.move_column col, col+1 unless col == colcount
|
263
|
-
#}
|
264
|
-
#bind_key(?<) {
|
265
|
-
#col = atable.focussed_col
|
266
|
-
#atable.move_column col, col-1 unless col == 0
|
267
|
-
##atable.move_column sel_col.value, sel_col.value-1 unless sel_col.value == 0
|
268
|
-
#}
|
269
|
-
## TODO popup and key labels
|
270
|
-
#bind_key(?\M-h, app) {|tab,td| $log.debug " BIND... #{tab.class}, #{td.class}"; app.make_popup atable}
|
271
|
-
#end
|
272
|
-
#keylabel = RubyCurses::Label.new @form, {'text' => "", "row" => r+table_ht+3, "col" => c, "color" => "yellow", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
273
|
-
#eventlabel = RubyCurses::Label.new @form, {'text' => "Events:", "row" => r+table_ht+6, "col" => c, "color" => "white", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
274
|
-
|
275
|
-
# report some events
|
276
|
-
#atable.table_model.bind(:TABLE_MODEL_EVENT){|e| #eventlabel.text = "Event: #{e}"}
|
277
|
-
#atable.get_table_column_model.bind(:TABLE_COLUMN_MODEL_EVENT){|e| eventlabel.text = "Event: #{e}"}
|
278
|
-
|
279
|
-
tablist_ht = 6
|
280
|
-
mylist = @db.get_data "select name from sqlite_master"
|
281
|
-
# mylist is an Array of SQLite3::ResultSet::ArrayWithTypesAndFields
|
282
|
-
raise "Database contains no tables! I need some tables" unless mylist
|
283
|
-
mylist.collect!{|x| x[0] } ## 1.9 hack, but will it run on 1.8 ??
|
284
|
-
$listdata = Variable.new mylist
|
285
|
-
tablelist = Listbox.new @form do
|
286
|
-
name "tablelist"
|
287
|
-
row 1
|
288
|
-
col t_width+2
|
289
|
-
width 20
|
290
|
-
height tablist_ht
|
291
|
-
# list mylist
|
292
|
-
list_variable $listdata
|
293
|
-
#selection_mode :multiple
|
294
|
-
#show_selector true
|
295
|
-
title "Tables"
|
296
|
-
title_attrib 'reverse'
|
297
|
-
help_text "Press ENTER to run * query, Space to select columns"
|
298
|
-
end
|
299
|
-
#tablelist.bind(:PRESS) { |alist| @status_row.text = "Selected #{alist.current_index}" }
|
300
|
-
tablelist.list_selection_model().bind(:LIST_SELECTION_EVENT,tablelist) { |lsm, alist| @status_row.text = "Selected #{alist.current_index}" }
|
301
|
-
|
302
|
-
collist = []
|
303
|
-
$coldata = Variable.new collist
|
304
|
-
columnlist = Listbox.new @form do
|
305
|
-
name "columnlist"
|
306
|
-
row tablist_ht+2
|
307
|
-
col t_width+2
|
308
|
-
width 20
|
309
|
-
height 15
|
310
|
-
# list mylist
|
311
|
-
list_variable $coldata
|
312
|
-
selection_mode :multiple
|
313
|
-
#show_selector true
|
314
|
-
title "Columns"
|
315
|
-
title_attrib 'reverse'
|
316
|
-
help_text "Press ENTER to append columns to sqlarea, Space to select"
|
317
|
-
end
|
318
|
-
## pressing SPACE on a table populates column list with its columns so they can be selected
|
319
|
-
#tablelist.bind_key(32) {
|
320
|
-
# Now space trapped at listbox level, need to use event
|
321
|
-
tablelist.list_selection_model().bind(:LIST_SELECTION_EVENT,tablelist) { |lsm, alist| @status_row.text = "Selected #{alist.current_index}"
|
322
|
-
#@status_row.text = "Selected table #{tablelist.get_content()[tablelist.current_index]}"
|
323
|
-
table = "#{tablelist.get_content()[tablelist.current_index]}"
|
324
|
-
##table = table[0] if table.class==Array ## 1.9 ???
|
325
|
-
columnlist.list_data_model.remove_all
|
326
|
-
columnlist.list_data_model.insert 0, *@db.get_metadata(table)
|
327
|
-
}
|
328
|
-
## pressing ENTER on a table runs a query on it, no need to type and SQL
|
329
|
-
#tablelist.bind_key(13) {
|
330
|
-
tablelist.bind(:PRESS) {
|
331
|
-
@status_row.text = "Selected #{tablelist.get_content()[tablelist.current_index]}"
|
332
|
-
table = "#{tablelist.get_content()[tablelist.current_index]}"
|
333
|
-
##table = table[0] if table.class==Array ## 1.9 ???
|
334
|
-
run_query "select * from #{table}"
|
335
|
-
}
|
336
|
-
#columnlist.bind_key(13) {
|
337
|
-
columnlist.bind(:PRESS) {
|
338
|
-
## append column name to sqlarea if ENTER pressed
|
339
|
-
column = "#{columnlist.get_content()[columnlist.current_index]}"
|
340
|
-
sqlarea << "#{column},"
|
341
|
-
}
|
342
|
-
columnlist.bind_key(32) {
|
343
|
-
## select row - later can press Construct button
|
344
|
-
columnlist.toggle_row_selection
|
345
|
-
column = "#{columnlist.get_content()[columnlist.current_index]}"
|
346
|
-
}
|
347
|
-
## construct an SQL after selecting some columns in the column list
|
348
|
-
b_construct.command {
|
349
|
-
# current_index is wrong, we need selected_index
|
350
|
-
table = "#{tablelist.get_content()[tablelist.selected_index]}"
|
351
|
-
#table = table[0] if table.class==Array ## 1.9 ???
|
352
|
-
indexes = columnlist.selected_rows()
|
353
|
-
columns=[]
|
354
|
-
indexes.each do |i|
|
355
|
-
columns << columnlist.get_content()[i]
|
356
|
-
end
|
357
|
-
sql = "select #{columns.join(',')} from #{table}"
|
358
|
-
sqlarea << sql
|
359
|
-
}
|
360
|
-
|
361
|
-
|
362
|
-
@form.repaint
|
363
|
-
@window.wrefresh
|
364
|
-
Ncurses::Panel.update_panels
|
365
|
-
begin
|
366
|
-
while((ch = @window.getchar()) != ?\C-q.getbyte(0) )
|
367
|
-
break if ch == KEY_F1
|
368
|
-
s = keycode_tos ch
|
369
|
-
status_row.text = "Pressed #{ch} , #{s}. Press C-q to quit, Alt-Tab for exiting table "
|
370
|
-
@form.handle_key(ch)
|
371
|
-
|
372
|
-
@form.repaint
|
373
|
-
@window.wrefresh
|
374
|
-
end
|
375
|
-
ensure
|
376
|
-
@window.destroy if !@window.nil?
|
377
|
-
end
|
378
|
-
end
|
379
|
-
## execute the query in the textarea
|
380
|
-
# @param [String] sql string
|
381
|
-
def run_query sql
|
382
|
-
#query = sqlarea.get_text
|
383
|
-
query = sql
|
384
|
-
begin
|
385
|
-
@content = @db.get_data query
|
386
|
-
if @content.nil?
|
387
|
-
@status_row.text = "0 rows retrieved"
|
388
|
-
return
|
389
|
-
end
|
390
|
-
#cw = @db.estimate_column_widths @atable.width, @db.columns
|
391
|
-
atable = create_table @tp, @tab_ctr #, buttrow, t_width, c
|
392
|
-
atable.set_data @content, @db.columns
|
393
|
-
cw = atable.estimate_column_widths @db.columns, @db.datatypes
|
394
|
-
atable.set_column_widths cw
|
395
|
-
rescue => exc
|
396
|
-
$log.debug(exc.backtrace.join("\n"))
|
397
|
-
alert exc.to_s
|
398
|
-
return
|
399
|
-
end
|
400
|
-
@status_row.text = "#{@content.size} rows retrieved"
|
401
|
-
atable.repaint
|
402
|
-
end
|
403
|
-
## create a Table component for populating with data
|
404
|
-
def create_table tp, counter #, buttrow, t_width, c
|
405
|
-
table_ht = 15
|
406
|
-
atable = Table.new do
|
407
|
-
name "sqltable#{counter}"
|
408
|
-
help_text "M-Tab for next field, C-q quit"
|
409
|
-
end
|
410
|
-
atable.bind(:TABLE_TRAVERSAL_EVENT){|e| @header.text_right "Row #{e.newrow+1} of #{atable.row_count}" }
|
411
|
-
@tab_ctr += 1
|
412
|
-
tab1 = tp.add_tab "Tab&#{@tab_ctr}" , atable
|
413
|
-
return atable
|
414
|
-
end
|
415
|
-
## create the single tabbedpane for populating with resultsets
|
416
|
-
def create_tabbed_pane form, buttrow, t_width, c
|
417
|
-
tp = RubyCurses::TabbedPane.new form do
|
418
|
-
height 16
|
419
|
-
width t_width
|
420
|
-
row buttrow +1
|
421
|
-
col c
|
422
|
-
button_type :ok
|
423
|
-
end
|
424
|
-
return tp
|
425
|
-
end
|
426
|
-
end
|
427
|
-
if $0 == __FILE__
|
428
|
-
include RubyCurses
|
429
|
-
include RubyCurses::Utils
|
430
|
-
|
431
|
-
begin
|
432
|
-
# Initialize curses
|
433
|
-
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
434
|
-
#$log = Logger.new("rbc13.log")
|
435
|
-
$log = Logger.new(ENV['LOGDIR'] || "" + "rbc13.log")
|
436
|
-
|
437
|
-
$log.level = Logger::DEBUG
|
438
|
-
|
439
|
-
colors = Ncurses.COLORS
|
440
|
-
$log.debug "START #{colors} colors SQLC demo "
|
441
|
-
|
442
|
-
catch(:close) do
|
443
|
-
t = Sqlc.new
|
444
|
-
t.run
|
445
|
-
end
|
446
|
-
rescue => ex
|
447
|
-
ensure
|
448
|
-
VER::stop_ncurses
|
449
|
-
p ex if ex
|
450
|
-
p(ex.backtrace.join("\n")) if ex
|
451
|
-
$log.debug( ex) if ex
|
452
|
-
$log.debug(ex.backtrace.join("\n")) if ex
|
453
|
-
end
|
454
|
-
end
|