Class: CDK::VIEWER

Inherits:
CDKOBJS show all
Defined in:
lib/cdk/components/viewer.rb

Constant Summary collapse

DOWN =
0
UP =
1

Instance Attribute Summary

Attributes included from HasTitle

#title_attrib

Attributes included from HasScreen

#is_visible, #screen, #screen_index

Attributes included from ExitConditions

#exit_type

Attributes included from Bindings

#binding_list

Attributes included from Focusable

#accepts_focus, #has_focus

Attributes included from Borders

#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box

Instance Method Summary collapse

Methods inherited from CDKOBJS

#setBackgroundColor, #timeout, #validCDKObject, #validObjType

Methods included from WindowHooks

#refreshData, #saveData

Methods included from WindowInput

#getc, #getch, #inject, #setPostProcess, #setPreProcess

Methods included from HasTitle

#cleanTitle, #drawTitle, #init_title

Methods included from HasScreen

#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh

Methods included from ExitConditions

#init_exit_conditions, #resetExitType, #setExitType

Methods included from Bindings

#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind

Methods included from Focusable

#focus, #init_focus, #unfocus

Methods included from Borders

#getBox, #init_borders, #setBXattr, #setBox, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar

Methods included from Movement

#move, #move_specific

Methods included from Converters

#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute

Methods included from Justifications

#justify_string

Methods included from Alignments

#alignxy

Constructor Details

#initialize(cdkscreen, xplace, yplace, height, width, buttons, button_count, button_highlight, box, shadow) ⇒ VIEWER

Returns a new instance of VIEWER.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cdk/components/viewer.rb', line 8

def initialize(cdkscreen, xplace, yplace, height, width,
    buttons, button_count, button_highlight, box, shadow)
  super()
  parent_width = cdkscreen.window.getmaxx
  parent_height = cdkscreen.window.getmaxy
  box_width = width
  box_height = height
  button_width = 0
  button_adj = 0
  button_pos = 1
  bindings = {
      CDK::BACKCHAR => Ncurses::KEY_PPAGE,
      'b'           => Ncurses::KEY_PPAGE,
      'B'           => Ncurses::KEY_PPAGE,
      CDK::FORCHAR  => Ncurses::KEY_NPAGE,
      ' '           => Ncurses::KEY_NPAGE,
      'f'           => Ncurses::KEY_NPAGE,
      'F'           => Ncurses::KEY_NPAGE,
      '|'           => Ncurses::KEY_HOME,
      '$'           => Ncurses::KEY_END,
  }

  self.setBox(box)

  box_height = CDK.setWidgetDimension(parent_height, height, 0)
  box_width = CDK.setWidgetDimension(parent_width, width, 0)

  # Rejustify the x and y positions if we need to.
  xtmp = [xplace]
  ytmp = [yplace]
  alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
  xpos = xtmp[0]
  ypos = ytmp[0]

  # Make the viewer window.
  @win= Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
  if @win.nil?
    self.destroy
    return nil
  end

  # Turn the keypad on for the viewer.
  @win.keypad(true)

  # Create the buttons.
  @button_count = button_count
  @button = []
  @button_len = []
  @button_pos = []
  if button_count > 0
    (0...button_count).each do |x|
      button_len = []
      @button << char2Chtype(buttons[x], button_len, [])
      @button_len << button_len[0]
      button_width += @button_len[x] + 1
    end
    button_adj = (box_width - button_width) / (button_count + 1)
    button_pos = 1 + button_adj
    (0...button_count).each do |x|
      @button_pos << button_pos
      button_pos += button_adj + @button_len[x]
    end
  end

  # Set the rest of the variables.
  @screen = cdkscreen
  @parent = cdkscreen.window
  @shadow_win = nil
  @button_highlight = button_highlight
  @box_height = box_height
  @box_width = box_width - 2
  @view_size = height - 2
  @input_window = @win
  @shadow = shadow
  @current_button = 0
  @current_top = 0
  @length = 0
  @left_char = 0
  @max_left_char = 0
  @max_top_line = 0
  @characters = 0
  @list_size = -1
  @show_line_info = 1
  @exit_type = :EARLY_EXIT

  # Do we need to create a shadow?
  if shadow
    @shadow_win = Ncurses::WINDOW.new(box_height, box_width + 1,
        ypos + 1, xpos + 1)
    if @shadow_win.nil?
      self.destroy
      return nil
    end
  end

  # Setup the key bindings.
  bindings.each do |from, to|
    self.bind(:VIEWER, from, :getc, to)
  end

  cdkscreen.register(:VIEWER, self)
