canis 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -7
- data/examples/testdb.rb +1 -1
- data/lib/canis/core/widgets/rwidget.rb +9 -11
- data/lib/canis/core/widgets/table.rb +75 -61
- data/lib/canis/core/widgets/textpad.rb +88 -93
- data/lib/canis/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ff168e0396a8194dde1fef712068369b675a575648806182c9a5f5540198f7
|
4
|
+
data.tar.gz: 4b0b4a2e219ea2bfefcaff61a293bd47a3d5e423a4237c1d76be0f1c86857767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f295681678c651300eeb93153df8ba6b6a751f5daacb86baa88f2e07b005159b93d933fb2c75e80ca0c7c620b92696dccd0a2237beaefef8e78b165c185b6943
|
7
|
+
data.tar.gz: f5191705d2292807e095c4f90e1740ed8b307a2e0c0a6f75f9049f44c8601009df3b0d9609f55d9145e33974ee26f8eccbeca86e1bc92cd4958ec4dace1f9bc9
|
data/README.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
# Canis
|
2
2
|
|
3
|
+
**2019-03-11**. Kindly note that `canis` is not, and will never be, production-ready.
|
4
|
+
Very few ruby programmers are using ncurses so the usage of canis is
|
5
|
+
very low if any. So kindly do not use for critical work.
|
3
6
|
|
4
|
-
|
7
|
+
That is why I made a much simpler and stripped version of `canis` called `umbra`.
|
8
|
+
I use `umbra` mostly, but that too for a screen with a few fields and a single table,
|
9
|
+
and some popups.
|
10
|
+
|
11
|
+
Umbra will be easier for you to go through, and hack (if you come across a problem) than canis. Having said that, I am perhaps the only user of `umbra`, so again it is at your own risk.
|
12
|
+
|
13
|
+
If anyone wishes to take over and maintain `canis` please contact me.
|
14
|
+
|
15
|
+
## Last update on 2018-03-05 for ruby 2.5
|
5
16
|
|
6
17
|
Everything seems to be working fine without any changes.
|
7
18
|
|
@@ -23,7 +34,7 @@ document reader, `rigel` which is based on the code of `ribhu` (which was rbcurs
|
|
23
34
|
## Usage
|
24
35
|
|
25
36
|
Until, we have better documentation, the best way to understand "canis" is to run the examples in the examples
|
26
|
-
folder. This gives a good idea of what the library does. Now you can open the source and get a feel of the
|
37
|
+
folder. This gives a good idea of what the library does. Now you can open the source and get a feel of the
|
27
38
|
structure of the code and what to study. One can also select an example that is close to the application one has in mind
|
28
39
|
and use the source as a starting point.
|
29
40
|
|
@@ -51,8 +62,8 @@ TODO: Write usage instructions here
|
|
51
62
|
|
52
63
|
Commonly used widgets and features:
|
53
64
|
|
54
|
-
- Textpad - to display non-editable multiline text. Text can be colored.
|
55
|
-
- Listbox - identical to the textpad except that it allows single or multiple selection, and has
|
65
|
+
- Textpad - to display non-editable multiline text. Text can be colored.
|
66
|
+
- Listbox - identical to the textpad except that it allows single or multiple selection, and has
|
56
67
|
some extra events such as entering and leaving or row, and selection.
|
57
68
|
- Field - user entry of a single line of data.
|
58
69
|
- Label - readonly text
|
@@ -80,7 +91,7 @@ Lesser used widgets and features:
|
|
80
91
|
Some Issues with rbcurse:
|
81
92
|
|
82
93
|
Widgets required explicit coordinates. To that effect the App class allowed for `Stack` and `Flow` (idea borrowed from
|
83
|
-
the **Shoes** project. This works well, but all stack and flow information is lost when controls are placed meaning that a
|
94
|
+
the **Shoes** project. This works well, but all stack and flow information is lost when controls are placed meaning that a
|
84
95
|
change in the window size (if user resizes) does not (and cannot) resize the application.
|
85
96
|
|
86
97
|
Canis has recently introduced Layout objects which have the ability to re-locate and resize objects when screen size
|
@@ -91,7 +102,7 @@ Currently there are three layout objects:
|
|
91
102
|
- `StackLayout` : does only stacking of objects (vertical placement)
|
92
103
|
- `FlowLayout` : does only horizontal placement of obects
|
93
104
|
- `SplitLayout` : allows for multiple stacks and flows by means of splitting a split either horizontally or vertically
|
94
|
-
and either placing an object in it, or splitting it further.
|
105
|
+
and either placing an object in it, or splitting it further.
|
95
106
|
These are based on an `AbstractLayout` which can be used to derive further layouts.
|
96
107
|
|
97
108
|
It is my intention to move usage over to these layouts since they are simpler, and allow for resizing (and to abandon
|
@@ -103,7 +114,7 @@ Issues canis would like to address:
|
|
103
114
|
I would like to do this before reaching 1.0.
|
104
115
|
|
105
116
|
- Keymapping. Currently, takes codes as integers, but i would have liked moving to strings as in vim.
|
106
|
-
Currently we have to map `?\C-a.getbytes(0)` or `[?g, ?g]`, whereas a string would allow us to map `"<C-x>s"`
|
117
|
+
Currently we have to map `?\C-a.getbytes(0)` or `[?g, ?g]`, whereas a string would allow us to map `"<C-x>s"`
|
107
118
|
or `"<F1>"` or `"gg"`. The issue is that there is too much rework within the library since each widget uses integer mappings.
|
108
119
|
Mapping and matching multiple keys would be a lot easier if stored internally as a string, currently multiple
|
109
120
|
mappings require a hash or tree at each level.
|
@@ -115,6 +126,9 @@ This tutorial needs to be updated for canis. Although, canis has diverged/forked
|
|
115
126
|
There is some on-line documentation of classes at:
|
116
127
|
http://rubydoc.info/gems/canis/0.0.8/frames
|
117
128
|
|
129
|
+
Umbra/ncumbra is at:
|
130
|
+
https://github.com/mare-imbrium/umbra
|
131
|
+
|
118
132
|
## Contributing
|
119
133
|
|
120
134
|
- Please give suggestions on how to improve the documentation.
|
data/examples/testdb.rb
CHANGED
@@ -105,7 +105,7 @@ begin
|
|
105
105
|
#file = "movies1000.txt"
|
106
106
|
|
107
107
|
arr = get_data
|
108
|
-
tv = Canis::Table.new @form, :row =>
|
108
|
+
tv = Canis::Table.new @form, :row => 2, :col => 0, :height => h, :width => w, :name => "tv", :suppress_borders => false do |b|
|
109
109
|
|
110
110
|
b.resultset $columns, arr
|
111
111
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
* Author: jkepler (ABCD)
|
10
10
|
* Date: 2008-11-19 12:49
|
11
11
|
* License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
12
|
-
* Last update:
|
12
|
+
* Last update: 2018-05-16 12:40
|
13
13
|
|
14
14
|
== CHANGES
|
15
15
|
* 2011-10-2 Added PropertyVetoException to rollback changes to property
|
@@ -97,15 +97,14 @@ class Module # dsl_accessor {{{
|
|
97
97
|
oldvalue = @#{sym}
|
98
98
|
tmp = val.size == 1 ? val[0] : val
|
99
99
|
newvalue = tmp
|
100
|
-
if
|
100
|
+
if @_object_created.nil?
|
101
101
|
@#{sym} = tmp
|
102
102
|
end
|
103
|
-
return(self) if
|
103
|
+
return(self) if @_object_created.nil?
|
104
104
|
|
105
105
|
if oldvalue != newvalue
|
106
106
|
# trying to reduce calls to fire, when object is being created
|
107
107
|
begin
|
108
|
-
@property_changed = true
|
109
108
|
fire_property_change("#{sym}", oldvalue, newvalue) if !oldvalue.nil?
|
110
109
|
@#{sym} = tmp
|
111
110
|
@config["#{sym}"]=@#{sym}
|
@@ -909,9 +908,9 @@ module Canis
|
|
909
908
|
# create a logger giving a path.
|
910
909
|
def create_logger path
|
911
910
|
#path = File.join(ENV["LOGDIR"] || "./" ,"canis14.log")
|
912
|
-
|
913
|
-
logg = Logger.new(
|
914
|
-
raise "Could not create logger
|
911
|
+
_path = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
912
|
+
logg = Logger.new(_path)
|
913
|
+
raise "Could not create logger: #{path}" unless logg
|
915
914
|
# if not set, will default to 0 which is debug. Other values are 1 - info, 2 - warn
|
916
915
|
logg.level = ENV["CANIS_LOG_LEVEL"].to_i
|
917
916
|
colors = Ncurses.COLORS
|
@@ -1023,12 +1022,11 @@ module Canis
|
|
1023
1022
|
return :NO_BLOCK
|
1024
1023
|
end # if
|
1025
1024
|
end
|
1026
|
-
## added on 2009-01-08 00:33
|
1027
1025
|
# goes with dsl_property
|
1028
|
-
# Need to inform listeners - done 2010-02-25 23:09
|
1029
1026
|
# Can throw a FieldValidationException or PropertyVetoException
|
1030
1027
|
def fire_property_change text, oldvalue, newvalue
|
1031
|
-
return if
|
1028
|
+
return if @_object_created.nil? # 2018-05-15 - removed check for nil, as object can be nil on creation
|
1029
|
+
# but set later.
|
1032
1030
|
#$log.debug " FPC #{self}: #{text} #{oldvalue}, #{newvalue}"
|
1033
1031
|
$log.debug " FPC #{self}: #{text} "
|
1034
1032
|
if @pce.nil?
|
@@ -1037,7 +1035,7 @@ module Canis
|
|
1037
1035
|
@pce.set( self, text, oldvalue, newvalue)
|
1038
1036
|
end
|
1039
1037
|
fire_handler :PROPERTY_CHANGE, @pce
|
1040
|
-
@repaint_required = true
|
1038
|
+
@repaint_required = true
|
1041
1039
|
repaint_all(true) # for repainting borders, headers etc 2011-09-28 V1.3.1
|
1042
1040
|
end
|
1043
1041
|
|
@@ -7,11 +7,11 @@
|
|
7
7
|
# Author: jkepler http://github.com/mare-imbrium/canis/
|
8
8
|
# Date: 2013-03-29 - 20:07
|
9
9
|
# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
10
|
-
# Last update:
|
10
|
+
# Last update: 2019-03-12 15:17
|
11
11
|
# ----------------------------------------------------------------------------- #
|
12
12
|
# table.rb Copyright (C) 2012-2014 kepler
|
13
13
|
|
14
|
-
# == CHANGES:
|
14
|
+
# == CHANGES:
|
15
15
|
# - changed @content to @list since all multirow wids and utils expect @list
|
16
16
|
# - changed name from tablewidget to table
|
17
17
|
#
|
@@ -29,7 +29,7 @@ require 'logger'
|
|
29
29
|
require 'canis'
|
30
30
|
require 'canis/core/widgets/textpad'
|
31
31
|
|
32
|
-
##
|
32
|
+
##
|
33
33
|
# The motivation to create yet another table widget is because tabular_widget
|
34
34
|
# is based on textview etc which have a lot of complex processing and rendering
|
35
35
|
# whereas textpad is quite simple. It is easy to just add one's own renderer
|
@@ -83,8 +83,8 @@ module Canis
|
|
83
83
|
# It's a pretty simple sorter and uses sort, not sort_by.
|
84
84
|
# Improvements welcome.
|
85
85
|
# Usage: provide model in constructor or using model method
|
86
|
-
# Call toggle_sort_order(column_index)
|
87
|
-
# Call sort.
|
86
|
+
# Call toggle_sort_order(column_index)
|
87
|
+
# Call sort.
|
88
88
|
# Currently, this sorts the provided model in-place. Future versions
|
89
89
|
# may maintain a copy, or use a table that provides a mapping of model to result.
|
90
90
|
# # TODO check if column_sortable
|
@@ -123,11 +123,11 @@ module Canis
|
|
123
123
|
# with textpad, this way we avoid touching it
|
124
124
|
header = @model.delete_at 0
|
125
125
|
begin
|
126
|
-
# next line often can give error "array within array" - i think on date fields that
|
126
|
+
# next line often can give error "array within array" - i think on date fields that
|
127
127
|
# contain nils
|
128
|
-
@model.sort!{|x,y|
|
128
|
+
@model.sort!{|x,y|
|
129
129
|
res = 0
|
130
|
-
@sort_keys.each { |ee|
|
130
|
+
@sort_keys.each { |ee|
|
131
131
|
e = ee.abs-1 # since we had offsetted by 1 earlier
|
132
132
|
abse = e.abs
|
133
133
|
if ee < 0
|
@@ -173,7 +173,7 @@ module Canis
|
|
173
173
|
# internally, reverse sort is maintained by multiplying number by -1
|
174
174
|
@sort_keys ||= []
|
175
175
|
if @sort_keys.first && index == @sort_keys.first.abs
|
176
|
-
@sort_keys[0] *= -1
|
176
|
+
@sort_keys[0] *= -1
|
177
177
|
else
|
178
178
|
@sort_keys.delete index # in case its already there
|
179
179
|
@sort_keys.delete(index*-1) # in case its already there
|
@@ -241,7 +241,7 @@ module Canis
|
|
241
241
|
# and returns an array which is used for printing
|
242
242
|
#
|
243
243
|
# return an array so caller can color columns if need be
|
244
|
-
def convert_value_to_text r
|
244
|
+
def convert_value_to_text r
|
245
245
|
str = []
|
246
246
|
fmt = nil
|
247
247
|
field = nil
|
@@ -285,12 +285,12 @@ module Canis
|
|
285
285
|
def render pad, lineno, str
|
286
286
|
#lineno += 1 # header_adjustment
|
287
287
|
# header_adjustment means columns have been set
|
288
|
-
return render_header pad, lineno, 0, str if lineno == 0
|
288
|
+
return render_header pad, lineno, 0, str if lineno == 0 && @source.header_adjustment > 0
|
289
289
|
#text = str.join " | "
|
290
290
|
#text = @fmstr % str
|
291
291
|
text = convert_value_to_text str
|
292
292
|
if @_check_coloring
|
293
|
-
|
293
|
+
$log.debug "XXX: INSIDE COLORIIN"
|
294
294
|
text = colorize pad, lineno, text
|
295
295
|
return
|
296
296
|
end
|
@@ -314,7 +314,7 @@ module Canis
|
|
314
314
|
att = REVERSE
|
315
315
|
# FIXME currentl this overflows into next row
|
316
316
|
end
|
317
|
-
|
317
|
+
|
318
318
|
FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
|
319
319
|
FFI::NCurses.mvwaddstr(pad, lineno, 0, text)
|
320
320
|
FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
|
@@ -323,6 +323,7 @@ module Canis
|
|
323
323
|
def render_header pad, lineno, col, columns
|
324
324
|
# I could do it once only but if user sets colors midway we can check once whenvever
|
325
325
|
# repainting
|
326
|
+
# $log.debug "INSIDE render_header XXXXX #{@source.name}, #{lineno}, #{col}"
|
326
327
|
check_colors #if @_check_coloring.nil?
|
327
328
|
#text = columns.join " | "
|
328
329
|
#text = @fmstr % columns
|
@@ -349,7 +350,7 @@ module Canis
|
|
349
350
|
}
|
350
351
|
end
|
351
352
|
def each_column
|
352
|
-
@chash.each_with_index { |c, i|
|
353
|
+
@chash.each_with_index { |c, i|
|
353
354
|
next if c.hidden
|
354
355
|
yield c,i if block_given?
|
355
356
|
}
|
@@ -395,10 +396,10 @@ module Canis
|
|
395
396
|
# focus, and should be used for row operations.
|
396
397
|
#
|
397
398
|
# In order to use Textpad easily, the first row of the table model is the column names. Data is maintained
|
398
|
-
# in an Array. Several operations are delegated to Array, or have the same name. You can get the list
|
399
|
+
# in an Array. Several operations are delegated to Array, or have the same name. You can get the list
|
399
400
|
# using `list()` to run other Array operations on it.
|
400
401
|
#
|
401
|
-
# If you modify the Array directly, you may have to use `fire_row_changed(index)` to reflect the update to
|
402
|
+
# If you modify the Array directly, you may have to use `fire_row_changed(index)` to reflect the update to
|
402
403
|
# a single row. If you delete or add a row, you will have to use `fire_dimension_changed()`. However,
|
403
404
|
# internal functions do this automatically.
|
404
405
|
#
|
@@ -418,12 +419,12 @@ module Canis
|
|
418
419
|
# When printing we should loop through chash and get the index in data
|
419
420
|
#
|
420
421
|
# should be zero here, but then we won't get textpad correct
|
421
|
-
@_header_adjustment = 0
|
422
|
+
@_header_adjustment = 0
|
422
423
|
@col_min_width = 3
|
423
424
|
|
424
425
|
self.extend DefaultListSelection
|
425
426
|
super
|
426
|
-
create_default_renderer unless @renderer # 2014-04-10 - 11:01
|
427
|
+
create_default_renderer unless @renderer # 2014-04-10 - 11:01
|
427
428
|
# NOTE listselection takes + and - for ask_select
|
428
429
|
bind_key(?w, "next column") { self.next_column }
|
429
430
|
bind_key(?b, "prev column") { self.prev_column }
|
@@ -441,9 +442,9 @@ module Canis
|
|
441
442
|
@list_selection_model = nil
|
442
443
|
@list_selection_model = Canis::DefaultListSelectionModel.new self
|
443
444
|
end
|
444
|
-
|
445
|
+
|
445
446
|
# retrieve the column info structure for the given offset. The offset
|
446
|
-
# pertains to the visible offset not actual offset in data model.
|
447
|
+
# pertains to the visible offset not actual offset in data model.
|
447
448
|
# These two differ when we move a column.
|
448
449
|
# @return ColumnInfo object containing width align color bgcolor attrib hidden
|
449
450
|
def get_column index
|
@@ -454,7 +455,7 @@ module Canis
|
|
454
455
|
@chash[index] = c
|
455
456
|
return c
|
456
457
|
end
|
457
|
-
##
|
458
|
+
##
|
458
459
|
# returns collection of ColumnInfo objects
|
459
460
|
def column_model
|
460
461
|
@chash
|
@@ -463,8 +464,8 @@ module Canis
|
|
463
464
|
# calculate pad width based on widths of columns
|
464
465
|
def content_cols
|
465
466
|
total = 0
|
466
|
-
#@chash.each_pair { |i, c|
|
467
|
-
#@chash.each_with_index { |c, i|
|
467
|
+
#@chash.each_pair { |i, c|
|
468
|
+
#@chash.each_with_index { |c, i|
|
468
469
|
#next if c.hidden
|
469
470
|
each_column {|c,i|
|
470
471
|
w = c.width
|
@@ -474,7 +475,7 @@ module Canis
|
|
474
475
|
return total
|
475
476
|
end
|
476
477
|
|
477
|
-
#
|
478
|
+
#
|
478
479
|
# This calculates and stores the offset at which each column starts.
|
479
480
|
# Used when going to next column or doing a find for a string in the table.
|
480
481
|
# TODO store this inside the hash so it's not calculated again in renderer
|
@@ -483,8 +484,8 @@ module Canis
|
|
483
484
|
@coffsets = []
|
484
485
|
total = 0
|
485
486
|
|
486
|
-
#@chash.each_pair { |i, c|
|
487
|
-
#@chash.each_with_index { |c, i|
|
487
|
+
#@chash.each_pair { |i, c|
|
488
|
+
#@chash.each_with_index { |c, i|
|
488
489
|
#next if c.hidden
|
489
490
|
each_column {|c,i|
|
490
491
|
w = c.width
|
@@ -501,10 +502,10 @@ module Canis
|
|
501
502
|
def _convert_curpos_to_column #:nodoc:
|
502
503
|
_calculate_column_offsets unless @coffsets
|
503
504
|
x = 0
|
504
|
-
@coffsets.each_with_index { |i, ix|
|
505
|
-
if @curpos < i
|
505
|
+
@coffsets.each_with_index { |i, ix|
|
506
|
+
if @curpos < i
|
506
507
|
break
|
507
|
-
else
|
508
|
+
else
|
508
509
|
x += 1
|
509
510
|
end
|
510
511
|
}
|
@@ -526,7 +527,7 @@ module Canis
|
|
526
527
|
# TODO take care of multipliers
|
527
528
|
_calculate_column_offsets unless @coffsets
|
528
529
|
c = @column_pointer.next
|
529
|
-
cp = @coffsets[c]
|
530
|
+
cp = @coffsets[c]
|
530
531
|
#$log.debug " next_column #{c} , #{cp} "
|
531
532
|
@curpos = cp if cp
|
532
533
|
down() if c < @column_pointer.last_index
|
@@ -538,13 +539,13 @@ module Canis
|
|
538
539
|
# TODO take care of multipliers
|
539
540
|
_calculate_column_offsets unless @coffsets
|
540
541
|
c = @column_pointer.previous
|
541
|
-
cp = @coffsets[c]
|
542
|
+
cp = @coffsets[c]
|
542
543
|
#$log.debug " prev #{c} , #{cp} "
|
543
544
|
@curpos = cp if cp
|
544
545
|
up() if c > @column_pointer.last_index
|
545
546
|
fire_column_event :ENTER_COLUMN
|
546
547
|
end
|
547
|
-
# a column traversal has happened.
|
548
|
+
# a column traversal has happened.
|
548
549
|
# FIXME needs to be looked into. is this consistent naming wise and are we using the correct object
|
549
550
|
# In old system it was TABLE_TRAVERSAL_EVENT
|
550
551
|
def fire_column_event eve
|
@@ -579,7 +580,7 @@ module Canis
|
|
579
580
|
end
|
580
581
|
def contract_column
|
581
582
|
x = _convert_curpos_to_column
|
582
|
-
w = get_column(x).width
|
583
|
+
w = get_column(x).width
|
583
584
|
return if w <= @col_min_width
|
584
585
|
column_width x, w-1 if w
|
585
586
|
@coffsets = nil
|
@@ -601,7 +602,7 @@ module Canis
|
|
601
602
|
|
602
603
|
##
|
603
604
|
# getter and setter for columns
|
604
|
-
# 2014-04-10 - 13:49
|
605
|
+
# 2014-04-10 - 13:49
|
605
606
|
# @param [Array] columns to set as Array of Strings
|
606
607
|
# @return if no args, returns array of column names as Strings
|
607
608
|
# NOTE
|
@@ -620,10 +621,11 @@ module Canis
|
|
620
621
|
@list << array
|
621
622
|
_init_model array
|
622
623
|
|
623
|
-
# update the names in column model
|
624
|
-
array.each_with_index { |n,i|
|
624
|
+
# update the names in column model
|
625
|
+
array.each_with_index { |n,i|
|
625
626
|
c = get_column(i)
|
626
|
-
c.name = name
|
627
|
+
#c.name = name ## 2018-05-19 - seems to be a bug
|
628
|
+
c.name = n
|
627
629
|
}
|
628
630
|
self
|
629
631
|
end
|
@@ -647,7 +649,7 @@ module Canis
|
|
647
649
|
def _init_model array
|
648
650
|
# clear the column data -- this line should be called otherwise previous tables stuff will remain.
|
649
651
|
@chash.clear
|
650
|
-
array.each_with_index { |e,i|
|
652
|
+
array.each_with_index { |e,i|
|
651
653
|
# if columns added later we could be overwriting the width
|
652
654
|
c = get_column(i)
|
653
655
|
c.width ||= 10
|
@@ -658,7 +660,7 @@ module Canis
|
|
658
660
|
# size each column based on widths of this row of data.
|
659
661
|
def model_row index
|
660
662
|
array = @list[index]
|
661
|
-
array.each_with_index { |c,i|
|
663
|
+
array.each_with_index { |c,i|
|
662
664
|
# if columns added later we could be overwriting the width
|
663
665
|
ch = get_column(i)
|
664
666
|
ch.width = c.to_s.length + 2
|
@@ -670,7 +672,7 @@ module Canis
|
|
670
672
|
# estimate columns widths based on data in first 10 or so rows
|
671
673
|
# This will override any previous widths, so put custom widths
|
672
674
|
# after calling this.
|
673
|
-
def estimate_column_widths
|
675
|
+
def estimate_column_widths
|
674
676
|
each_column {|c,i|
|
675
677
|
c.width = suggest_column_width(i)
|
676
678
|
}
|
@@ -683,7 +685,7 @@ module Canis
|
|
683
685
|
#ret = @cw[col] || 2
|
684
686
|
ret = get_column(col).width || 2
|
685
687
|
ctr = 0
|
686
|
-
@list.each_with_index { |r, i|
|
688
|
+
@list.each_with_index { |r, i|
|
687
689
|
#next if i < @toprow # this is also a possibility, it checks visible rows
|
688
690
|
break if ctr > 10
|
689
691
|
ctr += 1
|
@@ -736,7 +738,7 @@ module Canis
|
|
736
738
|
#
|
737
739
|
# table = Table.new ...
|
738
740
|
# table.filename 'contacts.tsv', :separator => '|', :columns => true
|
739
|
-
#
|
741
|
+
#
|
740
742
|
def filename name, _config = {}
|
741
743
|
arr = File.open(name,"r").read.split("\n")
|
742
744
|
lines = []
|
@@ -782,7 +784,7 @@ module Canis
|
|
782
784
|
l = @list
|
783
785
|
end
|
784
786
|
|
785
|
-
File.open(outfile, 'w') {|f|
|
787
|
+
File.open(outfile, 'w') {|f|
|
786
788
|
l.each {|r|
|
787
789
|
line = r.join "\t"
|
788
790
|
f.puts line
|
@@ -805,7 +807,7 @@ module Canis
|
|
805
807
|
end
|
806
808
|
alias :<< :add
|
807
809
|
|
808
|
-
# delete a data row at index
|
810
|
+
# delete a data row at index
|
809
811
|
#
|
810
812
|
# NOTE : This does not adjust for header_adjustment. So zero will refer to the header if there is one.
|
811
813
|
# This is to keep consistent with textpad which does not know of header_adjustment and uses the actual
|
@@ -813,7 +815,7 @@ module Canis
|
|
813
815
|
#
|
814
816
|
def delete_at ix
|
815
817
|
return unless @list
|
816
|
-
raise ArgumentError, "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list.length
|
818
|
+
raise ArgumentError, "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list.length
|
817
819
|
fire_dimension_changed
|
818
820
|
#@list.delete_at(ix + @_header_adjustment)
|
819
821
|
@list.delete_at(ix)
|
@@ -843,7 +845,7 @@ module Canis
|
|
843
845
|
fire_row_changed actrow
|
844
846
|
self
|
845
847
|
end
|
846
|
-
|
848
|
+
|
847
849
|
#------- column related methods ------#
|
848
850
|
#
|
849
851
|
# convenience method to set width of a column
|
@@ -871,11 +873,11 @@ module Canis
|
|
871
873
|
def _invalidate_width_cache #:nodoc:
|
872
874
|
@coffsets = nil
|
873
875
|
end
|
874
|
-
##
|
876
|
+
##
|
875
877
|
# should all this move into table column model or somepn
|
876
878
|
# move a column from offset ix to offset newix
|
877
879
|
def move_column ix, newix
|
878
|
-
acol = @chash.delete_at ix
|
880
|
+
acol = @chash.delete_at ix
|
879
881
|
@chash.insert newix, acol
|
880
882
|
_invalidate_width_cache
|
881
883
|
#tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE)
|
@@ -894,7 +896,7 @@ module Canis
|
|
894
896
|
def calculate_column_width col, maxrows=99
|
895
897
|
ret = 3
|
896
898
|
ctr = 0
|
897
|
-
@list.each_with_index { |r, i|
|
899
|
+
@list.each_with_index { |r, i|
|
898
900
|
#next if i < @toprow # this is also a possibility, it checks visible rows
|
899
901
|
break if ctr > maxrows
|
900
902
|
ctr += 1
|
@@ -914,10 +916,22 @@ module Canis
|
|
914
916
|
sr = @startrow + top
|
915
917
|
sc = @startcol + left
|
916
918
|
# first do header always in first row
|
917
|
-
|
919
|
+
# -- prefresh arguments are:
|
920
|
+
# 1. pad
|
921
|
+
# 2. pminrow
|
922
|
+
# 3. pmincol (pad upper left)
|
923
|
+
# 4, sminrow (screen upper left row)
|
924
|
+
# 5, smincol
|
925
|
+
# 6, smaxrow
|
926
|
+
# 7, smaxcol
|
927
|
+
|
928
|
+
# 2019-03-12 - fixed bug in table, only printed header if table on row 1
|
929
|
+
retval = FFI::NCurses.prefresh(@pad, @prow, @pcol, sr, sc, sr + 1, @cols + sc)
|
930
|
+
$log.warn "XXX: PADREFRESH HEADER #{retval}, #{@prow}, #{@pcol}, #{sr}, #{sc}, #{1+sr}, #{@cols+sc}." if retval == -1
|
931
|
+
# retval = FFI::NCurses.prefresh(@pad,0,@pcol, sr , sc , 2 , @cols+ sc );
|
918
932
|
# now print rest of data
|
919
933
|
# h is header_adjustment
|
920
|
-
h = 1
|
934
|
+
h = 1
|
921
935
|
retval = FFI::NCurses.prefresh(@pad,@prow + h,@pcol, sr + h , sc , @rows + sr , @cols+ sc );
|
922
936
|
$log.warn "XXX: PADREFRESH #{retval}, #{@prow}, #{@pcol}, #{sr}, #{sc}, #{@rows+sr}, #{@cols+sc}." if retval == -1
|
923
937
|
# padrefresh can fail if width is greater than NCurses.COLS
|
@@ -930,7 +944,7 @@ module Canis
|
|
930
944
|
# set a default renderer
|
931
945
|
#--
|
932
946
|
# we were not doing this automatically, so repaint was going to TP and failing on mvaddstr
|
933
|
-
# 2014-04-10 - 10:57
|
947
|
+
# 2014-04-10 - 10:57
|
934
948
|
#++
|
935
949
|
def create_default_renderer
|
936
950
|
r = DefaultTableRenderer.new self
|
@@ -958,7 +972,7 @@ module Canis
|
|
958
972
|
end
|
959
973
|
super
|
960
974
|
end
|
961
|
-
##
|
975
|
+
##
|
962
976
|
# Find the next row that contains given string
|
963
977
|
# Overrides textpad since each line is an array
|
964
978
|
# NOTE does not go to next match within row
|
@@ -982,7 +996,7 @@ module Canis
|
|
982
996
|
# value can be numeric
|
983
997
|
col = f.to_s.index str
|
984
998
|
if col
|
985
|
-
col += @coffsets[jx]
|
999
|
+
col += @coffsets[jx]
|
986
1000
|
first ||= [ ix, col ]
|
987
1001
|
if ix > @current_index
|
988
1002
|
return [ix, col]
|
@@ -996,14 +1010,14 @@ module Canis
|
|
996
1010
|
# if yield returns true, collects index of row into array and returns the array
|
997
1011
|
# @returns array of indices which can be empty
|
998
1012
|
# Value yielded can be fixnum or date etc
|
999
|
-
def matching_indices
|
1013
|
+
def matching_indices
|
1000
1014
|
raise "block required for matching_indices" unless block_given?
|
1001
1015
|
@indices = []
|
1002
1016
|
## content can be string or Chunkline, so we had to write <tt>index</tt> for this.
|
1003
1017
|
@list.each_with_index do |fields, ix|
|
1004
1018
|
flag = yield ix, fields
|
1005
1019
|
if flag
|
1006
|
-
@indices << ix
|
1020
|
+
@indices << ix
|
1007
1021
|
end
|
1008
1022
|
end
|
1009
1023
|
#$log.debug "XXX: INDICES found #{@indices}"
|
@@ -1023,7 +1037,7 @@ module Canis
|
|
1023
1037
|
end
|
1024
1038
|
@indices = nil
|
1025
1039
|
end
|
1026
|
-
##
|
1040
|
+
##
|
1027
1041
|
# Ensure current row is visible, if not make it first row
|
1028
1042
|
# This overrides textpad due to header_adjustment, otherwise
|
1029
1043
|
# during next_match, the header overrides the found row.
|
@@ -1038,7 +1052,7 @@ module Canis
|
|
1038
1052
|
# yields non-hidden columns (ColumnInfo) and the offset/index
|
1039
1053
|
# This is the order in which columns are to be printed
|
1040
1054
|
def each_column
|
1041
|
-
@chash.each_with_index { |c, i|
|
1055
|
+
@chash.each_with_index { |c, i|
|
1042
1056
|
next if c.hidden
|
1043
1057
|
yield c,i if block_given?
|
1044
1058
|
}
|
@@ -1051,7 +1065,7 @@ module Canis
|
|
1051
1065
|
end
|
1052
1066
|
else
|
1053
1067
|
@list.each_with_index { |line, ix|
|
1054
|
-
#FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix])
|
1068
|
+
# FFI::NCurses.mvwaddstr(@pad,ix, 0, @list[ix].to_s)
|
1055
1069
|
render @pad, ix, line
|
1056
1070
|
}
|
1057
1071
|
end
|
@@ -1063,8 +1077,8 @@ module Canis
|
|
1063
1077
|
ha = @_header_adjustment
|
1064
1078
|
# ha takes into account whether there are headers or not
|
1065
1079
|
footer = "#{@current_index+1-ha} of #{@list.length-ha} "
|
1066
|
-
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
1067
|
-
@repaint_footer_required = false
|
1080
|
+
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
1081
|
+
@repaint_footer_required = false
|
1068
1082
|
end
|
1069
1083
|
|
1070
1084
|
end # class Table
|
@@ -4,17 +4,17 @@
|
|
4
4
|
# ----------------------------------------------------------------------------- #
|
5
5
|
# File: textpad.rb
|
6
6
|
# Description: A class that displays text using a pad.
|
7
|
-
# The motivation for this is to put formatted text and not care about truncating and
|
7
|
+
# The motivation for this is to put formatted text and not care about truncating and
|
8
8
|
# stuff. Also, there will be only one write, not each time scrolling happens.
|
9
9
|
# I found textview code for repaint being more complex than required.
|
10
10
|
# Author: jkepler http://github.com/mare-imbrium/mancurses/
|
11
11
|
# Date: 2011-11-09 - 16:59
|
12
12
|
# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
13
|
-
# Last update:
|
13
|
+
# Last update: 2019-03-12 00:17
|
14
14
|
#
|
15
15
|
# == CHANGES
|
16
16
|
# - changed @content to @list since all multirow widgets use that and so do utils etc
|
17
|
-
# == TODO
|
17
|
+
# == TODO
|
18
18
|
# Take care of 3 cases:
|
19
19
|
# 1. complete data change, then recreate pad, and call init_vars resetting row, col and curpos etc
|
20
20
|
# This is done by method text().
|
@@ -33,7 +33,7 @@ require 'forwardable'
|
|
33
33
|
include Canis
|
34
34
|
module Canis
|
35
35
|
extend self
|
36
|
-
class TextPad < Widget #
|
36
|
+
class TextPad < Widget #
|
37
37
|
include BorderTitle
|
38
38
|
extend Forwardable
|
39
39
|
|
@@ -116,17 +116,17 @@ module Canis
|
|
116
116
|
end
|
117
117
|
|
118
118
|
# calculates the dimensions of the pad which will be used when the pad refreshes, taking into account
|
119
|
-
# whether borders are printed or not. This must be called whenever there is a change in height or width
|
119
|
+
# whether borders are printed or not. This must be called whenever there is a change in height or width
|
120
120
|
# otherwise @rows will not be recalculated.
|
121
121
|
# Internal.
|
122
122
|
def __calc_dimensions
|
123
|
-
## NOTE
|
123
|
+
## NOTE
|
124
124
|
# ---------------------------------------------------
|
125
125
|
# Since we are using pads, you need to get your height, width and rows correct
|
126
126
|
# Make sure the height factors in the row, else nothing may show
|
127
127
|
# ---------------------------------------------------
|
128
|
-
|
129
|
-
|
128
|
+
|
129
|
+
|
130
130
|
raise " CALC inside #{@name} h or w is nil #{@height} , #{@width} " if @height.nil? or @width.nil?
|
131
131
|
@rows = @height
|
132
132
|
@cols = @width
|
@@ -149,13 +149,13 @@ module Canis
|
|
149
149
|
#@cols -=0
|
150
150
|
@cols -=1
|
151
151
|
@scrollatrows = @height - 1 # check this out 0 or 1
|
152
|
-
@row_offset = @col_offset = 0
|
152
|
+
@row_offset = @col_offset = 0
|
153
153
|
end
|
154
154
|
@top = @row
|
155
155
|
@left = @col
|
156
156
|
@lastrow = @row + @row_offset
|
157
157
|
@lastcol = @col + @col_offset
|
158
|
-
$log.debug " CALC_DIMENSION
|
158
|
+
$log.debug " CALC_DIMENSION r:#{@rows} , c:#{@cols}, h:#{@height} , w:#{@width} , top:#{@top} , left:#{@left} "
|
159
159
|
end
|
160
160
|
def scrollatrows
|
161
161
|
unless @suppress_borders
|
@@ -189,12 +189,12 @@ module Canis
|
|
189
189
|
## creates the pad
|
190
190
|
def create_pad
|
191
191
|
destroy if @pad
|
192
|
-
#$log.debug "XXXCP: create_pad #{@content_rows} #{@content_cols} , w:#{@width} c #{@cols} , r: #{@rows}"
|
192
|
+
#$log.debug "XXXCP: create_pad #{@content_rows} #{@content_cols} , w:#{@width} c #{@cols} , r: #{@rows}"
|
193
193
|
|
194
194
|
@content_rows = @content_cols = nil
|
195
195
|
@content_rows = pad_rows()
|
196
196
|
@content_cols = pad_cols()
|
197
|
-
$log.debug "XXXCP: create_pad :#{@content_rows} , #{@content_cols} . w:#{@width} c #{@cols} , r: #{@rows}"
|
197
|
+
$log.debug "XXXCP: create_pad :#{@content_rows} , #{@content_cols} . w:#{@width} c #{@cols} , r: #{@rows}"
|
198
198
|
raise "create_pad content_rows is nil " unless @content_rows
|
199
199
|
raise "create_pad content_cols is nil " unless @content_cols
|
200
200
|
|
@@ -204,7 +204,7 @@ module Canis
|
|
204
204
|
# content_rows can be more than size of pad, but never less. Same for cols.
|
205
205
|
# height of pad, or number of row, earlier called @content_rows
|
206
206
|
public
|
207
|
-
def pad_rows
|
207
|
+
def pad_rows
|
208
208
|
# content_rows can be more than size of pad, but never less. Same for cols.
|
209
209
|
return @content_rows if @content_rows
|
210
210
|
content_rows = @list.count
|
@@ -234,7 +234,7 @@ module Canis
|
|
234
234
|
@clearstring = nil
|
235
235
|
$log.debug " populate pad color = #{@color} , bg = #{@bgcolor} "
|
236
236
|
#cp = get_color($datacolor, color(), bgcolor())
|
237
|
-
# commenting off next line meant that textdialog had a black background 2014-05-01 - 23:37
|
237
|
+
# commenting off next line meant that textdialog had a black background 2014-05-01 - 23:37
|
238
238
|
#@cp = FFI::NCurses.COLOR_PAIR(cp)
|
239
239
|
# we seem to be clearing always since a pad is often reused. so making the variable whenever pad created.
|
240
240
|
|
@@ -271,7 +271,7 @@ module Canis
|
|
271
271
|
# REST IS REQUIRED otherwise sometimes last line of window is not cleared
|
272
272
|
# Happens in bline.rb. i think the above clears the new pad size in the window
|
273
273
|
# which if it is smaller then does not clear complete window.
|
274
|
-
## TRYING OUT COMMENTING OFF THE REMAINDER 2014-05-31 - 14:35
|
274
|
+
## TRYING OUT COMMENTING OFF THE REMAINDER 2014-05-31 - 14:35
|
275
275
|
# next part is messing up messageboxes which have a white background
|
276
276
|
# so i use this copied from print_border
|
277
277
|
# In messageboxes the border is more inside. but pad cannot clear the entire
|
@@ -292,7 +292,7 @@ module Canis
|
|
292
292
|
sp = " " * ww
|
293
293
|
#if color == $datacolor
|
294
294
|
$log.debug " clear_pad: colors #{@cp}, ( #{_bgcolor} #{_color} ) #{$datacolor} , attrib #{att} . r #{r} w #{ww}, h #{@height} top #{@window.top} "
|
295
|
-
# 2014-05-15 - 11:01 seems we were clearing an extra row at bottom.
|
295
|
+
# 2014-05-15 - 11:01 seems we were clearing an extra row at bottom.
|
296
296
|
# earlier it was r+1 but that was missing the first row, so now made it r+0 2014-06-20 - 01:15 XXX
|
297
297
|
(r+0).upto(r+@height-startcol-1) do |rr|
|
298
298
|
@window.printstring( rr, _col ,sp , color, att)
|
@@ -317,7 +317,7 @@ module Canis
|
|
317
317
|
public
|
318
318
|
def padrefresh
|
319
319
|
# sometimes padref is called directly from somewhere but dimensions have changed.
|
320
|
-
# 2014-05-27 - 11:42
|
320
|
+
# 2014-05-27 - 11:42
|
321
321
|
unless @__first_time
|
322
322
|
__calc_dimensions
|
323
323
|
@__first_time = true
|
@@ -350,7 +350,7 @@ module Canis
|
|
350
350
|
#sr -= _t
|
351
351
|
#$log.warn "XXX PADRE after correcting ser #{sr} and #{ser} "
|
352
352
|
end
|
353
|
-
# there are some freak cases where prow or pcol comes as -1, but prefresh does not return a -1. However, this
|
353
|
+
# there are some freak cases where prow or pcol comes as -1, but prefresh does not return a -1. However, this
|
354
354
|
# could affect some other calculation somewhere.
|
355
355
|
|
356
356
|
retval = FFI::NCurses.prefresh(@pad,@prow,@pcol, sr , sc , ser , sec );
|
@@ -376,10 +376,11 @@ module Canis
|
|
376
376
|
#$log.debug "XXX: PADREFRESH #{retval} #{self.class}, #{@prow}, #{@pcol}, #{sr}, #{sc}, #{ser}, #{sec}." if retval == 0
|
377
377
|
# padrefresh can fail if width is greater than NCurses.COLS
|
378
378
|
# or if height exceeds tput lines. As long as content is less, it will work
|
379
|
-
# the moment content_rows exceeds then this issue happens.
|
379
|
+
# the moment content_rows exceeds then this issue happens.
|
380
380
|
# @rows + sr < tput lines
|
381
381
|
#FFI::NCurses.prefresh(@pad,@prow,@pcol, @startrow + top, @startcol + left, @rows + @startrow + top, @cols+@startcol + left);
|
382
382
|
end
|
383
|
+
|
383
384
|
# length of longest string in array
|
384
385
|
# This will give a 'wrong' max length if the array has ansi color escape sequences in it
|
385
386
|
# which inc the length but won't be printed. Such lines actually have less length when printed
|
@@ -390,10 +391,12 @@ module Canis
|
|
390
391
|
return 0 unless longest
|
391
392
|
longest.length
|
392
393
|
end
|
394
|
+
|
393
395
|
public
|
394
|
-
|
396
|
+
|
397
|
+
# to be called with program / user has added a row or changed column widths so that
|
395
398
|
# the pad needs to be recreated. However, cursor positioning is maintained since this
|
396
|
-
# is considered to be a minor change.
|
399
|
+
# is considered to be a minor change.
|
397
400
|
# We do not call `init_vars` since user is continuing to do some work on a row/col.
|
398
401
|
# NOTE : if height and width are changed then only render_all is required
|
399
402
|
# not a reparse since content has not changed.
|
@@ -405,7 +408,7 @@ module Canis
|
|
405
408
|
fire_handler :DIMENSION_CHANGED, _method
|
406
409
|
@__first_time = nil
|
407
410
|
end
|
408
|
-
# repaint only one row since content of that row has changed.
|
411
|
+
# repaint only one row since content of that row has changed.
|
409
412
|
# No recreate of pad is done.
|
410
413
|
def fire_row_changed ix
|
411
414
|
return if ix >= @list.length
|
@@ -414,7 +417,7 @@ module Canis
|
|
414
417
|
fire_handler :ROW_CHANGED, ix
|
415
418
|
_arr = _getarray
|
416
419
|
render @pad, ix, _arr[ix]
|
417
|
-
|
420
|
+
|
418
421
|
end
|
419
422
|
# ---- end pad related ----- }}}
|
420
423
|
# ---- Section render related ----- {{{
|
@@ -447,13 +450,13 @@ module Canis
|
|
447
450
|
# in Window and Pad stuff and perhaps include it conditionally.
|
448
451
|
|
449
452
|
|
450
|
-
# before updating a single row in a table
|
453
|
+
# before updating a single row in a table
|
451
454
|
# we need to clear the row otherwise previous contents can show through
|
452
455
|
def clear_row pad, lineno
|
453
456
|
if @renderer and @renderer.respond_to? :clear_row
|
454
457
|
@renderer.clear_row pad, lineno
|
455
458
|
else
|
456
|
-
# need pad width not window width, the other clearstring uses width of
|
459
|
+
# need pad width not window width, the other clearstring uses width of
|
457
460
|
# widget to paint on window.
|
458
461
|
@_clearstring ||= " " * @content_cols
|
459
462
|
# what about bg color ??? XXX, left_margin and internal width
|
@@ -461,7 +464,7 @@ module Canis
|
|
461
464
|
cp = @cp || FFI::NCurses.COLOR_PAIR($datacolor)
|
462
465
|
att = attr() || NORMAL
|
463
466
|
FFI::NCurses.wattron(pad,cp | att)
|
464
|
-
FFI::NCurses.mvwaddstr(pad,lineno, 0, @_clearstring)
|
467
|
+
FFI::NCurses.mvwaddstr(pad,lineno, 0, @_clearstring)
|
465
468
|
FFI::NCurses.wattroff(pad,cp | att)
|
466
469
|
end
|
467
470
|
end
|
@@ -471,7 +474,7 @@ module Canis
|
|
471
474
|
return unless @print_footer
|
472
475
|
return unless @suppress_borders
|
473
476
|
footer = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines "
|
474
|
-
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
477
|
+
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
475
478
|
=begin
|
476
479
|
if @list_footer
|
477
480
|
if false
|
@@ -480,18 +483,18 @@ module Canis
|
|
480
483
|
footer_attrib = @list_footer.config[:attrib] || Ncurses::A_REVERSE
|
481
484
|
#footer = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines "
|
482
485
|
$log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2"
|
483
|
-
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, footer_attrib)
|
486
|
+
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, footer_attrib)
|
484
487
|
end
|
485
488
|
# use default print method which only prints on left
|
486
489
|
@list_footer.print self
|
487
490
|
end
|
488
491
|
=end
|
489
|
-
@repaint_footer_required = false # 2010-01-23 22:55
|
492
|
+
@repaint_footer_required = false # 2010-01-23 22:55
|
490
493
|
end
|
491
494
|
|
492
495
|
# ---- Section render related end ----- }}}
|
493
496
|
# ---- Section data related start {{{
|
494
|
-
|
497
|
+
|
495
498
|
# supply a filename as source for textpad
|
496
499
|
# Reads up file into @list
|
497
500
|
# One can optionally send in a method which takes a filename and returns an array of data
|
@@ -553,7 +556,7 @@ module Canis
|
|
553
556
|
|
554
557
|
@document = val[0]
|
555
558
|
@document.source ||= self
|
556
|
-
@document.parse_required # added 2014-09-03 - 17:54
|
559
|
+
@document.parse_required # added 2014-09-03 - 17:54
|
557
560
|
@list = @document.text
|
558
561
|
when Array
|
559
562
|
# This is the complex case which i would like to phase out.
|
@@ -597,7 +600,7 @@ module Canis
|
|
597
600
|
|
598
601
|
@document = val
|
599
602
|
@document.source ||= self
|
600
|
-
@document.parse_required # added 2014-09-03 - 17:54
|
603
|
+
@document.parse_required # added 2014-09-03 - 17:54
|
601
604
|
@list = @document.text
|
602
605
|
end
|
603
606
|
@_populate_needed = true
|
@@ -618,8 +621,8 @@ module Canis
|
|
618
621
|
fmt = val.size == 2 ? val[1] : nil
|
619
622
|
case fmt
|
620
623
|
when Hash
|
621
|
-
#raise "textpad.text expected content_type in Hash : #{fmt}"
|
622
|
-
c = fmt[:content_type]
|
624
|
+
#raise "textpad.text expected content_type in Hash : #{fmt}"
|
625
|
+
c = fmt[:content_type]
|
623
626
|
t = fmt[:title]
|
624
627
|
@title = t if t
|
625
628
|
@content_type = c if c
|
@@ -631,11 +634,11 @@ module Canis
|
|
631
634
|
@content_type = fmt
|
632
635
|
when NilClass
|
633
636
|
else
|
634
|
-
raise "textpad.text expected symbol or content_type in Hash, got #{fmt.class} "
|
637
|
+
raise "textpad.text expected symbol or content_type in Hash, got #{fmt.class} "
|
635
638
|
end
|
636
639
|
|
637
640
|
## some programs like testlistbox which uses multibuffers calls this with a config
|
638
|
-
# in arg2 containing :content_type and :title
|
641
|
+
# in arg2 containing :content_type and :title
|
639
642
|
|
640
643
|
|
641
644
|
# added so callers can have one interface and avoid an if condition
|
@@ -708,7 +711,7 @@ module Canis
|
|
708
711
|
#@native_text[@current_index]
|
709
712
|
_getarray[@current_index]
|
710
713
|
end
|
711
|
-
## NOTE : 2014-04-09 - 14:05 i think this does not have line wise operations since we deal with
|
714
|
+
## NOTE : 2014-04-09 - 14:05 i think this does not have line wise operations since we deal with
|
712
715
|
# formatting of data
|
713
716
|
# But what if data is not formatted. This imposes a severe limitation. listbox does have linewise
|
714
717
|
# operations, so lets try them
|
@@ -723,10 +726,10 @@ module Canis
|
|
723
726
|
self
|
724
727
|
end
|
725
728
|
# @deprecated : row_count used just for compat, use length or size
|
726
|
-
def row_count ; @list.length ; end
|
729
|
+
def row_count ; @list.length ; end
|
727
730
|
|
728
731
|
## ------ LIST / ARRAY OPERATIONS ----
|
729
|
-
# All multirow widgets must use Array semantics 2014-04-10 - 17:29
|
732
|
+
# All multirow widgets must use Array semantics 2014-04-10 - 17:29
|
730
733
|
# NOTE some operations will make selected indices in selection modules invalid
|
731
734
|
# clear will need to clear indices, delete_at and insert may need to also adjust
|
732
735
|
# selection or focus index/es.
|
@@ -739,7 +742,7 @@ module Canis
|
|
739
742
|
# delegate some modify operations to Array: insert, clear, delete_at, []= <<
|
740
743
|
# However, we should check if content array is nil ?
|
741
744
|
# fire_dim is called, although it is not required in []=
|
742
|
-
%w[ insert delete_at << push].each { |e|
|
745
|
+
%w[ insert delete_at << push].each { |e|
|
743
746
|
eval %{
|
744
747
|
def #{e}(*args)
|
745
748
|
@list ||= []
|
@@ -755,7 +758,7 @@ module Canis
|
|
755
758
|
def clear
|
756
759
|
return unless @list
|
757
760
|
@list.clear
|
758
|
-
@native_text.clear if @native_text # check this line, should it be removed 2014-08-27 - 20:54
|
761
|
+
@native_text.clear if @native_text # check this line, should it be removed 2014-08-27 - 20:54
|
759
762
|
fire_dimension_changed :clear
|
760
763
|
init_vars
|
761
764
|
end
|
@@ -805,7 +808,7 @@ module Canis
|
|
805
808
|
$multiplier = 0
|
806
809
|
end
|
807
810
|
def top_of_window
|
808
|
-
@current_index = @prow
|
811
|
+
@current_index = @prow
|
809
812
|
$multiplier ||= 0
|
810
813
|
if $multiplier > 0
|
811
814
|
@current_index += $multiplier
|
@@ -884,7 +887,7 @@ module Canis
|
|
884
887
|
@prow = @current_index - @scrollatrows
|
885
888
|
end
|
886
889
|
|
887
|
-
# scrolls lines backward a window full at a time, on pressing pageup
|
890
|
+
# scrolls lines backward a window full at a time, on pressing pageup
|
888
891
|
# C-u may not work since it is trapped by form earlier. Need to fix
|
889
892
|
def scroll_backward
|
890
893
|
#@oldindex = @current_index
|
@@ -985,7 +988,7 @@ module Canis
|
|
985
988
|
# if curpos is at zero , we should be checking previous line !
|
986
989
|
$multiplier.times {
|
987
990
|
# if at start of line, go to previous line
|
988
|
-
if pos == 0
|
991
|
+
if pos == 0
|
989
992
|
if @current_index > 0
|
990
993
|
line -= 1
|
991
994
|
pos = _arr[line].to_s.size
|
@@ -1056,7 +1059,7 @@ module Canis
|
|
1056
1059
|
@curpos = _arr[@current_index].size
|
1057
1060
|
@repaint_required = true
|
1058
1061
|
end
|
1059
|
-
#
|
1062
|
+
#
|
1060
1063
|
# moves cursor to start of line, panning if required
|
1061
1064
|
def cursor_bol
|
1062
1065
|
# copy of C-a - start of line
|
@@ -1064,7 +1067,7 @@ module Canis
|
|
1064
1067
|
@pcol = 0
|
1065
1068
|
@curpos = 0
|
1066
1069
|
end
|
1067
|
-
#
|
1070
|
+
#
|
1068
1071
|
# return true if the given row is visible
|
1069
1072
|
def is_visible? index
|
1070
1073
|
j = index - @prow #@toprow
|
@@ -1117,7 +1120,7 @@ module Canis
|
|
1117
1120
|
# event when user hits ENTER on a row, user would bind :PRESS
|
1118
1121
|
# callers may use +text()+ to get the value of the row, +source+ to get parent object.
|
1119
1122
|
#
|
1120
|
-
# obj.bind :PRESS { |eve| eve.text }
|
1123
|
+
# obj.bind :PRESS { |eve| eve.text }
|
1121
1124
|
#
|
1122
1125
|
def fire_action_event
|
1123
1126
|
return if @list.nil? || @list.size == 0
|
@@ -1129,7 +1132,7 @@ module Canis
|
|
1129
1132
|
def text_action_event
|
1130
1133
|
aev = TextActionEvent.new self, :PRESS, current_value().to_s, @current_index, @curpos
|
1131
1134
|
end
|
1132
|
-
#
|
1135
|
+
#
|
1133
1136
|
# execute binding when a row is entered, used more in lists to display some text
|
1134
1137
|
# in a header or footer as one traverses
|
1135
1138
|
#
|
@@ -1137,18 +1140,15 @@ module Canis
|
|
1137
1140
|
return nil if @list.nil? || @list.size == 0
|
1138
1141
|
|
1139
1142
|
@repaint_footer_required = true
|
1140
|
-
#alert "on_enter rr #{@repaint_required}, #{@repaint_all} oi #{@oldindex}, ci #{@current_index}, or #{@oldrow} "
|
1141
1143
|
|
1142
1144
|
## can this be done once and stored, and one instance used since a lot of traversal will be done
|
1143
1145
|
require 'canis/core/include/ractionevent'
|
1144
1146
|
aev = TextActionEvent.new self, :ENTER_ROW, current_value().to_s, @current_index, @curpos
|
1145
1147
|
fire_handler :ENTER_ROW, aev
|
1146
|
-
#@repaint_required = true
|
1147
1148
|
end
|
1148
1149
|
|
1149
1150
|
#
|
1150
1151
|
# called when this widget is entered, by form
|
1151
|
-
# 2014-05-27 - 17:02 we were not calling super, so :ENTER was not triggered !!!
|
1152
1152
|
def on_enter
|
1153
1153
|
super
|
1154
1154
|
set_form_row
|
@@ -1161,11 +1161,6 @@ module Canis
|
|
1161
1161
|
def set_form_col
|
1162
1162
|
end
|
1163
1163
|
|
1164
|
-
private
|
1165
|
-
|
1166
|
-
# check that current_index and prow are within correct ranges
|
1167
|
-
# sets row (and someday col too)
|
1168
|
-
# sets repaint_required
|
1169
1164
|
|
1170
1165
|
public
|
1171
1166
|
def bounds_check
|
@@ -1198,7 +1193,7 @@ module Canis
|
|
1198
1193
|
@repaint_required = true
|
1199
1194
|
end
|
1200
1195
|
end
|
1201
|
-
#
|
1196
|
+
#
|
1202
1197
|
# save last cursor position so when reentering, cursor can be repositioned
|
1203
1198
|
def lastcurpos r,c
|
1204
1199
|
@lastrow = r
|
@@ -1228,7 +1223,7 @@ module Canis
|
|
1228
1223
|
#$log.debug " check_prow after prow #{@prow} , list count #{cc} "
|
1229
1224
|
# we still need to check the max that prow can go otherwise
|
1230
1225
|
# the pad shows earlier stuff.
|
1231
|
-
#
|
1226
|
+
#
|
1232
1227
|
return
|
1233
1228
|
end
|
1234
1229
|
public
|
@@ -1237,7 +1232,7 @@ module Canis
|
|
1237
1232
|
__calc_dimensions
|
1238
1233
|
@__first_time = true
|
1239
1234
|
end
|
1240
|
-
return unless @list # trying out since it goes into padrefresh even when no data 2014-04-10 - 00:32
|
1235
|
+
return unless @list # trying out since it goes into padrefresh even when no data 2014-04-10 - 00:32
|
1241
1236
|
@graphic = @form.window unless @graphic
|
1242
1237
|
@window ||= @graphic
|
1243
1238
|
raise "Window not set in textpad" unless @window
|
@@ -1253,16 +1248,16 @@ module Canis
|
|
1253
1248
|
#$log.debug " repaint textpad RR #{@repaint_required} #{@window.top} "
|
1254
1249
|
unless @repaint_required
|
1255
1250
|
print_foot if @repaint_footer_required # set in on_enter_row
|
1256
|
-
# trying out removing this, since too many refreshes 2014-05-01 - 12:45
|
1257
|
-
#padrefresh
|
1258
|
-
return
|
1251
|
+
# trying out removing this, since too many refreshes 2014-05-01 - 12:45
|
1252
|
+
#padrefresh
|
1253
|
+
return
|
1259
1254
|
end
|
1260
|
-
# if repaint is required, print_foot not called. unless repaint_all is set, and that
|
1255
|
+
# if repaint is required, print_foot not called. unless repaint_all is set, and that
|
1261
1256
|
# is rarely set.
|
1262
|
-
|
1257
|
+
|
1263
1258
|
preprocess_text
|
1264
1259
|
|
1265
|
-
# in textdialog, @window was nil going into create_pad 2014-04-15 - 01:28
|
1260
|
+
# in textdialog, @window was nil going into create_pad 2014-04-15 - 01:28
|
1266
1261
|
|
1267
1262
|
# creates pad and calls render_all
|
1268
1263
|
populate_pad if !@pad or @_populate_needed
|
@@ -1295,8 +1290,8 @@ module Canis
|
|
1295
1290
|
@window.print_border_only @top, @left, @height-1, @width, clr
|
1296
1291
|
print_title
|
1297
1292
|
|
1298
|
-
# oldrow changed to oldindex 2014-04-13 - 16:55
|
1299
|
-
@repaint_footer_required = true if @oldindex != @current_index
|
1293
|
+
# oldrow changed to oldindex 2014-04-13 - 16:55
|
1294
|
+
@repaint_footer_required = true if @oldindex != @current_index
|
1300
1295
|
print_foot if @print_footer && !@suppress_borders && @repaint_footer_required
|
1301
1296
|
|
1302
1297
|
@window.wrefresh
|
@@ -1314,15 +1309,15 @@ module Canis
|
|
1314
1309
|
bindings
|
1315
1310
|
=begin
|
1316
1311
|
bind_key([?g,?g], 'goto_start'){ goto_start } # mapping double keys like vim
|
1317
|
-
bind_key(279, 'goto_start'){ goto_start }
|
1318
|
-
bind_keys([?G,277], 'goto end'){ goto_end }
|
1319
|
-
bind_keys([?k,KEY_UP], "Up"){ up }
|
1320
|
-
bind_keys([?j,KEY_DOWN], "Down"){ down }
|
1321
|
-
bind_key(?\C-e, "Scroll Window Down"){ scroll_window_down }
|
1322
|
-
bind_key(?\C-y, "Scroll Window Up"){ scroll_window_up }
|
1323
|
-
bind_keys([32,338, ?\C-d], "Scroll Forward"){ scroll_forward }
|
1324
|
-
# adding CTRL_SPACE as back scroll 2014-04-14
|
1325
|
-
bind_keys([0,?\C-b,339], "Scroll Backward"){ scroll_backward }
|
1312
|
+
bind_key(279, 'goto_start'){ goto_start }
|
1313
|
+
bind_keys([?G,277], 'goto end'){ goto_end }
|
1314
|
+
bind_keys([?k,KEY_UP], "Up"){ up }
|
1315
|
+
bind_keys([?j,KEY_DOWN], "Down"){ down }
|
1316
|
+
bind_key(?\C-e, "Scroll Window Down"){ scroll_window_down }
|
1317
|
+
bind_key(?\C-y, "Scroll Window Up"){ scroll_window_up }
|
1318
|
+
bind_keys([32,338, ?\C-d], "Scroll Forward"){ scroll_forward }
|
1319
|
+
# adding CTRL_SPACE as back scroll 2014-04-14
|
1320
|
+
bind_keys([0,?\C-b,339], "Scroll Backward"){ scroll_backward }
|
1326
1321
|
# the next one invalidates the single-quote binding for bookmarks
|
1327
1322
|
#bind_key([?',?']){ goto_last_position } # vim , goto last row position (not column)
|
1328
1323
|
bind_key(?/, :ask_search)
|
@@ -1351,7 +1346,7 @@ module Canis
|
|
1351
1346
|
# ----------- end internal stuff --------------- }}}
|
1352
1347
|
public
|
1353
1348
|
# ---- Section search related start ----- {{{
|
1354
|
-
##
|
1349
|
+
##
|
1355
1350
|
# Ask user for string to search for
|
1356
1351
|
# This uses the dialog, but what if user wants the old style.
|
1357
1352
|
# Isn't there a cleaner way to let user override style, or allow user
|
@@ -1363,7 +1358,7 @@ module Canis
|
|
1363
1358
|
# the following is a change that enables callers to prompt for the string
|
1364
1359
|
# using some other style, basically the classical style and send the string in
|
1365
1360
|
str = get_string("Enter pattern: ", :title => "Find pattern") unless str
|
1366
|
-
return if str.nil?
|
1361
|
+
return if str.nil?
|
1367
1362
|
str = @last_regex if str == ""
|
1368
1363
|
return if !str or str == ""
|
1369
1364
|
str = Regexp.new str if str.is_a? String
|
@@ -1376,7 +1371,7 @@ module Canis
|
|
1376
1371
|
@curpos = ix[1]
|
1377
1372
|
ensure_visible
|
1378
1373
|
end
|
1379
|
-
##
|
1374
|
+
##
|
1380
1375
|
# Find next matching row for string accepted in ask_search
|
1381
1376
|
#
|
1382
1377
|
def find_more
|
@@ -1389,7 +1384,7 @@ module Canis
|
|
1389
1384
|
ensure_visible
|
1390
1385
|
end
|
1391
1386
|
|
1392
|
-
##
|
1387
|
+
##
|
1393
1388
|
# Find the next row that contains given string
|
1394
1389
|
# @return row and col offset of match, or nil
|
1395
1390
|
# FIXME: 2014-05-26 - 01:26 currently if there are two matches in a row skips the second
|
@@ -1429,7 +1424,7 @@ module Canis
|
|
1429
1424
|
# NOTE:
|
1430
1425
|
# startline and endline are more for internal purposes, externally we would call this only with
|
1431
1426
|
# the pattern.
|
1432
|
-
# @example
|
1427
|
+
# @example
|
1433
1428
|
# pos = next_match /abc/
|
1434
1429
|
# # pos is nil or [line, col]
|
1435
1430
|
#
|
@@ -1448,7 +1443,7 @@ module Canis
|
|
1448
1443
|
_line = to_searchable(startline)
|
1449
1444
|
_col = _line.index(str, pos) if _line
|
1450
1445
|
if _col
|
1451
|
-
return [startline, _col]
|
1446
|
+
return [startline, _col]
|
1452
1447
|
end
|
1453
1448
|
startline += 1 # FIXME check this end of file
|
1454
1449
|
end
|
@@ -1485,10 +1480,10 @@ module Canis
|
|
1485
1480
|
def to_searchable index
|
1486
1481
|
_getarray[index].to_s
|
1487
1482
|
end
|
1488
|
-
##
|
1483
|
+
##
|
1489
1484
|
# Ensure current row is visible, if not make it first row
|
1490
1485
|
# NOTE - need to check if its at end and then reduce scroll at rows, check_prow does that
|
1491
|
-
#
|
1486
|
+
#
|
1492
1487
|
# @param current_index (default if not given)
|
1493
1488
|
#
|
1494
1489
|
def ensure_visible row = @current_index
|
@@ -1502,7 +1497,7 @@ module Canis
|
|
1502
1497
|
# where the current index is actually being displayed (example if it wishes to display
|
1503
1498
|
# a popup at that row)
|
1504
1499
|
# An argument is not being taken since the index should be visible.
|
1505
|
-
def visual_index
|
1500
|
+
def visual_index
|
1506
1501
|
row = @current_index
|
1507
1502
|
row - @prow
|
1508
1503
|
end
|
@@ -1517,7 +1512,7 @@ module Canis
|
|
1517
1512
|
#
|
1518
1513
|
# This was just indicative, and is not used anywhere
|
1519
1514
|
def DEADhighlight_row index = @current_index, cfg={}
|
1520
|
-
return unless index
|
1515
|
+
return unless index
|
1521
1516
|
c = 0 # we are using pads so no col except for left_margin if present
|
1522
1517
|
# in a pad we don't need to convert index to printable
|
1523
1518
|
r = index
|
@@ -1530,7 +1525,7 @@ module Canis
|
|
1530
1525
|
end
|
1531
1526
|
##---- dead unused }}}
|
1532
1527
|
|
1533
|
-
end # class textpad
|
1528
|
+
end # class textpad
|
1534
1529
|
|
1535
1530
|
# renderer {{{
|
1536
1531
|
# Very basic renderer that only prints based on color pair of the textpad
|
@@ -1540,7 +1535,7 @@ module Canis
|
|
1540
1535
|
# content cols is the width in columns of pad
|
1541
1536
|
# list is the data array
|
1542
1537
|
attr_accessor :content_cols, :list
|
1543
|
-
# the widget this is associated with.
|
1538
|
+
# the widget this is associated with.
|
1544
1539
|
attr_accessor :source
|
1545
1540
|
|
1546
1541
|
def initialize source=nil
|
@@ -1558,7 +1553,7 @@ module Canis
|
|
1558
1553
|
alias :update_colors :pre_render
|
1559
1554
|
|
1560
1555
|
# derived classes may choose to override this.
|
1561
|
-
# However, they should set size and color and attrib at the start since these
|
1556
|
+
# However, they should set size and color and attrib at the start since these
|
1562
1557
|
# can change after the object has been created depending on the application.
|
1563
1558
|
def render_all pad, arr
|
1564
1559
|
pre_render
|
@@ -1609,7 +1604,7 @@ module Canis
|
|
1609
1604
|
end
|
1610
1605
|
# renderer }}}
|
1611
1606
|
# This is the default key handler.
|
1612
|
-
# It takes care of catching numbers so that vim's movement can use numeric args.
|
1607
|
+
# It takes care of catching numbers so that vim's movement can use numeric args.
|
1613
1608
|
# That is taken care of by multiplier. Other than that it has the key_map process the key.
|
1614
1609
|
#
|
1615
1610
|
class DefaultKeyHandler # ---- {{{
|
@@ -1649,10 +1644,10 @@ module Canis
|
|
1649
1644
|
end
|
1650
1645
|
# --- NOTE ABOUT BLACK RECT LEFT on SCREEN {{{
|
1651
1646
|
## NOTE if textpad does not handle the event and it goes to form which pops
|
1652
|
-
# up a messagebox, then padrefresh does not happen, since control does not
|
1647
|
+
# up a messagebox, then padrefresh does not happen, since control does not
|
1653
1648
|
# come back here, so a black rect is left on screen
|
1654
|
-
# please note that a bounds check will not happen for stuff that
|
1655
|
-
# is triggered by form, so you'll have to to it yourself or
|
1649
|
+
# please note that a bounds check will not happen for stuff that
|
1650
|
+
# is triggered by form, so you'll have to to it yourself or
|
1656
1651
|
# call setrowcol explicity if the cursor is not updated
|
1657
1652
|
# --- }}}
|
1658
1653
|
|
data/lib/canis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kepler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -220,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
- !ruby/object:Gem::Version
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
|
-
|
224
|
-
rubygems_version: 2.7.6
|
223
|
+
rubygems_version: 3.0.2
|
225
224
|
signing_key:
|
226
225
|
specification_version: 4
|
227
226
|
summary: ruby ncurses library for easy application development
|