rndk 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
data/lib/rndk/template.rb
CHANGED
@@ -1,21 +1,41 @@
|
|
1
1
|
require 'rndk'
|
2
2
|
|
3
3
|
module RNDK
|
4
|
-
class
|
5
|
-
def initialize(
|
6
|
-
overlay, box, shadow)
|
4
|
+
class Template < Widget
|
5
|
+
def initialize(screen, config={})
|
7
6
|
super()
|
8
|
-
|
9
|
-
|
7
|
+
@widget_type = :template
|
8
|
+
@supported_signals += [:before_input, :after_input]
|
9
|
+
|
10
|
+
x = 0
|
11
|
+
y = 0
|
12
|
+
title = "template"
|
13
|
+
label = "label"
|
14
|
+
plate = "##/##/####"
|
15
|
+
overlay = "dd/mm/yyyy"
|
16
|
+
box = true
|
17
|
+
shadow = false
|
18
|
+
|
19
|
+
config.each do |key, val|
|
20
|
+
x = val if key == :x
|
21
|
+
y = val if key == :y
|
22
|
+
title = val if key == :title
|
23
|
+
label = val if key == :label
|
24
|
+
plate = val if key == :plate
|
25
|
+
overlay = val if key == :overlay
|
26
|
+
box = val if key == :box
|
27
|
+
shadow = val if key == :shadow
|
28
|
+
end
|
29
|
+
|
30
|
+
parent_width = Ncurses.getmaxx(screen.window)
|
31
|
+
parent_height = Ncurses.getmaxy(screen.window)
|
10
32
|
box_width = 0
|
11
33
|
box_height = if box then 3 else 1 end
|
12
34
|
plate_len = 0
|
13
35
|
|
14
|
-
if plate.nil? || plate.size == 0
|
15
|
-
return nil
|
16
|
-
end
|
36
|
+
return nil if plate.nil? || plate.size == 0
|
17
37
|
|
18
|
-
self.set_box
|
38
|
+
self.set_box box
|
19
39
|
|
20
40
|
field_width = plate.size + 2 * @border_size
|
21
41
|
|
@@ -36,11 +56,11 @@ module RNDK
|
|
36
56
|
overlay_len = []
|
37
57
|
@overlay = RNDK.char2Chtype(overlay, overlay_len, [])
|
38
58
|
@overlay_len = overlay_len[0]
|
39
|
-
@field_attr = @overlay[0] &
|
59
|
+
@field_attr = @overlay[0] & RNDK::Color[:extract]
|
40
60
|
else
|
41
61
|
@overlay = []
|
42
62
|
@overlay_len = 0
|
43
|
-
@field_attr =
|
63
|
+
@field_attr = RNDK::Color[:normal]
|
44
64
|
end
|
45
65
|
|
46
66
|
# Set the box width.
|
@@ -59,9 +79,9 @@ module RNDK
|
|
59
79
|
box_width - @label_len - 2 * @border_size].min
|
60
80
|
|
61
81
|
# Rejustify the x and y positions if we need to.
|
62
|
-
xtmp = [
|
63
|
-
ytmp = [
|
64
|
-
RNDK.alignxy(
|
82
|
+
xtmp = [x]
|
83
|
+
ytmp = [y]
|
84
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, box_width, box_height)
|
65
85
|
xpos = xtmp[0]
|
66
86
|
ypos = ytmp[0]
|
67
87
|
|
@@ -95,8 +115,8 @@ module RNDK
|
|
95
115
|
@plate = plate.clone
|
96
116
|
|
97
117
|
# Set up the rest of the structure.
|
98
|
-
@screen =
|
99
|
-
@parent =
|
118
|
+
@screen = screen
|
119
|
+
@parent = screen.window
|
100
120
|
@shadow_win = nil
|
101
121
|
@field_width = field_width
|
102
122
|
@box_height = box_height
|
@@ -161,7 +181,7 @@ module RNDK
|
|
161
181
|
end
|
162
182
|
|
163
183
|
if change
|
164
|
-
if self.
|
184
|
+
if self.valid_template? test
|
165
185
|
@info = test
|
166
186
|
self.drawField
|
167
187
|
else
|
@@ -187,16 +207,16 @@ module RNDK
|
|
187
207
|
ypos + 1, xpos + 1)
|
188
208
|
end
|
189
209
|
|
190
|
-
|
210
|
+
screen.register(@widget_type, self)
|
191
211
|
end
|
192
212
|
|
193
213
|
# This actually manages the tempalte widget
|
194
|
-
def activate(actions)
|
195
|
-
self.draw
|
214
|
+
def activate(actions=[])
|
215
|
+
self.draw
|
196
216
|
|
197
217
|
if actions.nil? || actions.size == 0
|
198
218
|
while true
|
199
|
-
input = self.getch
|
219
|
+
input = self.getch
|
200
220
|
|
201
221
|
# Inject each character into the widget.
|
202
222
|
ret = self.inject(input)
|
@@ -220,10 +240,10 @@ module RNDK
|
|
220
240
|
end
|
221
241
|
|
222
242
|
# This injects a character into the widget.
|
223
|
-
def inject
|
224
|
-
pp_return =
|
243
|
+
def inject input
|
244
|
+
pp_return = true
|
225
245
|
complete = false
|
226
|
-
ret =
|
246
|
+
ret = false
|
227
247
|
|
228
248
|
self.set_exit_type(0)
|
229
249
|
|
@@ -231,16 +251,14 @@ module RNDK
|
|
231
251
|
self.drawField
|
232
252
|
|
233
253
|
# Check if there is a pre-process function to be called.
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
254
|
+
keep_going = self.run_signal_binding(:before_input, input)
|
255
|
+
|
256
|
+
if keep_going
|
238
257
|
|
239
|
-
# Should we continue?
|
240
|
-
if pp_return != 0
|
241
258
|
# Check a predefined binding
|
242
|
-
if self.
|
243
|
-
|
259
|
+
if self.is_bound? input
|
260
|
+
self.run_key_binding input
|
261
|
+
#complete = true
|
244
262
|
else
|
245
263
|
case input
|
246
264
|
when RNDK::ERASE
|
@@ -296,26 +314,22 @@ module RNDK
|
|
296
314
|
end
|
297
315
|
end
|
298
316
|
|
299
|
-
|
300
|
-
if !complete && !(@post_process_func.nil?)
|
301
|
-
@post_process_func.call(:TEMPLATE, self, @post_process_data, input)
|
302
|
-
end
|
317
|
+
self.run_signal_binding(:after_input) if not complete
|
303
318
|
end
|
304
319
|
|
305
|
-
if !complete
|
306
|
-
self.set_exit_type(0)
|
307
|
-
end
|
308
320
|
|
321
|
+
self.set_exit_type(0) if not complete
|
309
322
|
@return_data = ret
|
310
|
-
|
323
|
+
|
324
|
+
ret
|
311
325
|
end
|
312
326
|
|
313
|
-
def
|
327
|
+
def valid_template? input
|
314
328
|
pp = 0
|
315
329
|
ip = 0
|
316
330
|
while ip < input.size && pp < @plate.size
|
317
331
|
newchar = input[ip]
|
318
|
-
while pp < @plate.size && !RNDK::
|
332
|
+
while pp < @plate.size && !RNDK::Template.isPlateChar(@plate[pp])
|
319
333
|
pp += 1
|
320
334
|
end
|
321
335
|
if pp == @plate.size
|
@@ -352,7 +366,7 @@ module RNDK
|
|
352
366
|
if @info.size > 0
|
353
367
|
mixed_string = ''
|
354
368
|
while plate_pos < @plate_len && info_pos < @info.size
|
355
|
-
mixed_string << if RNDK::
|
369
|
+
mixed_string << if RNDK::Template.isPlateChar(@plate[plate_pos])
|
356
370
|
then info_pos += 1; @info[info_pos - 1]
|
357
371
|
else @plate[plate_pos]
|
358
372
|
end
|
@@ -369,7 +383,7 @@ module RNDK
|
|
369
383
|
unmixed_string = ''
|
370
384
|
|
371
385
|
while pos < @info.size
|
372
|
-
if RNDK::
|
386
|
+
if RNDK::Template.isPlateChar(@plate[pos])
|
373
387
|
unmixed_string << info[pos]
|
374
388
|
end
|
375
389
|
pos += 1
|
@@ -379,9 +393,9 @@ module RNDK
|
|
379
393
|
end
|
380
394
|
|
381
395
|
# Move the template field to the given location.
|
382
|
-
def move(
|
396
|
+
def move(x, y, relative, refresh_flag)
|
383
397
|
windows = [@win, @label_win, @field_win, @shadow_win]
|
384
|
-
self.move_specific(
|
398
|
+
self.move_specific(x, y, relative, refresh_flag,
|
385
399
|
windows, [])
|
386
400
|
end
|
387
401
|
|
@@ -397,7 +411,7 @@ module RNDK
|
|
397
411
|
Draw.drawObjBox(@win, self)
|
398
412
|
end
|
399
413
|
|
400
|
-
self.
|
414
|
+
self.draw_title(@win)
|
401
415
|
|
402
416
|
Ncurses.wrefresh @win
|
403
417
|
|
@@ -408,7 +422,7 @@ module RNDK
|
|
408
422
|
def drawField
|
409
423
|
field_color = 0
|
410
424
|
|
411
|
-
# Draw in the label and the template
|
425
|
+
# Draw in the label and the template widget.
|
412
426
|
unless @label_win.nil?
|
413
427
|
Draw.writeChtype(@label_win, 0, 0, @label, RNDK::HORIZONTAL,
|
414
428
|
0, @label_len)
|
@@ -425,8 +439,8 @@ module RNDK
|
|
425
439
|
if @info.size > 0
|
426
440
|
pos = 0
|
427
441
|
(0...[@field_width, @plate.size].min).each do |x|
|
428
|
-
if RNDK::
|
429
|
-
field_color = @overlay[x] &
|
442
|
+
if RNDK::Template.isPlateChar(@plate[x]) && pos < @info.size
|
443
|
+
field_color = @overlay[x] & RNDK::Color[:extract]
|
430
444
|
Ncurses.mvwaddch(@field_win, 0, x, @info[pos].ord | field_color)
|
431
445
|
pos += 1
|
432
446
|
end
|
@@ -441,7 +455,7 @@ module RNDK
|
|
441
455
|
# Adjust the cursor for the template
|
442
456
|
def adjustCursor(direction)
|
443
457
|
while @plate_pos < [@field_width, @plate.size].min &&
|
444
|
-
!RNDK::
|
458
|
+
!RNDK::Template.isPlateChar(@plate[@plate_pos])
|
445
459
|
@plate_pos += direction
|
446
460
|
@screen_pos += direction
|
447
461
|
end
|
@@ -450,7 +464,7 @@ module RNDK
|
|
450
464
|
end
|
451
465
|
|
452
466
|
# Set the background attribute of the widget.
|
453
|
-
def
|
467
|
+
def set_bg_color(attrib)
|
454
468
|
Ncurses.wbkgd(@win, attrib)
|
455
469
|
Ncurses.wbkgd(@field_win, attrib)
|
456
470
|
Ncurses.wbkgd(@label_win, attrib) unless @label_win.nil?
|
@@ -458,7 +472,7 @@ module RNDK
|
|
458
472
|
|
459
473
|
# Destroy this widget.
|
460
474
|
def destroy
|
461
|
-
self.
|
475
|
+
self.clean_title
|
462
476
|
|
463
477
|
# Delete the windows
|
464
478
|
RNDK.window_delete(@field_win)
|
@@ -467,14 +481,14 @@ module RNDK
|
|
467
481
|
RNDK.window_delete(@win)
|
468
482
|
|
469
483
|
# Clean the key bindings.
|
470
|
-
self.clean_bindings
|
484
|
+
self.clean_bindings
|
471
485
|
|
472
|
-
|
486
|
+
@screen.unregister self
|
473
487
|
end
|
474
488
|
|
475
489
|
# Erase the widget.
|
476
490
|
def erase
|
477
|
-
if self.
|
491
|
+
if self.valid?
|
478
492
|
RNDK.window_erase(@field_win)
|
479
493
|
RNDK.window_erase(@label_win)
|
480
494
|
RNDK.window_erase(@shadow_win)
|
@@ -538,11 +552,11 @@ module RNDK
|
|
538
552
|
end
|
539
553
|
|
540
554
|
def focus
|
541
|
-
self.draw
|
555
|
+
self.draw
|
542
556
|
end
|
543
557
|
|
544
558
|
def unfocus
|
545
|
-
self.draw
|
559
|
+
self.draw
|
546
560
|
end
|
547
561
|
|
548
562
|
def self.isPlateChar(c)
|
@@ -553,8 +567,7 @@ module RNDK
|
|
553
567
|
super(@win)
|
554
568
|
end
|
555
569
|
|
556
|
-
|
557
|
-
|
558
|
-
end
|
570
|
+
|
571
|
+
|
559
572
|
end
|
560
573
|
end
|
data/lib/rndk/version.rb
CHANGED
data/lib/rndk/viewer.rb
CHANGED
@@ -1,41 +1,144 @@
|
|
1
1
|
require 'rndk'
|
2
|
+
require 'rndk/label'
|
3
|
+
require 'rndk/entry'
|
2
4
|
|
3
5
|
module RNDK
|
4
|
-
class VIEWER < Widget
|
5
|
-
DOWN = 0
|
6
|
-
UP = 1
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
# Shows a list of lines with lots of fancy things.
|
8
|
+
# Generally used to view files, has Buttons, Label and Entry.
|
9
|
+
#
|
10
|
+
# ## Example
|
11
|
+
#
|
12
|
+
# ```
|
13
|
+
# viewer = RNDK::Viewer.new(screen, {
|
14
|
+
# :x => RNDK::CENTER,
|
15
|
+
# :y => RNDK::CENTER,
|
16
|
+
# :title => "</77>Awesome Viewer",
|
17
|
+
# :buttons => buttons,
|
18
|
+
# :shadow => true
|
19
|
+
# })
|
20
|
+
#
|
21
|
+
# # To set the lines of Viewer we must use Viewer#set.
|
22
|
+
# # No way to do it on the constructor :(
|
23
|
+
# viewer.set :items => lines
|
24
|
+
# ```
|
25
|
+
#
|
26
|
+
# ## Keybindings
|
27
|
+
#
|
28
|
+
# Left Arrow:: Shifts the viewport one column left.
|
29
|
+
# Right Arrow:: Shifts the viewport one column left
|
30
|
+
# Up Arrow:: Scrolls the viewport one line up.
|
31
|
+
# Down Arrow:: Scrolls the viewport one line down.
|
32
|
+
# Prev Page:: Scroll one page backward.
|
33
|
+
# Ctrl-B:: Scroll one page backward.
|
34
|
+
# B:: Scroll one page backward.
|
35
|
+
# b:: Scroll one page backward.
|
36
|
+
# Next Page:: Scroll one page forward.
|
37
|
+
# Ctrl-F:: Scroll one page forward.
|
38
|
+
# Space:: Scroll one page forward.
|
39
|
+
# F:: Scroll one page forward.
|
40
|
+
# f:: Scroll one page forward.
|
41
|
+
# Home:: Shift the whole list to the far left.
|
42
|
+
# |:: Shift the whole list to the far left.
|
43
|
+
# End:: Shift the whole list to the far right.
|
44
|
+
# $:: Shift the whole list to the far right.
|
45
|
+
# 1:: Moves to the first line in the viewer.
|
46
|
+
# <:: Moves to the first line in the viewer.
|
47
|
+
# g:: Moves to the first line in the viewer.
|
48
|
+
# >:: Moves to the last line in the viewer.
|
49
|
+
# G:: Moves to the last line in the viewer.
|
50
|
+
# L:: Moves half the distance to the end of the viewer.
|
51
|
+
# l:: Moves half the distance to the top of the viewer.
|
52
|
+
# ?:: Searches up for a pattern.
|
53
|
+
# /:: Searches down for a pattern.
|
54
|
+
# n:: Repeats last search.
|
55
|
+
# N:: Repeats last search, reversed direction.
|
56
|
+
# ::: Jumps to a given line.
|
57
|
+
# i:: Displays file statistics.
|
58
|
+
# s:: Displays file statistics.
|
59
|
+
# Tab:: Switches buttons.
|
60
|
+
# Return:: Exit the widget and return the index of the selected button. Set `exit_type` to `:NORMAL`.
|
61
|
+
# Escape:: Exit the widget and return -1. Set `exit_type` to `:ESCAPE_HIT`.
|
62
|
+
# Ctrl-L:: Refreshes the screen.
|
63
|
+
#
|
64
|
+
#
|
65
|
+
# TODO There's something wrong with this widget
|
66
|
+
# why wont it work with Traverse?
|
67
|
+
class Viewer < Widget
|
68
|
+
|
69
|
+
DOWN = 0
|
70
|
+
UP = 1
|
71
|
+
|
72
|
+
# Creates a new Viewer Widget.
|
73
|
+
#
|
74
|
+
# ## Settings
|
75
|
+
#
|
76
|
+
# * `x` is the x position - can be an integer or
|
77
|
+
# `RNDK::LEFT`, `RNDK::RIGHT`, `RNDK::CENTER`.
|
78
|
+
# * `y` is the y position - can be an integer or
|
79
|
+
# `RNDK::TOP`, `RNDK::BOTTOM`, `RNDK::CENTER`.
|
80
|
+
# * `width`/`height` are integers - if either are 0, Widget
|
81
|
+
# will be created with full width/height of the screen.
|
82
|
+
# If it's a negative value, will create with full width/height
|
83
|
+
# minus the value.
|
84
|
+
# * `title` can be more than one line - just split them
|
85
|
+
# with `\n`s.
|
86
|
+
# * `buttons` is an Array of Strings with all buttons.
|
87
|
+
#
|
88
|
+
# @todo complete documentation
|
89
|
+
#
|
90
|
+
# @note To set the data inside Viewer, you _must_ call
|
91
|
+
# Viewer#set! No stuffin' things on the constructor.
|
92
|
+
#
|
93
|
+
def initialize(screen, config={})
|
10
94
|
super()
|
11
|
-
|
12
|
-
|
13
|
-
|
95
|
+
@widget_type = :viewer
|
96
|
+
@supported_signals += [:before_input, :after_input]
|
97
|
+
|
98
|
+
# This is UGLY AS HELL
|
99
|
+
# But I don't have time to clean this up right now
|
100
|
+
# (lots of widgets, you know) :(
|
101
|
+
x = 0
|
102
|
+
y = 0
|
103
|
+
width = 0
|
104
|
+
height = 0
|
105
|
+
title = "viewer"
|
106
|
+
buttons = []
|
107
|
+
button_highlight = RNDK::Color[:reverse]
|
108
|
+
box = true
|
109
|
+
shadow = false
|
110
|
+
|
111
|
+
config.each do |key, val|
|
112
|
+
x = val if key == :x
|
113
|
+
y = val if key == :y
|
114
|
+
width = val if key == :width
|
115
|
+
height = val if key == :height
|
116
|
+
title = val if key == :title
|
117
|
+
buttons = val if key == :buttons
|
118
|
+
button_highlight = val if key == :button_highlight
|
119
|
+
box = val if key == :box
|
120
|
+
shadow = val if key == :shadow
|
121
|
+
end
|
122
|
+
|
123
|
+
parent_width = Ncurses.getmaxx screen.window
|
124
|
+
parent_height = Ncurses.getmaxy screen.window
|
125
|
+
|
126
|
+
box_width = width
|
14
127
|
box_height = height
|
128
|
+
|
15
129
|
button_width = 0
|
16
130
|
button_adj = 0
|
17
131
|
button_pos = 1
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
' ' => Ncurses::KEY_NPAGE,
|
24
|
-
'f' => Ncurses::KEY_NPAGE,
|
25
|
-
'F' => Ncurses::KEY_NPAGE,
|
26
|
-
'|' => Ncurses::KEY_HOME,
|
27
|
-
'$' => Ncurses::KEY_END,
|
28
|
-
}
|
29
|
-
|
30
|
-
self.set_box(box)
|
31
|
-
|
32
|
-
box_height = RNDK.setWidgetDimension(parent_height, height, 0)
|
33
|
-
box_width = RNDK.setWidgetDimension(parent_width, width, 0)
|
132
|
+
|
133
|
+
self.set_box box
|
134
|
+
|
135
|
+
box_width = RNDK.set_widget_dimension(parent_width, width, 0)
|
136
|
+
box_height = RNDK.set_widget_dimension(parent_height, height, 0)
|
34
137
|
|
35
138
|
# Rejustify the x and y positions if we need to.
|
36
|
-
xtmp = [
|
37
|
-
ytmp = [
|
38
|
-
RNDK.alignxy(
|
139
|
+
xtmp = [x]
|
140
|
+
ytmp = [y]
|
141
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, box_width, box_height)
|
39
142
|
xpos = xtmp[0]
|
40
143
|
ypos = ytmp[0]
|
41
144
|
|
@@ -50,28 +153,29 @@ module RNDK
|
|
50
153
|
Ncurses.keypad(@win, true)
|
51
154
|
|
52
155
|
# Create the buttons.
|
53
|
-
@button_count =
|
156
|
+
@button_count = buttons.size
|
54
157
|
@button = []
|
55
158
|
@button_len = []
|
56
159
|
@button_pos = []
|
57
|
-
|
58
|
-
|
160
|
+
|
161
|
+
if @button_count > 0
|
162
|
+
(0...@button_count).each do |x|
|
59
163
|
button_len = []
|
60
164
|
@button << RNDK.char2Chtype(buttons[x], button_len, [])
|
61
165
|
@button_len << button_len[0]
|
62
166
|
button_width += @button_len[x] + 1
|
63
167
|
end
|
64
|
-
button_adj = (box_width - button_width) / (button_count + 1)
|
168
|
+
button_adj = (box_width - button_width) / (@button_count + 1)
|
65
169
|
button_pos = 1 + button_adj
|
66
|
-
(0
|
170
|
+
(0...@button_count).each do |x|
|
67
171
|
@button_pos << button_pos
|
68
172
|
button_pos += button_adj + @button_len[x]
|
69
173
|
end
|
70
174
|
end
|
71
175
|
|
72
176
|
# Set the rest of the variables.
|
73
|
-
@screen =
|
74
|
-
@parent =
|
177
|
+
@screen = screen
|
178
|
+
@parent = screen.window
|
75
179
|
@shadow_win = nil
|
76
180
|
@button_highlight = button_highlight
|
77
181
|
@box_height = box_height
|
@@ -86,10 +190,14 @@ module RNDK
|
|
86
190
|
@max_left_char = 0
|
87
191
|
@max_top_line = 0
|
88
192
|
@characters = 0
|
89
|
-
@
|
90
|
-
@
|
193
|
+
@items_size = -1
|
194
|
+
@show_line_items = 1
|
91
195
|
@exit_type = :EARLY_EXIT
|
92
196
|
|
197
|
+
@search_pattern = []
|
198
|
+
|
199
|
+
self.set_title title
|
200
|
+
|
93
201
|
# Do we need to create a shadow?
|
94
202
|
if shadow
|
95
203
|
@shadow_win = Ncurses.newwin(box_height,
|
@@ -103,26 +211,53 @@ module RNDK
|
|
103
211
|
end
|
104
212
|
|
105
213
|
# Setup the key bindings.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
214
|
+
self.bind_key('b') { self.scroll_page_up }
|
215
|
+
self.bind_key('B') { self.scroll_page_up }
|
216
|
+
self.bind_key(' ') { self.scroll_page_down }
|
217
|
+
self.bind_key('f') { self.scroll_page_down }
|
218
|
+
self.bind_key('F') { self.scroll_page_down }
|
219
|
+
self.bind_key('|') { self.scroll_begin }
|
220
|
+
self.bind_key('$') { self.scroll_end }
|
221
|
+
|
222
|
+
screen.register(@widget_type, self)
|
111
223
|
end
|
112
224
|
|
113
225
|
# This function sets various attributes of the widget.
|
114
|
-
def set(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
226
|
+
def set(config)
|
227
|
+
items = @items
|
228
|
+
hide_control_chars = @hide_control_chars
|
229
|
+
show_line_items = @show_line_items
|
230
|
+
title = @title
|
231
|
+
buttons = @buttons
|
232
|
+
button_highlight = @button_highlight
|
233
|
+
box = @box
|
234
|
+
shadow = @shadow
|
235
|
+
|
236
|
+
config.each do |key, val|
|
237
|
+
x = val if key == :x
|
238
|
+
y = val if key == :y
|
239
|
+
width = val if key == :width
|
240
|
+
height = val if key == :height
|
241
|
+
title = val if key == :title
|
242
|
+
items = val if key == :items
|
243
|
+
hide_control_chars = val if key == :hide_control_chars
|
244
|
+
show_line_items = val if key == :show_line_items
|
245
|
+
buttons = val if key == :buttons
|
246
|
+
button_highlight = val if key == :button_highlight
|
247
|
+
box = val if key == :box
|
248
|
+
shadow = val if key == :shadow
|
249
|
+
end
|
250
|
+
|
251
|
+
self.set_title(title) if title != @title
|
252
|
+
self.set_highlight(button_highlight) if button_highlight != @button_highlight
|
253
|
+
self.set_items_line(show_line_items) if show_line_items != @show_line_items
|
254
|
+
self.set_box(box) if box != @box
|
255
|
+
self.set_items(items, hide_control_chars) if items != @items
|
121
256
|
end
|
122
257
|
|
123
258
|
# This sets the title of the viewer. (A nil title is allowed.
|
124
259
|
# It just means that the viewer will not have a title when drawn.)
|
125
|
-
def set_title
|
260
|
+
def set_title title
|
126
261
|
super(title, -(@box_width + 1))
|
127
262
|
@title_adj = @title_lines
|
128
263
|
|
@@ -130,66 +265,64 @@ module RNDK
|
|
130
265
|
@view_size = @box_height - (@title_lines + 1) - 2
|
131
266
|
end
|
132
267
|
|
133
|
-
def
|
134
|
-
|
268
|
+
def get_title
|
269
|
+
@title
|
135
270
|
end
|
136
271
|
|
137
|
-
def
|
272
|
+
def setup_line(interpret, items, x)
|
138
273
|
# Did they ask for attribute interpretation?
|
139
274
|
if interpret
|
140
|
-
|
141
|
-
|
142
|
-
@
|
143
|
-
@
|
144
|
-
@
|
275
|
+
items_len = []
|
276
|
+
items_pos = []
|
277
|
+
@items[x] = RNDK.char2Chtype(items, items_len, items_pos)
|
278
|
+
@items_len[x] = items_len[0]
|
279
|
+
@items_pos[x] = RNDK.justifyString(@box_width, @items_len[x], items_pos[0])
|
145
280
|
else
|
146
281
|
# We must convert tabs and other nonprinting characters. The curses
|
147
282
|
# library normally does this, but we are bypassing it by writing
|
148
283
|
# chtypes directly.
|
149
284
|
t = ''
|
150
285
|
len = 0
|
151
|
-
(0...
|
152
|
-
if
|
286
|
+
(0...items.size).each do |y|
|
287
|
+
if items[y] == "\t".ord
|
153
288
|
begin
|
154
289
|
t << ' '
|
155
290
|
len += 1
|
156
291
|
end while (len & 7) != 0
|
157
|
-
elsif RNDK.
|
158
|
-
t << RNDK.
|
292
|
+
elsif RNDK.char_of(items[y].ord).match(/^[[:print:]]$/)
|
293
|
+
t << RNDK.char_of(items[y].ord)
|
159
294
|
len += 1
|
160
295
|
else
|
161
|
-
t << Ncurses.unctrl(
|
296
|
+
t << Ncurses.unctrl(items[y].ord)
|
162
297
|
len += 1
|
163
298
|
end
|
164
299
|
end
|
165
|
-
@
|
166
|
-
@
|
167
|
-
@
|
300
|
+
@items[x] = t
|
301
|
+
@items_len[x] = t.size
|
302
|
+
@items_pos[x] = 0
|
168
303
|
end
|
169
|
-
@widest_line = [@widest_line, @
|
304
|
+
@widest_line = [@widest_line, @items_len[x]].max
|
170
305
|
end
|
171
306
|
|
172
|
-
def
|
173
|
-
if x < @
|
174
|
-
@list[x] = ''
|
175
|
-
end
|
307
|
+
def free_line(x)
|
308
|
+
@items[x] = '' if x < @items_size
|
176
309
|
end
|
177
310
|
|
178
311
|
# This function sets the contents of the viewer.
|
179
|
-
def
|
312
|
+
def set_items(items, interpret)
|
180
313
|
current_line = 0
|
181
|
-
viewer_size =
|
314
|
+
viewer_size = items.size
|
182
315
|
|
183
|
-
if
|
184
|
-
|
316
|
+
if items.size < 0
|
317
|
+
items.size = items.size
|
185
318
|
end
|
186
319
|
|
187
320
|
# Compute the size of the resulting display
|
188
|
-
viewer_size =
|
189
|
-
if
|
190
|
-
(0...
|
321
|
+
viewer_size = items.size
|
322
|
+
if items.size > 0 && interpret
|
323
|
+
(0...items.size).each do |x|
|
191
324
|
filename = ''
|
192
|
-
if RNDK.checkForLink(
|
325
|
+
if RNDK.checkForLink(items[x], filename) == 1
|
193
326
|
file_contents = []
|
194
327
|
file_len = RNDK.read_file(filename, file_contents)
|
195
328
|
|
@@ -200,27 +333,27 @@ module RNDK
|
|
200
333
|
end
|
201
334
|
end
|
202
335
|
|
203
|
-
# Clean out the old viewer
|
336
|
+
# Clean out the old viewer items. (if there is any)
|
204
337
|
@in_progress = true
|
205
338
|
self.clean
|
206
|
-
self.
|
339
|
+
self.create_items(viewer_size)
|
207
340
|
|
208
|
-
# Keep some semi-permanent
|
341
|
+
# Keep some semi-permanent items
|
209
342
|
@interpret = interpret
|
210
343
|
|
211
|
-
# Copy the
|
344
|
+
# Copy the itemsrmation given.
|
212
345
|
current_line = 0
|
213
346
|
x = 0
|
214
|
-
while x <
|
215
|
-
if
|
216
|
-
@
|
217
|
-
@
|
218
|
-
@
|
347
|
+
while x < items.size && current_line < viewer_size
|
348
|
+
if items[x].size == 0
|
349
|
+
@items[current_line] = ''
|
350
|
+
@items_len[current_line] = 0
|
351
|
+
@items_pos[current_line] = 0
|
219
352
|
current_line += 1
|
220
353
|
else
|
221
354
|
# Check if we have a file link in this line.
|
222
355
|
filename = []
|
223
|
-
if RNDK.checkForLink(
|
356
|
+
if RNDK.checkForLink(items[x], filename) == 1
|
224
357
|
# We have a link, open the file.
|
225
358
|
file_contents = []
|
226
359
|
file_len = 0
|
@@ -233,7 +366,7 @@ module RNDK
|
|
233
366
|
else '<C></K>Link Failed: Could not open the file %s'
|
234
367
|
end
|
235
368
|
temp = fopen_fmt % filename
|
236
|
-
self.
|
369
|
+
self.setup_line(true, temp, current_line)
|
237
370
|
current_line += 1
|
238
371
|
else
|
239
372
|
# For each line read, copy it into the viewer.
|
@@ -242,14 +375,14 @@ module RNDK
|
|
242
375
|
if current_line >= viewer_size
|
243
376
|
break
|
244
377
|
end
|
245
|
-
self.
|
246
|
-
@characters += @
|
378
|
+
self.setup_line(false, file_contents[file_line], current_line)
|
379
|
+
@characters += @items_len[current_line]
|
247
380
|
current_line += 1
|
248
381
|
end
|
249
382
|
end
|
250
383
|
elsif current_line < viewer_size
|
251
|
-
self.
|
252
|
-
@characters += @
|
384
|
+
self.setup_line(@interpret, items[x], current_line)
|
385
|
+
@characters += @items_len[current_line]
|
253
386
|
current_line += 1
|
254
387
|
end
|
255
388
|
end
|
@@ -264,20 +397,20 @@ module RNDK
|
|
264
397
|
@max_left_char = 0
|
265
398
|
end
|
266
399
|
|
267
|
-
# Set up the needed vars for the viewer
|
400
|
+
# Set up the needed vars for the viewer items.
|
268
401
|
@in_progress = false
|
269
|
-
@
|
270
|
-
if @
|
402
|
+
@items_size = viewer_size
|
403
|
+
if @items_size <= @view_size
|
271
404
|
@max_top_line = 0
|
272
405
|
else
|
273
|
-
@max_top_line = @
|
406
|
+
@max_top_line = @items_size - 1
|
274
407
|
end
|
275
|
-
return @
|
408
|
+
return @items_size
|
276
409
|
end
|
277
410
|
|
278
|
-
def
|
279
|
-
size << @
|
280
|
-
|
411
|
+
def get_items(size)
|
412
|
+
size << @items_size
|
413
|
+
@items
|
281
414
|
end
|
282
415
|
|
283
416
|
# This function sets the highlight type of the buttons.
|
@@ -285,72 +418,101 @@ module RNDK
|
|
285
418
|
@button_highlight = button_highlight
|
286
419
|
end
|
287
420
|
|
288
|
-
def
|
289
|
-
|
421
|
+
def get_highlight
|
422
|
+
@button_highlight
|
290
423
|
end
|
291
424
|
|
292
|
-
# This sets whether or not you wnat to set the viewer
|
293
|
-
|
294
|
-
|
425
|
+
# This sets whether or not you wnat to set the viewer
|
426
|
+
# items line.
|
427
|
+
def set_items_line(show_line_items)
|
428
|
+
@show_line_items = show_line_items
|
295
429
|
end
|
296
430
|
|
297
|
-
def
|
298
|
-
|
431
|
+
def get_items_line
|
432
|
+
@show_line_items
|
299
433
|
end
|
300
434
|
|
301
435
|
# This removes all the lines inside the scrolling window.
|
302
436
|
def clean
|
303
437
|
# Clean up the memory used...
|
304
|
-
(0...@
|
305
|
-
self.
|
438
|
+
(0...@items_size).each do |x|
|
439
|
+
self.free_line(x)
|
306
440
|
end
|
307
441
|
|
308
442
|
# Reset some variables.
|
309
|
-
@
|
443
|
+
@items_size = 0
|
310
444
|
@max_left_char = 0
|
311
445
|
@widest_line = 0
|
312
446
|
@current_top = 0
|
313
447
|
@max_top_line = 0
|
314
448
|
|
315
449
|
# Redraw the window.
|
316
|
-
self.draw
|
450
|
+
self.draw
|
317
451
|
end
|
318
452
|
|
319
453
|
def PatternNotFound(pattern)
|
320
|
-
|
454
|
+
temp_items = [
|
321
455
|
"</U/5>Pattern '%s' not found.<!U!5>" % pattern,
|
322
456
|
]
|
323
|
-
|
457
|
+
@screen.popup_label temp_items
|
324
458
|
end
|
325
459
|
|
326
460
|
# This function actually controls the viewer...
|
327
|
-
def activate(actions)
|
461
|
+
def activate(actions=[])
|
462
|
+
self.draw
|
463
|
+
|
464
|
+
if actions.nil? || actions.size == 0
|
465
|
+
loop do
|
466
|
+
input = self.getch
|
467
|
+
|
468
|
+
# Inject the character into the widget.
|
469
|
+
ret = self.inject input
|
470
|
+
|
471
|
+
return ret if @exit_type != :EARLY_EXIT
|
472
|
+
end
|
473
|
+
else
|
474
|
+
# Inject each character one at a time.
|
475
|
+
actions.each do |action|
|
476
|
+
ret = self.inject action
|
477
|
+
|
478
|
+
return ret if @exit_type != :EARLY_EXIT
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
# Set the exit type for the widget and return
|
483
|
+
self.set_exit_type(0)
|
484
|
+
return nil
|
485
|
+
end
|
486
|
+
|
487
|
+
def inject input
|
488
|
+
|
328
489
|
refresh = false
|
329
|
-
# Create the
|
330
|
-
|
490
|
+
# Create the itemsrmation about the file stats.
|
491
|
+
file_items = [
|
331
492
|
'</5> </U>File Statistics<!U> <!5>',
|
332
493
|
'</5> <!5>',
|
333
494
|
'</5/R>Character Count:<!R> %-4d <!5>' % @characters,
|
334
|
-
'</5/R>Line Count :<!R> %-4d <!5>' % @
|
495
|
+
'</5/R>Line Count :<!R> %-4d <!5>' % @items_size,
|
335
496
|
'</5> <!5>',
|
336
497
|
'<C></5>Press Any Key To Continue.<!5>'
|
337
498
|
]
|
338
499
|
|
339
|
-
|
500
|
+
temp_items = ['<C></5>Press Any Key To Continue.<!5>']
|
340
501
|
|
341
|
-
#
|
342
|
-
|
502
|
+
# Calls a pre-process block if exists.
|
503
|
+
# They can interrup input.
|
504
|
+
continue = run_signal_binding(:before_input, input)
|
343
505
|
|
344
|
-
|
345
|
-
self.draw(@box)
|
506
|
+
if continue
|
346
507
|
|
347
|
-
# Do this until KEY_ENTER is hit.
|
348
|
-
while true
|
349
508
|
# Reset the refresh flag.
|
350
509
|
refresh = false
|
351
510
|
|
352
|
-
|
353
|
-
|
511
|
+
if self.is_bound? input
|
512
|
+
self.run_key_binding input
|
513
|
+
#complete = true
|
514
|
+
|
515
|
+
else
|
354
516
|
case input
|
355
517
|
when RNDK::KEY_TAB
|
356
518
|
if @button_count > 1
|
@@ -361,7 +523,7 @@ module RNDK
|
|
361
523
|
end
|
362
524
|
|
363
525
|
# Redraw the buttons.
|
364
|
-
self.
|
526
|
+
self.draw_buttons
|
365
527
|
end
|
366
528
|
when RNDK::PREV
|
367
529
|
if @button_count > 1
|
@@ -372,78 +534,36 @@ module RNDK
|
|
372
534
|
end
|
373
535
|
|
374
536
|
# Redraw the buttons.
|
375
|
-
self.
|
376
|
-
end
|
377
|
-
when Ncurses::KEY_UP
|
378
|
-
if @current_top > 0
|
379
|
-
@current_top -= 1
|
380
|
-
refresh = true
|
381
|
-
else
|
382
|
-
RNDK.beep
|
383
|
-
end
|
384
|
-
when Ncurses::KEY_DOWN
|
385
|
-
if @current_top < @max_top_line
|
386
|
-
@current_top += 1
|
387
|
-
refresh = true
|
388
|
-
else
|
389
|
-
RNDK.beep
|
390
|
-
end
|
391
|
-
when Ncurses::KEY_RIGHT
|
392
|
-
if @left_char < @max_left_char
|
393
|
-
@left_char += 1
|
394
|
-
refresh = true
|
395
|
-
else
|
396
|
-
RNDK.beep
|
397
|
-
end
|
398
|
-
when Ncurses::KEY_LEFT
|
399
|
-
if @left_char > 0
|
400
|
-
@left_char -= 1
|
401
|
-
refresh = true
|
402
|
-
else
|
403
|
-
RNDK.beep
|
404
|
-
end
|
405
|
-
when Ncurses::KEY_PPAGE
|
406
|
-
if @current_top > 0
|
407
|
-
if @current_top - (@view_size - 1) > 0
|
408
|
-
@current_top = @current_top - (@view_size - 1)
|
409
|
-
else
|
410
|
-
@current_top = 0
|
411
|
-
end
|
412
|
-
refresh = true
|
413
|
-
else
|
414
|
-
RNDK.beep
|
415
|
-
end
|
416
|
-
when Ncurses::KEY_NPAGE
|
417
|
-
if @current_top < @max_top_line
|
418
|
-
if @current_top + @view_size < @max_top_line
|
419
|
-
@current_top = @current_top + (@view_size - 1)
|
420
|
-
else
|
421
|
-
@current_top = @max_top_line
|
422
|
-
end
|
423
|
-
refresh = true
|
424
|
-
else
|
425
|
-
RNDK.beep
|
537
|
+
self.draw_buttons
|
426
538
|
end
|
427
|
-
when Ncurses::
|
428
|
-
|
429
|
-
|
430
|
-
when Ncurses::
|
431
|
-
|
432
|
-
|
539
|
+
when Ncurses::KEY_UP then self.scroll_up
|
540
|
+
when Ncurses::KEY_DOWN then self.scroll_down
|
541
|
+
when Ncurses::KEY_RIGHT then self.scroll_right
|
542
|
+
when Ncurses::KEY_LEFT then self.scroll_left
|
543
|
+
when Ncurses::KEY_HOME then self.scroll_begin
|
544
|
+
when Ncurses::KEY_END then self.scroll_end
|
545
|
+
when Ncurses::KEY_PPAGE, RNDK::BACKCHAR
|
546
|
+
self.scroll_page_up
|
547
|
+
when Ncurses::KEY_NPAGE, RNDK::FORCHAR
|
548
|
+
self.scroll_page_down
|
549
|
+
|
433
550
|
when 'g'.ord, '1'.ord, '<'.ord
|
434
551
|
@current_top = 0
|
435
552
|
refresh = true
|
553
|
+
|
436
554
|
when 'G'.ord, '>'.ord
|
437
555
|
@current_top = @max_top_line
|
438
556
|
refresh = true
|
557
|
+
|
439
558
|
when 'L'.ord
|
440
|
-
x = (@
|
559
|
+
x = (@items_size + @current_top) / 2
|
441
560
|
if x < @max_top_line
|
442
561
|
@current_top = x
|
443
562
|
refresh = true
|
444
563
|
else
|
445
564
|
RNDK.beep
|
446
565
|
end
|
566
|
+
|
447
567
|
when 'l'.ord
|
448
568
|
x = @current_top / 2
|
449
569
|
if x >= 0
|
@@ -452,25 +572,29 @@ module RNDK
|
|
452
572
|
else
|
453
573
|
RNDK.beep
|
454
574
|
end
|
575
|
+
|
455
576
|
when '?'.ord
|
456
|
-
@search_direction =
|
457
|
-
self.
|
458
|
-
if !self.
|
577
|
+
@search_direction = Viewer::UP
|
578
|
+
self.get_and_store_pattern(@screen)
|
579
|
+
if !self.search_for_word(@search_pattern, @search_direction)
|
459
580
|
self.PatternNotFound(@search_pattern)
|
460
581
|
end
|
461
582
|
refresh = true
|
583
|
+
|
462
584
|
when '/'.ord
|
463
|
-
@search_direction =
|
464
|
-
self.
|
465
|
-
if !self.
|
585
|
+
@search_direction = Viewer::DOWN
|
586
|
+
self.get_and_store_pattern(@screen)
|
587
|
+
if !self.search_for_word(@search_pattern, @search_direction)
|
466
588
|
self.PatternNotFound(@search_pattern)
|
467
589
|
end
|
468
590
|
refresh = true
|
591
|
+
|
469
592
|
when 'N'.ord, 'n'.ord
|
470
593
|
if @search_pattern == ''
|
471
|
-
|
472
|
-
|
473
|
-
|
594
|
+
temp_items[0] = '</5>There is no pattern in the buffer.<!5>'
|
595
|
+
@screen.popup_label temp_items
|
596
|
+
|
597
|
+
elsif !self.search_for_word(@search_pattern,
|
474
598
|
if input == 'n'.ord
|
475
599
|
then @search_direction
|
476
600
|
else 1 - @search_direction
|
@@ -478,11 +602,12 @@ module RNDK
|
|
478
602
|
self.PatternNotFound(@search_pattern)
|
479
603
|
end
|
480
604
|
refresh = true
|
605
|
+
|
481
606
|
when ':'.ord
|
482
|
-
@current_top = self.
|
607
|
+
@current_top = self.jump_to_line
|
483
608
|
refresh = true
|
484
609
|
when 'i'.ord, 's'.ord, 'S'.ord
|
485
|
-
|
610
|
+
@screen.popup_label file_items
|
486
611
|
refresh = true
|
487
612
|
when RNDK::KEY_ESC
|
488
613
|
self.set_exit_type(input)
|
@@ -494,36 +619,41 @@ module RNDK
|
|
494
619
|
self.set_exit_type(input)
|
495
620
|
return @current_button
|
496
621
|
when RNDK::REFRESH
|
497
|
-
|
498
|
-
@screen.refresh
|
622
|
+
self.draw
|
499
623
|
else
|
500
624
|
RNDK.beep
|
501
625
|
end
|
626
|
+
|
627
|
+
run_signal_binding(:after_input, input)
|
502
628
|
end
|
503
629
|
|
504
630
|
# Do we need to redraw the screen?
|
505
|
-
if refresh
|
506
|
-
self.drawInfo
|
507
|
-
end
|
631
|
+
self.draw_items if refresh
|
508
632
|
end
|
633
|
+
self.draw
|
509
634
|
end
|
510
635
|
|
511
636
|
# This searches the document looking for the given word.
|
512
|
-
def
|
637
|
+
def get_and_store_pattern(screen)
|
513
638
|
temp = ''
|
514
639
|
|
515
640
|
# Check the direction.
|
516
|
-
if @search_direction ==
|
641
|
+
if @search_direction == Viewer::UP
|
517
642
|
temp = '</5>Search Up : <!5>'
|
518
643
|
else
|
519
644
|
temp = '</5>Search Down: <!5>'
|
520
645
|
end
|
521
646
|
|
522
647
|
# Pop up the entry field.
|
523
|
-
get_pattern = RNDK::Entry.new(screen,
|
524
|
-
|
525
|
-
|
526
|
-
|
648
|
+
get_pattern = RNDK::Entry.new(screen, {
|
649
|
+
:x => RNDK::CENTER,
|
650
|
+
:y => RNDK::CENTER,
|
651
|
+
:title => '',
|
652
|
+
:label => temp,
|
653
|
+
:field_color => RNDK::Color[:white_blue] | RNDK::Color[:bold],
|
654
|
+
:filler => '.'.ord | RNDK::Color[:white_blue] | RNDK::Color[:bold],
|
655
|
+
:field_width => 10
|
656
|
+
})
|
527
657
|
|
528
658
|
# Is there an old search pattern?
|
529
659
|
if @search_pattern.size != 0
|
@@ -532,11 +662,11 @@ module RNDK
|
|
532
662
|
end
|
533
663
|
|
534
664
|
# Activate this baby.
|
535
|
-
|
665
|
+
items = get_pattern.activate([])
|
536
666
|
|
537
|
-
# Save teh
|
538
|
-
if
|
539
|
-
@search_pattern =
|
667
|
+
# Save teh items.
|
668
|
+
if items.size != 0
|
669
|
+
@search_pattern = items
|
540
670
|
end
|
541
671
|
|
542
672
|
# Clean up.
|
@@ -545,22 +675,22 @@ module RNDK
|
|
545
675
|
|
546
676
|
# This searches for a line containing the word and realigns the value on
|
547
677
|
# the screen.
|
548
|
-
def
|
678
|
+
def search_for_word(pattern, direction)
|
549
679
|
found = false
|
550
680
|
|
551
681
|
# If the pattern is empty then return.
|
552
682
|
if pattern.size != 0
|
553
|
-
if direction ==
|
683
|
+
if direction == Viewer::DOWN
|
554
684
|
# Start looking from 'here' down.
|
555
685
|
x = @current_top + 1
|
556
|
-
while !found && x < @
|
686
|
+
while !found && x < @items_size
|
557
687
|
pos = 0
|
558
688
|
y = 0
|
559
|
-
while y < @
|
560
|
-
plain_char = RNDK.
|
689
|
+
while y < @items[x].size
|
690
|
+
plain_char = RNDK.char_of(@items[x][y])
|
561
691
|
|
562
692
|
pos += 1
|
563
|
-
if
|
693
|
+
if RNDK.char_of(pattern[pos-1]) != plain_char
|
564
694
|
y -= (pos - 1)
|
565
695
|
pos = 0
|
566
696
|
elsif pos == pattern.size
|
@@ -579,11 +709,11 @@ module RNDK
|
|
579
709
|
while ! found && x >= 0
|
580
710
|
y = 0
|
581
711
|
pos = 0
|
582
|
-
while y < @
|
583
|
-
plain_char = RNDK.
|
712
|
+
while y < @items[x].size
|
713
|
+
plain_char = RNDK.char_of(@items[x][y])
|
584
714
|
|
585
715
|
pos += 1
|
586
|
-
if RNDK.
|
716
|
+
if RNDK.char_of(pattern[pos-1]) != plain_char
|
587
717
|
y -= (pos - 1)
|
588
718
|
pos = 0
|
589
719
|
elsif pos == pattern.size
|
@@ -596,62 +726,55 @@ module RNDK
|
|
596
726
|
end
|
597
727
|
end
|
598
728
|
end
|
599
|
-
|
729
|
+
found
|
600
730
|
end
|
601
731
|
|
602
732
|
# This allows us to 'jump' to a given line in the file.
|
603
|
-
def
|
604
|
-
newline = RNDK::
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
733
|
+
def jump_to_line
|
734
|
+
newline = RNDK::Scale.new(@screen, {
|
735
|
+
:x => RNDK::CENTER,
|
736
|
+
:y => RNDK::CENTER,
|
737
|
+
:title => '<C>Jump To Line',
|
738
|
+
:label => '</5>Line :',
|
739
|
+
:field_color => RNDK::Color[:bold],
|
740
|
+
:field_width => @items_size.size + 1,
|
741
|
+
:start => @current_top + 1,
|
742
|
+
:high => @max_top_line + 1,
|
743
|
+
:fast_increment => 10,
|
744
|
+
:shador => true
|
745
|
+
})
|
746
|
+
|
747
|
+
line = newline.activate
|
609
748
|
newline.destroy
|
610
|
-
|
611
|
-
end
|
612
|
-
|
613
|
-
# This pops a little message up on the screen.
|
614
|
-
def popUpLabel(mesg)
|
615
|
-
# Set up variables.
|
616
|
-
label = RNDK::Label.new(@screen, RNDK::CENTER, RNDK::CENTER,
|
617
|
-
mesg, mesg.size, true, false)
|
618
|
-
|
619
|
-
# Draw the label and wait.
|
620
|
-
label.draw(true)
|
621
|
-
label.getch([])
|
622
|
-
|
623
|
-
# Clean up.
|
624
|
-
label.destroy
|
749
|
+
line - 1
|
625
750
|
end
|
626
751
|
|
627
752
|
# This moves the viewer field to the given location.
|
628
753
|
# Inherited
|
629
|
-
# def move(
|
754
|
+
# def move(x, y, relative, refresh_flag)
|
630
755
|
# end
|
631
756
|
|
632
757
|
# This function draws the viewer widget.
|
633
|
-
def draw
|
758
|
+
def draw
|
634
759
|
# Do we need to draw in the shadow?
|
635
760
|
unless @shadow_win.nil?
|
636
761
|
Draw.drawShadow @shadow_win
|
637
762
|
end
|
638
763
|
|
639
764
|
# Box it if it was asked for.
|
640
|
-
if box
|
765
|
+
if @box
|
641
766
|
Draw.drawObjBox(@win, self)
|
642
767
|
Ncurses.wrefresh @win
|
643
768
|
end
|
644
769
|
|
645
|
-
# Draw the
|
646
|
-
self.
|
770
|
+
# Draw the items in the viewer.
|
771
|
+
self.draw_items
|
647
772
|
end
|
648
773
|
|
649
774
|
# This redraws the viewer buttons.
|
650
|
-
def
|
775
|
+
def draw_buttons
|
651
776
|
# No buttons, no drawing
|
652
|
-
if @button_count == 0
|
653
|
-
return
|
654
|
-
end
|
777
|
+
return if @button_count == 0
|
655
778
|
|
656
779
|
# Redraw the buttons.
|
657
780
|
(0...@button_count).each do |x|
|
@@ -667,7 +790,7 @@ module RNDK
|
|
667
790
|
# Highlight the current button.
|
668
791
|
(0...@button_len[@current_button]).each do |x|
|
669
792
|
# Strip the character of any extra attributes.
|
670
|
-
character = RNDK.
|
793
|
+
character = RNDK.char_of @button[@current_button][x]
|
671
794
|
|
672
795
|
# Add the character into the window.
|
673
796
|
Ncurses.mvwaddch(@win,
|
@@ -681,73 +804,72 @@ module RNDK
|
|
681
804
|
end
|
682
805
|
|
683
806
|
# This sets the background attribute of the widget.
|
684
|
-
def
|
807
|
+
def set_bg_color(attrib)
|
685
808
|
Ncurses.wbkgd(@win, attrib)
|
686
809
|
end
|
687
810
|
|
688
|
-
def
|
689
|
-
@
|
690
|
-
@
|
691
|
-
@
|
811
|
+
def destroy_items
|
812
|
+
@items = []
|
813
|
+
@items_pos = []
|
814
|
+
@items_len = []
|
692
815
|
end
|
693
816
|
|
694
817
|
# This function destroys the viewer widget.
|
695
818
|
def destroy
|
696
|
-
self.
|
697
|
-
|
698
|
-
self.cleanTitle
|
819
|
+
self.destroy_items
|
820
|
+
self.clean_title
|
699
821
|
|
700
822
|
# Clean up the windows.
|
701
|
-
RNDK.window_delete
|
702
|
-
RNDK.window_delete
|
823
|
+
RNDK.window_delete @shadow_win
|
824
|
+
RNDK.window_delete @win
|
703
825
|
|
704
826
|
# Clean the key bindings.
|
705
|
-
self.clean_bindings
|
827
|
+
self.clean_bindings
|
706
828
|
|
707
|
-
# Unregister this
|
708
|
-
|
829
|
+
# Unregister this widget.
|
830
|
+
@screen.unregister self
|
709
831
|
end
|
710
832
|
|
711
833
|
# This function erases the viewer widget from the screen.
|
712
834
|
def erase
|
713
|
-
if self.
|
835
|
+
if self.valid?
|
714
836
|
RNDK.window_erase(@win)
|
715
837
|
RNDK.window_erase(@shadow_win)
|
716
838
|
end
|
717
839
|
end
|
718
840
|
|
719
|
-
# This draws the viewer
|
720
|
-
def
|
841
|
+
# This draws the viewer items lines.
|
842
|
+
def draw_items
|
721
843
|
temp = ''
|
722
844
|
line_adjust = false
|
723
845
|
|
724
846
|
# Clear the window.
|
725
847
|
Ncurses.werase(@win)
|
726
848
|
|
727
|
-
self.
|
849
|
+
self.draw_title @win
|
728
850
|
|
729
851
|
# Draw in the current line at the top.
|
730
|
-
if @
|
731
|
-
# Set up the
|
852
|
+
if @show_line_items == true
|
853
|
+
# Set up the items line and draw it.
|
732
854
|
if @in_progress
|
733
855
|
temp = 'processing...'
|
734
|
-
elsif @
|
735
|
-
temp = '%d/%d %2.0f%%' % [@current_top + 1, @
|
736
|
-
((1.0 * @current_top + 1) / (@
|
856
|
+
elsif @items_size != 0
|
857
|
+
temp = '%d/%d %2.0f%%' % [@current_top + 1, @items_size,
|
858
|
+
((1.0 * @current_top + 1) / (@items_size)) * 100]
|
737
859
|
else
|
738
860
|
temp = '%d/%d %2.0f%%' % [0, 0, 0.0]
|
739
861
|
end
|
740
862
|
|
741
|
-
# The
|
863
|
+
# The items_adjust variable tells us if we have to shift down one line
|
742
864
|
# because the person asked for the line X of Y line at the top of the
|
743
|
-
# screen. We only want to set this to true if they asked for the
|
865
|
+
# screen. We only want to set this to true if they asked for the items
|
744
866
|
# line and there is no title or if the two items overlap.
|
745
867
|
if @title_lines == '' || @title_pos[0] < temp.size + 2
|
746
|
-
|
868
|
+
items_adjust = true
|
747
869
|
end
|
748
870
|
Draw.writeChar(@win,
|
749
871
|
1,
|
750
|
-
if
|
872
|
+
if items_adjust then @title_lines else 0 end + 1,
|
751
873
|
temp,
|
752
874
|
RNDK::HORIZONTAL,
|
753
875
|
0,
|
@@ -755,24 +877,24 @@ module RNDK
|
|
755
877
|
end
|
756
878
|
|
757
879
|
# Determine the last line to draw.
|
758
|
-
last_line = [@
|
759
|
-
last_line -= if
|
880
|
+
last_line = [@items_size, @view_size].min
|
881
|
+
last_line -= if items_adjust then 1 else 0 end
|
760
882
|
|
761
|
-
# Redraw the
|
883
|
+
# Redraw the items.
|
762
884
|
(0...last_line).each do |x|
|
763
|
-
if @current_top + x < @
|
764
|
-
screen_pos = @
|
885
|
+
if @current_top + x < @items_size
|
886
|
+
screen_pos = @items_pos[@current_top + x] + 1 - @left_char
|
765
887
|
|
766
888
|
Draw.writeChtype(@win,
|
767
889
|
if screen_pos >= 0 then screen_pos else 1 end,
|
768
|
-
x + @title_lines + if
|
769
|
-
@
|
890
|
+
x + @title_lines + if items_adjust then 1 else 0 end + 1,
|
891
|
+
@items[x + @current_top],
|
770
892
|
RNDK::HORIZONTAL,
|
771
893
|
if screen_pos >= 0
|
772
894
|
then 0
|
773
|
-
else @left_char - @
|
895
|
+
else @left_char - @items_pos[@current_top + x]
|
774
896
|
end,
|
775
|
-
@
|
897
|
+
@items_len[x + @current_top])
|
776
898
|
end
|
777
899
|
end
|
778
900
|
|
@@ -795,21 +917,21 @@ module RNDK
|
|
795
917
|
end
|
796
918
|
|
797
919
|
# Draw the buttons. This will call refresh on the viewer win.
|
798
|
-
self.
|
920
|
+
self.draw_buttons
|
799
921
|
end
|
800
922
|
|
801
|
-
# The
|
802
|
-
def
|
923
|
+
# The items_size may be negative, to assign no definite limit.
|
924
|
+
def create_items(items_size)
|
803
925
|
status = false
|
804
926
|
|
805
|
-
self.
|
927
|
+
self.destroy_items
|
806
928
|
|
807
|
-
if
|
929
|
+
if items_size >= 0
|
808
930
|
status = true
|
809
931
|
|
810
|
-
@
|
811
|
-
@
|
812
|
-
@
|
932
|
+
@items = []
|
933
|
+
@items_pos = []
|
934
|
+
@items_len = []
|
813
935
|
end
|
814
936
|
return status
|
815
937
|
end
|
@@ -818,8 +940,87 @@ module RNDK
|
|
818
940
|
super(@win)
|
819
941
|
end
|
820
942
|
|
821
|
-
def
|
822
|
-
|
943
|
+
def scroll_up
|
944
|
+
if @current_top > 0
|
945
|
+
@current_top -= 1
|
946
|
+
refresh = true
|
947
|
+
else
|
948
|
+
RNDK.beep
|
949
|
+
end
|
950
|
+
end
|
951
|
+
|
952
|
+
def scroll_down
|
953
|
+
if @current_top < @max_top_line
|
954
|
+
@current_top += 1
|
955
|
+
refresh = true
|
956
|
+
else
|
957
|
+
RNDK.beep
|
958
|
+
end
|
959
|
+
end
|
960
|
+
|
961
|
+
def scroll_right
|
962
|
+
if @left_char < @max_left_char
|
963
|
+
@left_char += 1
|
964
|
+
refresh = true
|
965
|
+
else
|
966
|
+
RNDK.beep
|
967
|
+
end
|
968
|
+
end
|
969
|
+
|
970
|
+
def scroll_left
|
971
|
+
if @left_char > 0
|
972
|
+
@left_char -= 1
|
973
|
+
refresh = true
|
974
|
+
else
|
975
|
+
RNDK.beep
|
976
|
+
end
|
977
|
+
end
|
978
|
+
|
979
|
+
def scroll_page_up
|
980
|
+
if @current_top > 0
|
981
|
+
if @current_top - (@view_size - 1) > 0
|
982
|
+
@current_top = @current_top - (@view_size - 1)
|
983
|
+
else
|
984
|
+
@current_top = 0
|
985
|
+
end
|
986
|
+
refresh = true
|
987
|
+
else
|
988
|
+
RNDK.beep
|
989
|
+
end
|
990
|
+
|
991
|
+
end
|
992
|
+
|
993
|
+
def scroll_page_down
|
994
|
+
if @current_top < @max_top_line
|
995
|
+
if @current_top + @view_size < @max_top_line
|
996
|
+
@current_top = @current_top + (@view_size - 1)
|
997
|
+
else
|
998
|
+
@current_top = @max_top_line
|
999
|
+
end
|
1000
|
+
refresh = true
|
1001
|
+
else
|
1002
|
+
RNDK.beep
|
1003
|
+
end
|
823
1004
|
end
|
1005
|
+
|
1006
|
+
def scroll_begin
|
1007
|
+
@left_char = 0
|
1008
|
+
refresh = true
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
def scroll_end
|
1012
|
+
@left_char = @max_left_char
|
1013
|
+
refresh = true
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
def focus
|
1017
|
+
self.draw
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
def unfocus
|
1021
|
+
self.draw
|
1022
|
+
end
|
1023
|
+
|
824
1024
|
end
|
825
1025
|
end
|
1026
|
+
|