end

Instance Method Details

#activate(actions) ⇒ Object

This function actually controls the viewer…



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/cdk/components/viewer.rb', line 325

def activate(actions)
  refresh = false
  # Create the information about the file stats.
  file_info = [
      '</5>      </U>File Statistics<!U>     <!5>',
      '</5>                          <!5>',
      '</5/R>Character Count:<!R> %-4d     <!5>' % @characters,
      '</5/R>Line Count     :<!R> %-4d     <!5>' % @list_size,
      '</5>                          <!5>',
      '<C></5>Press Any Key To Continue.<!5>'
  ]

  temp_info = ['<C></5>Press Any Key To Continue.<!5>']

  # Set the current button.
  @current_button = 0

  # Draw the widget list.
  self.draw(@box)

  # Do this until KEY_ENTER is hit.
  while true
    # Reset the refresh flag.
    refresh = false

    input = self.getch([])
    if !self.checkBind(:VIEWER, input)
      case input
      when CDK::KEY_TAB
        if @button_count > 1
          if @current_button == @button_count - 1
            @current_button = 0
          else
            @current_button += 1
          end

          # Redraw the buttons.
          self.drawButtons
        end
      when CDK::PREV
        if @button_count > 1
          if @current_button == 0
            @current_button = @button_count - 1
          else
            @current_button -= 1
          end

          # Redraw the buttons.
          self.drawButtons
        end
      when Ncurses::KEY_UP
        if @current_top > 0
          @current_top -= 1
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_DOWN
        if @current_top < @max_top_line
          @current_top += 1
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_RIGHT
        if @left_char < @max_left_char
          @left_char += 1
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_LEFT
        if @left_char > 0
          @left_char -= 1
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_PPAGE
        if @current_top > 0
          if @current_top - (@view_size - 1) > 0
            @current_top = @current_top - (@view_size - 1)
          else
            @current_top = 0
          end
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_NPAGE
        if @current_top < @max_top_line
          if @current_top + @view_size < @max_top_line
            @current_top = @current_top + (@view_size - 1)
          else
            @current_top = @max_top_line
          end
          refresh = true
        else
          CDK.Beep
        end
      when Ncurses::KEY_HOME
        @left_char = 0
        refresh = true
      when Ncurses::KEY_END
        @left_char = @max_left_char
        refresh = true
      when 'g'.ord, '1'.ord, '<'.ord
        @current_top = 0
        refresh = true
      when 'G'.ord, '>'.ord
        @current_top = @max_top_line
        refresh = true
      when 'L'.ord
        x = (@list_size + @current_top) / 2
        if x < @max_top_line
          @current_top = x
          refresh = true
        else
          CDK.Beep
        end
      when 'l'.ord
        x = @current_top / 2
        if x >= 0
          @current_top = x
          refresh = true
        else
          CDK.Beep
        end
      when '?'.ord
        @search_direction = CDK::VIEWER::UP
        self.getAndStorePattern(@screen)
        if !self.searchForWord(@search_pattern, @search_direction)
          self.PatternNotFound(@search_pattern)
        end
        refresh = true
      when '/'.ord
        @search_direction = CDK::VIEWER:DOWN
        self.getAndStorePattern(@screen)
        if !self.searchForWord(@search_pattern, @search_direction)
          self.PatternNotFound(@search_pattern)
        end
        refresh = true
      when 'N'.ord, 'n'.ord
        if @search_pattern == ''
          temp_info[0] = '</5>There is no pattern in the buffer.<!5>'
          self.popUpLabel(temp_info)
        elsif !self.searchForWord(@search_pattern,
            if input == 'n'.ord
            then @search_direction
            else 1 - @search_direction
            end)
          self.PatternNotFound(@search_pattern)
        end
        refresh = true
      when ':'.ord
        @current_top = self.jumpToLine
        refresh = true
      when 'i'.ord, 's'.ord, 'S'.ord
        self.popUpLabel(file_info)
        refresh = true
      when CDK::KEY_ESC
        self.setExitType(input)
        return -1
      when Ncurses::ERR
        self.setExitType(input)
        return -1
      when Ncurses::KEY_ENTER, CDK::KEY_RETURN
        self.setExitType(input)
        return @current_button
      when CDK::REFRESH
        @screen.erase
        @screen.refresh
      else
        CDK.Beep
      end
    end

    # Do we need to redraw the screen?
    if refresh
      self.drawInfo
    end
  end
end

#cleanObject

This removes all the lines inside the scrolling window.



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/cdk/components/viewer.rb', line 300

def clean
  # Clean up the memory used...
  (0...@list_size).each do |x|
    self.freeLine(x)
  end

  # Reset some variables.
  @list_size = 0
  @max_left_char = 0
  @widest_line = 0
  @current_top = 0
  @max_top_line = 0

  # Redraw the window.
  self.draw(@box)
end

#createList(list_size) ⇒ Object

The list_size may be negative, to assign no definite limit.



789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/cdk/components/viewer.rb', line 789

def createList(list_size)
  status = false

  self.destroyInfo

  if list_size >= 0
    status = true

    @list = []
    @list_pos = []
    @list_len = []
  end
  return status
end

#destroyObject

This function destroys the viewer widget.



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/cdk/components/viewer.rb', line 686

def destroy
  self.destroyInfo

  self.cleanTitle

  # Clean up the windows.
  CDK.deleteCursesWindow(@shadow_win)
  CDK.deleteCursesWindow(@win)

  # Clean the key bindings.
  self.cleanBindings(:VIEWER)

  # Unregister this object.
  CDK::SCREEN.unregister(:VIEWER, self)
end

#destroyInfoObject



679
680
681
682
683
# File 'lib/cdk/components/viewer.rb', line 679

def destroyInfo
  @list = []
  @list_pos = []
  @list_len = []
end

#draw(box) ⇒ Object

This function draws the viewer widget.



631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/cdk/components/viewer.rb', line 631

def draw(box)
  # Do we need to draw in the shadow?
  unless @shadow_win.nil?
    Draw.drawShadow(@shadow_win)
  end

  # Box it if it was asked for.
  if box
    Draw.drawObjBox(@win, self)
    wrefresh
  end

  # Draw the info in the viewer.
  self.drawInfo
end

#drawButtonsObject

This redraws the viewer buttons.



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/cdk/components/viewer.rb', line 648

def drawButtons
  # No buttons, no drawing
  if @button_count == 0
    return
  end

  # Redraw the buttons.
  (0...@button_count).each do |x|
    Draw.writeChtype(@win, @button_pos[x], @box_height - 2,
        @button[x], CDK::HORIZONTAL, 0, @button_len[x])
  end

  # Highlight the current button.
  (0...@button_len[@current_button]).each do |x|
    # Strip the character of any extra attributes.
    character = charOf(@button[@current_button][x])

    # Add the character into the window.
    @win.mvwaddch(@box_height - 2, @button_pos[@current_button] + x,
        character.ord | @button_highlight)
  end

  # Refresh the window.
  wrefresh
end

#drawInfoObject

This draws the viewer info lines.



711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
# File 'lib/cdk/components/viewer.rb', line 711

def drawInfo
  temp = ''
  line_adjust = false

  # Clear the window.
  @win.werase

  self.drawTitle(@win)

  # Draw in the current line at the top.
  if @show_line_info == true
    # Set up the info line and draw it.
    if @in_progress
      temp = 'processing...'
    elsif @list_size != 0
      temp = '%d/%d %2.0f%%' % [@current_top + 1, @list_size,
          ((1.0 * @current_top + 1) / (@list_size)) * 100]
    else
      temp = '%d/%d %2.0f%%' % [0, 0, 0.0]
    end

    # The list_adjust variable tells us if we have to shift down one line
    # because the person asked for the line X of Y line at the top of the
    # screen. We only want to set this to true if they asked for the info
    # line and there is no title or if the two items overlap.
    if @title_lines == '' || @title_pos[0] < temp.size + 2
      list_adjust = true
    end
    Draw.writeChar(@win, 1,
        if list_adjust then @title_lines else 0 end + 1,
        temp, CDK::HORIZONTAL, 0, temp.size)
  end

  # Determine the last line to draw.
  last_line = [@list_size, @view_size].min
  last_line -= if list_adjust then 1 else 0 end

  # Redraw the list.
  (0...last_line).each do |x|
    if @current_top + x < @list_size
      screen_pos = @list_pos[@current_top + x] + 1 - @left_char

      Draw.writeChtype(@win,
          if screen_pos >= 0 then screen_pos else 1 end,
          x + @title_lines + if list_adjust then 1 else 0 end + 1,
          @list[x + @current_top], CDK::HORIZONTAL,
          if screen_pos >= 0
          then 0
          else @left_char - @list_pos[@current_top + x]
          end,
          @list_len[x + @current_top])
    end
  end

  # Box it if we have to.
  if @box
    Draw.drawObjBox(@win, self)
    wrefresh
  end

  # Draw the separation line.
  if @button_count > 0
    boxattr = @BXAttr

    (1..@box_width).each do |x|
      @win.mvwaddch(@box_height - 3, x, @HZChar | boxattr)
    end

    @win.mvwaddch(@box_height - 3, 0, Ncurses::ACS_LTEE | boxattr)
    @win.mvwaddch(@box_height - 3, @win.getmaxx - 1,
        Ncurses::ACS_RTEE | boxattr)
  end

  # Draw the buttons. This will call refresh on the viewer win.
  self.drawButtons
end

#eraseObject

This function erases the viewer widget from the screen.



703
704
705
706
707
708
# File 'lib/cdk/components/viewer.rb', line 703

def erase
  if self.validCDKObject
    CDK.eraseCursesWindow(@win)
    CDK.eraseCursesWindow(@shadow_win)
  end
end

#freeLine(x) ⇒ Object



170
171
172
173
174
# File 'lib/cdk/components/viewer.rb', line 170

def freeLine(x)
  if x < @list_size
    @list[x] = ''
  end
end

#getAndStorePattern(screen) ⇒ Object

This searches the document looking for the given word.



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/cdk/components/viewer.rb', line 510

def getAndStorePattern(screen)
  temp = ''

  # Check the direction.
  if @search_direction == CDK::VIEWER::UP
    temp = '</5>Search Up  : <!5>'
  else
    temp = '</5>Search Down: <!5>'
  end

  # Pop up the entry field.
  get_pattern = CDK::ENTRY.new(screen, CDK::CENTER, CDK::CENTER,
      '', label, Ncurses.COLOR_PAIR(5) | Ncurses::A_BOLD,
      '.' | Ncurses.COLOR_PAIR(5) | Ncurses::A_BOLD,
      :MIXED, 10, 0, 256, true, false)

  # Is there an old search pattern?
  if @search_pattern.size != 0
    get_pattern.set(@search_pattern, get_pattern.min, get_pattern.max,
        get_pattern.box)
  end

  # Activate this baby.
  list = get_pattern.activate([])

  # Save teh list.
  if list.size != 0
    @search_pattern = list
  end

  # Clean up.
  get_pattern.destroy
end

#getHighlightObject



286
287
288
# File 'lib/cdk/components/viewer.rb', line 286

def getHighlight
  return @button_highlight
end

#getInfo(size) ⇒ Object



276
277
278
279
# File 'lib/cdk/components/viewer.rb', line 276

def getInfo(size)
  size << @list_size
  return @list
end

#getInfoLineObject



295
296
297
# File 'lib/cdk/components/viewer.rb', line 295

def getInfoLine
  return @show_line_info
end

#getTitleObject



131
132
133
# File 'lib/cdk/components/viewer.rb', line 131

def getTitle
  return @title
end

#jumpToLineObject

This allows us to ‘jump’ to a given line in the file.



601
602
603
604
605
606
607
608
609
# File 'lib/cdk/components/viewer.rb', line 601

def jumpToLine
  newline = CDK::SCALE.new(@screen, CDK::CENTER, CDK::CENTER,
      '<C>Jump To Line', '</5>Line :', Ncurses::A_BOLD,
      @list_size.size + 1, @current_top + 1, 0, @max_top_line + 1,
      1, 10, true, true)
  line = newline.activate([])
  newline.destroy
  return line - 1
end

#object_typeObject



808
809
810
# File 'lib/cdk/components/viewer.rb', line 808

def object_type
  :VIEWER
end

#PatternNotFound(pattern) ⇒ Object



317
318
319
320
321
322
# File 'lib/cdk/components/viewer.rb', line 317

def PatternNotFound(pattern)
  temp_info = [
      "</U/5>Pattern '%s' not found.<!U!5>" % pattern,
  ]
  self.popUpLabel(temp_info)
end

#popUpLabel(mesg) ⇒ Object

This pops a little message up on the screen.



612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/cdk/components/viewer.rb', line 612

def popUpLabel(mesg)
  # Set up variables.
  label = CDK::LABEL.new(@screen, CDK::CENTER, CDK::CENTER,
      mesg, mesg.size, true, false)

  # Draw the label and wait.
  label.draw(true)
  label.getch([])

  # Clean up.
  label.destroy
end

#positionObject



804
805
806
# File 'lib/cdk/components/viewer.rb', line 804

def position
  super(@win)
end

#searchForWord(pattern, direction) ⇒ Object

This searches for a line containing the word and realigns the value on the screen.



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/cdk/components/viewer.rb', line 546

def searchForWord(pattern, direction)
  found = false

  # If the pattern is empty then return.
  if pattern.size != 0
    if direction == CDK::VIEWER::DOWN
      # Start looking from 'here' down.
      x = @current_top + 1
      while !found && x < @list_size
        pos = 0
        y = 0
        while y < @list[x].size
          plain_char = charOf(@list[x][y])

          pos += 1
          if charOf(pattern[pos-1]) != plain_char
            y -= (pos - 1)
            pos = 0
          elsif pos == pattern.size
            @current_top = [x, @max_top_line].min
            @left_char = if y < @box_width then 0 else @max_left_char end
            found = true
            break
          end
          y += 1
        end
        x += 1
      end
    else
      # Start looking from 'here' up.
      x = @current_top - 1
      while ! found && x >= 0
        y = 0
        pos = 0
        while y < @list[x].size
          plain_char = charOf(@list[x][y])

          pos += 1
          if charOf(pattern[pos-1]) != plain_char
            y -= (pos - 1)
            pos = 0
          elsif pos == pattern.size
            @current_top = x
            @left_char = if y < @box_width then 0 else @max_left_char end
            found = true
            break
          end
        end
      end
    end
  end
  return found
end

#set(title, list, list_size, button_highlight, attr_interp, show_line_info, box) ⇒ Object

This function sets various attributes of the widget.



112
113
114
115
116
117
118
119
# File 'lib/cdk/components/viewer.rb', line 112

def set(title, list, list_size, button_highlight,
    attr_interp, show_line_info, box)
  self.setTitle(title)
  self.setHighlight(button_highlight)
  self.setInfoLine(show_line_info)
  self.setBox(box)
  return self.setInfo(list, list_size, attr_interp)
end

#setBKattr(attrib) ⇒ Object

This sets the background attribute of the widget.



675
676
677
# File 'lib/cdk/components/viewer.rb', line 675

def setBKattr(attrib)
  @win.wbkgd(attrib)
end

#setHighlight(button_highlight) ⇒ Object

This function sets the highlight type of the buttons.



282
283
284
# File 'lib/cdk/components/viewer.rb', line 282

def setHighlight(button_highlight)
  @button_highlight = button_highlight
end

#setInfo(list, list_size, interpret) ⇒ Object

This function sets the contents of the viewer.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/cdk/components/viewer.rb', line 177

def setInfo(list, list_size, interpret)
  current_line = 0
  viewer_size = list_size

  if list_size < 0
    list_size = list.size
  end

  # Compute the size of the resulting display
  viewer_size = list_size
  if list.size > 0 && interpret
    (0...list_size).each do |x|
      filename = ''
      if check_for_link(list[x], filename) == 1
        file_contents = []
        file_len = CDK.readFile(filename, file_contents)

        if file_len >= 0
          viewer_size += (file_len - 1)
        end
      end
    end
  end

  # Clean out the old viewer info. (if there is any)
  @in_progress = true
  self.clean
  self.createList(viewer_size)

  # Keep some semi-permanent info
  @interpret = interpret

  # Copy the information given.
  current_line = 0
  x = 0
  while x < list_size && current_line < viewer_size
    if list[x].size == 0
      @list[current_line] = ''
      @list_len[current_line] = 0
      @list_pos[current_line] = 0
      current_line += 1
    else
      # Check if we have a file link in this line.
      filename = []
      if check_for_link(list[x], filename) == 1
        # We have a link, open the file.
        file_contents = []
        file_len = 0

        # Open the file and put it into the viewer
        file_len = CDK.readFile(filename, file_contents)
        if file_len == -1
          fopen_fmt = if Ncurses.has_colors?
                      then '<C></16>Link Failed: Could not open the file %s'
                      else '<C></K>Link Failed: Could not open the file %s'
                      end
          temp = fopen_fmt % filename
          self.setupLine(true, temp, current_line)
          current_line += 1
        else
          # For each line read, copy it into the viewer.
          file_len = [file_len, viewer_size - current_line].min
          (0...file_len).each do |file_line|
            if current_line >= viewer_size
              break
            end
            self.setupLine(false, file_contents[file_line], current_line)
            @characters += @list_len[current_line]
            current_line += 1
          end
        end
      elsif current_line < viewer_size
        self.setupLine(@interpret, list[x], current_line)
        @characters += @list_len[current_line]
        current_line += 1
      end
    end
    x+= 1
  end

  # Determine how many characters we can shift to the right before
  # all the items have been viewer off the screen.
  if @widest_line > @box_width
    @max_left_char = (@widest_line - @box_width) + 1
  else
    @max_left_char = 0
  end

  # Set up the needed vars for the viewer list.
  @in_progress = false
  @list_size = viewer_size
  if @list_size <= @view_size
    @max_top_line = 0
  else
    @max_top_line = @list_size - 1
  end
  return @list_size
end

#setInfoLine(show_line_info) ⇒ Object

This sets whether or not you wnat to set the viewer info line.



291
292
293
# File 'lib/cdk/components/viewer.rb', line 291

def setInfoLine(show_line_info)
  @show_line_info = show_line_info
end

#setTitle(title) ⇒ Object

This sets the title of the viewer. (A nil title is allowed. It just means that the viewer will not have a title when drawn.)



123
124
125
126
127
128
129
# File 'lib/cdk/components/viewer.rb', line 123

def setTitle(title)
  super(title, -(@box_width + 1))
  @title_adj = @title_lines

  # Need to set @view_size
  @view_size = @box_height - (@title_lines + 1) - 2
end

#setupLine(interpret, list, x) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/cdk/components/viewer.rb', line 135

def setupLine(interpret, list, x)
  # Did they ask for attribute interpretation?
  if interpret
    list_len = []
    list_pos = []
    @list[x] = char2Chtype(list, list_len, list_pos)
    @list_len[x] = list_len[0]
    @list_pos[x] = justify_string(@box_width, @list_len[x], list_pos[0])
  else
    # We must convert tabs and other nonprinting characters. The curses
    # library normally does this, but we are bypassing it by writing
    # chtypes directly.
    t = ''
    len = 0
    (0...list.size).each do |y|
      if list[y] == "\t".ord
        begin
          t  << ' '
          len += 1
        end while (len & 7) != 0
      elsif charOf(list[y].ord).match(/^[[:print:]]$/)
        t << charOf(list[y].ord)
        len += 1
      else
        t << Ncurses.unctrl(list[y].ord)
        len += 1
      end
    end
    @list[x] = t
    @list_len[x] = t.size
    @list_pos[x] = 0
  end
  @widest_line = [@widest_line, @list_len[x]].max
end