Module: CDK

Defined in:
lib/cdk.rb,
lib/cdk/draw.rb,
lib/cdk/menu.rb,
lib/cdk/entry.rb,
lib/cdk/label.rb,
lib/cdk/radio.rb,
lib/cdk/scale.rb,
lib/cdk/dialog.rb,
lib/cdk/dscale.rb,
lib/cdk/fscale.rb,
lib/cdk/matrix.rb,
lib/cdk/mentry.rb,
lib/cdk/screen.rb,
lib/cdk/scroll.rb,
lib/cdk/slider.rb,
lib/cdk/uscale.rb,
lib/cdk/viewer.rb,
lib/cdk/display.rb,
lib/cdk/fselect.rb,
lib/cdk/fslider.rb,
lib/cdk/marquee.rb,
lib/cdk/swindow.rb,
lib/cdk/uslider.rb,
lib/cdk/calendar.rb,
lib/cdk/cdk_objs.rb,
lib/cdk/itemlist.rb,
lib/cdk/scroller.rb,
lib/cdk/template.rb,
lib/cdk/traverse.rb,
lib/cdk/alphalist.rb,
lib/cdk/buttonbox.rb,
lib/cdk/histogram.rb,
lib/cdk/selection.rb

Defined Under Namespace

Modules: Display, Draw, Traverse Classes: ALPHALIST, BUTTON, BUTTONBOX, CALENDAR, CDKOBJS, DIALOG, DSCALE, ENTRY, FSCALE, FSELECT, FSLIDER, GRAPH, HISTOGRAM, ITEMLIST, LABEL, MARQUEE, MATRIX, MENTRY, MENU, RADIO, SCALE, SCREEN, SCROLL, SCROLLER, SELECTION, SLIDER, SWINDOW, TEMPLATE, USCALE, USLIDER, VIEWER

Constant Summary collapse

VERSION_MAJOR =
0
VERSION_MINOR =
9
VERSION_PATCH =
0
CDK_PATHMAX =
256
L_MARKER =
'<'
R_MARKER =
'>'
LEFT =
9000
RIGHT =
9001
CENTER =
9002
TOP =
9003
BOTTOM =
9004
HORIZONTAL =
9005
VERTICAL =
9006
FULL =
9007
NONE =
0
ROW =
1
COL =
2
MAX_BINDINGS =
300
MAX_ITEMS =
2000
MAX_BUTTONS =
200
REFRESH =
CDK.CTRL('L')
PASTE =
CDK.CTRL('V')
COPY =
CDK.CTRL('Y')
ERASE =
CDK.CTRL('U')
CUT =
CDK.CTRL('X')
BEGOFLINE =
CDK.CTRL('A')
ENDOFLINE =
CDK.CTRL('E')
BACKCHAR =
CDK.CTRL('B')
FORCHAR =
CDK.CTRL('F')
TRANSPOSE =
CDK.CTRL('T')
NEXT =
CDK.CTRL('N')
PREV =
CDK.CTRL('P')
DELETE =
"\177".ord
KEY_ESC =
"\033".ord
KEY_RETURN =
"\012".ord
KEY_TAB =
"\t".ord
ALL_SCREENS =
[]
ALL_OBJECTS =
[]

Class Method Summary collapse

Class Method Details

.alignxy(window, xpos, ypos, box_width, box_height) ⇒ Object

This takes an x and y position and realigns the values iff they sent in values like CENTER, LEFT, RIGHT

window is an Ncurses::WINDOW object xpos, ypos is an array with exactly one value, an integer box_width, box_height is an integer



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
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/cdk.rb', line 137

def CDK.alignxy (window, xpos, ypos, box_width, box_height)
  first = window.getbegx
  last = window.getmaxx
  if (gap = (last - box_width)) < 0
    gap = 0
  end
  last = first + gap

  case xpos[0]
  when LEFT
    xpos[0] = first
  when RIGHT
    xpos[0] = first + gap
  when CENTER
    xpos[0] = first + (gap / 2)
  else
    if xpos[0] > last
      xpos[0] = last
    elsif xpos[0] < first
      xpos[0] = first
    end
  end

  first = window.getbegy
  last = window.getmaxy
  if (gap = (last - box_height)) < 0
    gap = 0
  end
  last = first + gap

  case ypos[0]
  when TOP
    ypos[0] = first
  when BOTTOM
    ypos[0] = first + gap
  when CENTER
    ypos[0] = first + (gap / 2)
  else
    if ypos[0] > last
      ypos[0] = last
    elsif ypos[0] < first
      ypos[0] = first
    end
  end
end

.alpha?(character) ⇒ Boolean

Returns:

  • (Boolean)


765
766
767
# File 'lib/cdk.rb', line 765

def CDK.alpha?(character)
  !(character.match(/^[[:alpha:]]$/).nil?)
end

.baseName(pathname) ⇒ Object

Returns the filename portion of the given pathname, i.e. after the last slash For now this function is just a wrapper for File.basename kept for ease of porting and will be completely replaced in the future



688
689
690
# File 'lib/cdk.rb', line 688

def CDK.baseName (pathname)
  File.basename(pathname)
end

.BeepObject

This beeps then flushes the stdout stream



117
118
119
120
# File 'lib/cdk.rb', line 117

def CDK.Beep
  Ncurses.beep
  $stdout.flush
end

.char2Chtype(string, to, align) ⇒ Object

This function takes a string, full of format markers and translates them into a chtype array. This is better suited to curses because curses uses chtype almost exclusively



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
508
509
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.rb', line 344

def CDK.char2Chtype (string, to, align)
  to << 0
  align << LEFT
  result = []

  if string.size > 0
    used = 0

    # The original code makes two passes since it has to pre-allocate space but
    # we should be able to make do with one since we can dynamically size it
    adjust = 0
    attrib = Ncurses::A_NORMAL
    last_char = 0
    start = 0
    used = 0
    x = 3

    # Look for an alignment marker.
    if string[0] == L_MARKER
      if string[1] == 'C' && string[2] == R_MARKER
        align[0] = CENTER
        start = 3
      elsif string[1] == 'R' && string[2] == R_MARKER
        align[0] = RIGHT
        start = 3
      elsif string[1] == 'L' && string[2] == R_MARKER
        start = 3
      elsif string[1] == 'B' && string[2] == '='
        # Set the item index value in the string.
        result = [' '.ord, ' '.ord, ' '.ord]

        # Pull out the bullet marker.
        while x < string.size and string[x] != R_MARKER
          result << (string[x].ord | Ncurses::A_BOLD)
          x += 1
        end
        adjust = 1

        # Set the alignment variables
        start = x
        used = x
      elsif string[1] == 'I' && string[2] == '='
        from = 3
        x = 0

        while from < string.size && string[from] != Ncurses.R_MARKER
          if CDK.digit?(string[from])
            adjust = adjust * 10 + string[from].to_i
            x += 1
          end
          from += 1
        end

        start = x + 4
      end
    end
    
    while adjust > 0
      adjust -= 1
      result << ' '
      used += 1
    end

    # Set the format marker boolean to false
    inside_marker = false

    # Start parsing the character string.
    from = start
    while from < string.size
      # Are we inside a format marker?
      if !inside_marker
        if string[from] == L_MARKER &&
            ['/', '!', '#'].include?(string[from + 1])
          inside_marker = true
        elsif string[from] == "\\" && string[from + 1] == L_MARKER
          from += 1
          result << (string[from].ord | attrib)
          used += 1
          from += 1
        elsif string[from] == "\t"
          begin
            result << ' '
            used += 1
          end while (used & 7).nonzero?
        else
          result << (string[from].ord | attrib)
          used += 1
        end
      else
        case string[from]
        when R_MARKER
          inside_marker = false
        when '#'
          last_char = 0
          case string[from + 2]
          when 'L'
            case string[from + 1]
            when 'L'
              last_char = Ncurses::ACS_LLCORNER
            when 'U'
              last_char = Ncurses::ACS_ULCORNER
            when 'H'
              last_char = Ncurses::ACS_HLINE
            when 'V'
              last_char = Ncurses::ACS_VLINE
            when 'P'
              last_char = Ncurses::ACS_PLUS
            end
          when 'R'
            case string[from + 1]
            when 'L'
              last_char = Ncurses::ACS_LRCORNER
            when 'U'
              last_char = Ncurses::ACS_URCORNER
            end
          when 'T'
            case string[from + 1]
            when 'T'
              last_char = Ncurses::ACS_TTEE
            when 'R'
              last_char = Ncurses::ACS_RTEE
            when 'L'
              last_char = Ncurses::ACS_LTEE
            when 'B'
              last_char = Ncurses::ACS_BTEE
            end
          when 'A'
            case string[from + 1]
            when 'L'
              last_char = Ncurses::ACS_LARROW
            when 'R'
              last_char = Ncurses::ACS_RARROW
            when 'U'
              last_char = Ncurses::ACS_UARROW
            when 'D'
              last_char = Ncurses::ACS_DARROW
            end
          else
            case [string[from + 1], string[from + 2]]
            when ['D', 'I']
              last_char = Ncurses::ACS_DIAMOND
            when ['C', 'B']
              last_char = Ncurses::ACS_CKBOARD
            when ['D', 'G']
              last_char = Ncurses::ACS_DEGREE
            when ['P', 'M']
              last_char = Ncurses::ACS_PLMINUS
            when ['B', 'U']
              last_char = Ncurses::ACS_BULLET
            when ['S', '1']
              last_char = Ncurses::ACS_S1
            when ['S', '9']
              last_char = Ncurses::ACS_S9
            end
          end

          if last_char.nonzero?
            adjust = 1
            from += 2

            if string[from + 1] == '('
              # check for a possible numeric modifier
              from += 2
              adjust = 0

              while from < string.size && string[from] != ')'
                if CDK.digit?(string[from])
                  adjust = (adjust * 10) + string[from].to_i
                end
                from += 1
              end
            end
          end
          (0...adjust).each do |x|
            result << (last_char | attrib)
            used += 1
          end
        when '/'
          mask = []
          from = CDK.encodeAttribute(string, from, mask)
          attrib |= mask[0]
        when '!'
          mask = []
          from = CDK.encodeAttribute(string, from, mask)
          attrib &= ~(mask[0])
        end
      end
      from += 1
    end

    if result.size == 0
      result << attrib
    end
    to[0] = used
  else
    result = []
  end
  return result
end

.CharOf(chtype) ⇒ Object



575
576
577
# File 'lib/cdk.rb', line 575

def CDK.CharOf(chtype)
  (chtype.ord & 255).chr
end

This function checks to see if a link has been requested



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/cdk.rb', line 661

def CDK.checkForLink (line, filename)
  f_pos = 0
  x = 3
  if line.nil?
    return -1
  end

  # Strip out the filename.
  if line[0] == L_MARKER && line[1] == 'F' && line[2] == '='
    while x < line.size
      if line[x] == R_MARKER
        break
      end
      if f_pos < CDK_PATHMAX
        filename << line[x]
        f_pos += 1
      end
      x += 1
    end
  end
  return f_pos != 0
end

.chtype2Char(string) ⇒ Object

This returns a string from a chtype array Formatting codes are omitted.



581
582
583
584
585
586
587
588
589
590
591
# File 'lib/cdk.rb', line 581

def CDK.chtype2Char(string)
  newstring = ''
  
  unless string.nil?
    string.each do |char|
      newstring << CDK.CharOf(char)
    end
  end

  return newstring
end

.chtype2String(string) ⇒ Object

This returns a string from a chtype array Formatting codes are embedded



595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/cdk.rb', line 595

def CDK.chtype2String(string)
  newstring = ''
  unless string.nil?
    need = 0
    (0...string.size).each do |x|
      need = CDK.decodeAttribute(newstring, need,
                                 x > 0 ? string[x - 1] : 0, string[x])
      newstring << string[x]
    end
  end

  return newstring
end

.cleanChar(s, len, character) ⇒ Object

This sets a blank string to be len of the given characer.



123
124
125
# File 'lib/cdk.rb', line 123

def CDK.cleanChar(s, len, character)
  s << character * len
end

.cleanChtype(s, len, character) ⇒ Object



127
128
129
# File 'lib/cdk.rb', line 127

def CDK.cleanChtype(s, len, character)
  s.concat(character * len)
end

.cmpStrChstr(str, chstr) ⇒ Object

Compare a regular string to a chtype string



545
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
# File 'lib/cdk.rb', line 545

def CDK.cmpStrChstr (str, chstr)
  i = 0
  r = 0

  if str.nil? && chstr.nil?
    return 0
  elsif str.nil?
    return 1
  elsif chstr.nil?
    return -1
  end

  while i < str.size && i < chstr.size
    if str[r].ord < chstr[r]
      return -1
    elsif str[r].ord > chstr[r]
      return 1
    end
    i += 1
  end

  if str.size < chstr.size
    return -1
  elsif str.size > chstr.size
    return 1
  else
    return 0
  end
end

.CTRL(c) ⇒ Object

some useful global values



66
67
68
# File 'lib/cdk.rb', line 66

def CDK.CTRL(c)
  c.ord & 0x1f
end

.decodeAttribute(string, from, oldattr, newattr) ⇒ Object

The reverse of encodeAttribute Well, almost. If attributes such as bold and underline are combined in the same string, we do not necessarily reconstruct them in the same order. Also, alignment markers and tabs are lost.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/cdk.rb', line 276

def CDK.decodeAttribute (string, from, oldattr, newattr)
  table = {
    'B' => Ncurses::A_BOLD,
    'D' => Ncurses::A_DIM,
    'K' => Ncurses::A_BLINK,
    'R' => Ncurses::A_REVERSE,
    'S' => Ncurses::A_STANDOUT,
    'U' => Ncurses::A_UNDERLINE
  }

  result = if string.nil? then '' else string end
  base_len = result.size
  tmpattr = oldattr & Ncurses::A_ATTRIBUTES

  newattr &= Ncurses::A_ATTRIBUTES
  if tmpattr != newattr
    while tmpattr != newattr
      found = false
      table.keys.each do |key|
        if (table[key] & tmpattr) != (table[key] & newattr)
          found = true
          result << CDK::L_MARKER
          if (table[key] & tmpattr).nonzero?
            result << '!'
            tmpattr &= ~(table[key])
          else
            result << '/'
            tmpattr |= table[key]
          end
          result << key
          break
        end
      end
      # XXX: Only checks if terminal has colours not if colours are started
      if Ncurses.has_colors?
        if (tmpattr & Ncurses::A_COLOR) != (newattr & Ncurses::A_COLOR)
          oldpair = Ncurses.PAIR_NUMBER(tmpattr)
          newpair = Ncurses.PAIR_NUMBER(newattr)
          if !found
            found = true
            result << CDK::L_MARKER
          end
          if newpair.zero?
            result << '!'
            result << oldpair.to_s
          else
            result << '/'
            result << newpair.to_s
          end
          tmpattr &= ~(Ncurses::A_COLOR)
          newattr &= ~(Ncurses::A_COLOR)
        end
      end

      if found
        result << CDK::R_MARKER
      else
        break
      end
    end
  end

  return from + result.size - base_len
end

.deleteCursesWindow(window) ⇒ Object

This safely deletes a given window.



736
737
738
739
740
741
# File 'lib/cdk.rb', line 736

def CDK.deleteCursesWindow (window)
  return if window.nil?

  CDK.eraseCursesWindow(window)
  window.delwin
end

.digit?(character) ⇒ Boolean

Returns:

  • (Boolean)


761
762
763
# File 'lib/cdk.rb', line 761

def CDK.digit?(character)
  !(character.match(/^[[:digit:]]$/).nil?)
end

.dirName(pathname) ⇒ Object

Returns the directory for the given pathname, i.e. the part before the last slash For now this function is just a wrapper for File.dirname kept for ease of porting and will be completely replaced in the future



696
697
698
# File 'lib/cdk.rb', line 696

def CDK.dirName (pathname)
  File.dirname(pathname)
end

.encodeAttribute(string, from, mask) ⇒ Object



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
# File 'lib/cdk.rb', line 227

def CDK.encodeAttribute (string, from, mask)
  mask << 0
  case string[from + 1]
  when 'B'
    mask[0] = Ncurses::A_BOLD
  when 'D'
    mask[0] = Ncurses::A_DIM
  when 'K'
    mask[0] = Ncurses::A_BLINK
  when 'R'
    mask[0] = Ncurses::A_REVERSE
  when 'S'
    mask[0] = Ncurses::A_STANDOUT
  when 'U'
    mask[0] = Ncurses::A_UNDERLINE
  end

  if mask[0] != 0
    from += 1
  elsif CDK.digit?(string[from+1]) and CDK.digit?(string[from + 2])
    if Ncurses.has_colors?
      # XXX: Only checks if terminal has colours not if colours are started
      pair = string[from + 1..from + 2].to_i
      mask[0] = Ncurses.COLOR_PAIR(pair)
    else
      mask[0] = Ncurses.A_BOLD
    end

    from += 2
  elsif CDK.digit?(string[from + 1])
    if Ncurses.has_colors?
      # XXX: Only checks if terminal has colours not if colours are started
      pair = string[from + 1].to_i
      mask[0] = Ncurses.COLOR_PAIR(pair)
    else
      mask[0] = Ncurses.A_BOLD
    end

    from += 1
  end

  return from
end

.eraseCursesWindow(window) ⇒ Object

This safely erases a given window



728
729
730
731
732
733
# File 'lib/cdk.rb', line 728

def CDK.eraseCursesWindow (window)
  return if window.nil?

  window.werase
  window.wrefresh
end

.getDirectoryContents(directory, list) ⇒ Object

This opens the current directory and reads the contents.



619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/cdk.rb', line 619

def CDK.getDirectoryContents(directory, list)
  counter = 0

  # Open the directory.
  Dir.foreach(directory) do |filename|
    next if filename == '.'
    list << filename
  end

  list.sort!
  return list.size
end

.getListindex(screen, title, list, list_size, numbers) ⇒ Object

This returns a selected value in a list



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
# File 'lib/cdk.rb', line 829

def CDK.getListindex(screen, title, list, list_size, numbers)
  selected = -1
  height = 10
  width = -1
  len = 0

  # Determine the height of the list.
  if list_size < 10
    height = list_size + if title.size == 0 then 2 else 3 end
  end

  # Determine the width of the list.
  list.each do |item|
    width = [width, item.size + 10].max
  end

  width = [width, title.size].max
  width += 5

  # Create the scrolling list.
  scrollp = CDK::SCROLL.new(screen, CDK::CENTER, CDK::CENTER, CDK::RIGHT,
      height, width, title, list, list_size, numbers, Ncurses::A_REVERSE,
      true, false)

  # Check if we made the lsit.
  if scrollp.nil?
    screen.refresh
    return -1
  end

  # Let the user play.
  selected = scrollp.activate([])

  # Check how they exited.
  if scrollp.exit_type != :NORMAL
    selected = -1
  end

  # Clean up.
  scrollp.destroy
  screen.refresh
  return selected
end

.getString(screen, title, label, init_value) ⇒ Object



782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/cdk.rb', line 782

def CDK.getString(screen, title, label, init_value)
  # Create the widget.
  widget = CDK::ENTRY.new(screen, CDK::CENTER, CDK::CENTER, title, label,
      Ncurses::A_NORMAL, '.', :MIXED, 40, 0, 5000, true, false)

  # Set the default value.
  widget.setValue(init_value)

  # Get the string.
  value = widget.activate([])

  # Make sure they exited normally.
  if widget.exit_type != :NORMAL
    widget.destroy
    return nil
  end

  # Return a copy of the string typed in.
  value = entry.getValue.clone
  widget.destroy
  return value
end

.intlen(value) ⇒ Object

This returns the length of the integer.

Currently a wrapper maintained for easy of porting.



614
615
616
# File 'lib/cdk.rb', line 614

def CDK.intlen (value)
  value.to_str.size
end

.isChar(c) ⇒ Object



769
770
771
# File 'lib/cdk.rb', line 769

def CDK.isChar(c)
  c >= 0 && c < Ncurses::KEY_MIN
end

.justifyString(box_width, mesg_length, justify) ⇒ Object

This takes a string, a field width, and a justification type and returns the adjustment to make, to fill the justification requirement



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/cdk.rb', line 186

def CDK.justifyString (box_width, mesg_length, justify)

  # make sure the message isn't longer than the width
  # if it is, return 0
  if mesg_length >= box_width
    return 0
  end

  # try to justify the message
  case justify
  when LEFT
    0
  when RIGHT
    box_width - mesg_length
  when CENTER
    (box_width - mesg_length) / 2
  else
    justify
  end
end

.KEY_F(n) ⇒ Object



773
774
775
# File 'lib/cdk.rb', line 773

def CDK.KEY_F(n)
  264 + n
end

.moveCursesWindow(window, xdiff, ydiff) ⇒ Object

This moves a given window (if we’re able to set the window’s beginning). We do not use mvwin(), because it does not (usually) move subwindows.



745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/cdk.rb', line 745

def CDK.moveCursesWindow (window, xdiff, ydiff)
  return if window.nil?

  xpos = []
  ypos = []
  window.getbegyx(ypos, xpos)
  if window.mvwin(ypos[0], xpos[0]) != Ncurses::ERR
    xpos[0] += xdiff
    ypos[0] += ydiff
    window.werase
    window.mvwin(ypos[0], xpos[0])
  else
    CDK.Beep
  end
end

.readFile(filename, array) ⇒ Object

This reads a file and sticks it into the list provided.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/cdk.rb', line 208

def CDK.readFile(filename, array)
  begin
    fd = File.new(filename, "r")
  rescue
    return -1
  end

  lines = fd.readlines.map do |line|
    if line.size > 0 && line[-1] == "\n"
      line[0...-1]
    else
      line
    end
  end
  array.concat(lines)
  fd.close
  array.size
end

.searchList(list, list_size, pattern) ⇒ Object

This looks for a subset of a word in the given list



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/cdk.rb', line 633

def CDK.searchList(list, list_size, pattern)
  index = -1

  if pattern.size > 0
    (0...list_size).each do |x|
      len = [list[x].size, pattern.size].min
      ret = (list[x][0...len] <=> pattern)

      # If 'ret' is less than 0 then the current word is alphabetically
      # less than the provided word.  At this point we will set the index
      # to the current position.  If 'ret' is greater than 0, then the
      # current word is alphabetically greater than the given word. We
      # should return with index, which might contain the last best match.
      # If they are equal then we've found it.
      if ret < 0
        index = ret
      else
        if ret == 0
          index = x
        end
        break
      end
    end
  end
  return index
end

.selectFile(screen, title) ⇒ Object

This allows a person to select a file.



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
# File 'lib/cdk.rb', line 806

def CDK.selectFile(screen, title)
  # Create the file selector.
  fselect = CDK::FSELECT.new(screen, CDK::CENTER, CDK::CENTER, -4, -20,
      title, 'File: ', Ncurses::A_NORMAL, '_', Ncurses::A_REVERSE,
      '</5>', '</48>', '</N>', '</N>', true, false)

  # Let the user play.
  filename = fselect.activate([])

  # Check the way the user exited the selector.
  if fselect.exit_type != :NORMAL
    fselect.destroy
    screen.refresh
    return nil
  end

  # Otherwise...
  fselect.destroy
  screen.refresh
  return filename
end

.setWidgetDimension(parent_dim, proposed_dim, adjustment) ⇒ Object

If the dimension is a negative value, the dimension will be the full height/width of the parent window - the value of the dimension. Otherwise, the dimension will be the given value.



703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/cdk.rb', line 703

def CDK.setWidgetDimension (parent_dim, proposed_dim, adjustment)
  # If the user passed in FULL, return the parents size
  if proposed_dim == FULL or proposed_dim == 0
    parent_dim
  elsif proposed_dim >= 0
    # if they gave a positive value, return it

    if proposed_dim >= parent_dim
      parent_dim
    else
      proposed_dim + adjustment
    end
  else
    # if they gave a negative value then return the dimension
    # of the parent plus the value given
    #
    if parent_dim + proposed_dim < 0
      parent_dim
    else
      parent_dim + proposed_dim
    end
  end
end

.VersionObject



777
778
779
780
# File 'lib/cdk.rb', line 777

def CDK.Version
  return "%d.%d.%d" %
      [CDK::VERSION_MAJOR, CDK::VERSION_MINOR, CDK::VERSION_PATCH]
end

.viewFile(screen, title, filename, buttons, button_count) ⇒ Object

This allows the user to view a file.



900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/cdk.rb', line 900

def CDK.viewFile(screen, title, filename, buttons, button_count)
  info = []
  result = 0

  # Open the file and read the contents.
  lines = CDK.readFile(filename, info)

  # If we couldn't read the file, return an error.
  if lines == -1
    result = lines
  else
    result = CDK.viewInfo(screen, title, info, lines, buttons,
        button_count, true)
  end
  return result
end

.viewInfo(screen, title, info, count, buttons, button_count, interpret) ⇒ Object

This allows the user to view information.



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/cdk.rb', line 874

def CDK.viewInfo(screen, title, info, count, buttons, button_count,
    interpret)
  selected = -1

  # Create the file viewer to view the file selected.
  viewer = CDK::VIEWER.new(screen, CDK::CENTER, CDK::CENTER, -6, -16,
      buttons, button_count, Ncurses::A_REVERSE, true, true)

  # Set up the viewer title, and the contents to the widget.
  viewer.set(title, info, count, Ncurses::A_REVERSE, interpret, true, true)

  # Activate the viewer widget.
  selected = viewer.activate([])

  # Make sure they exited normally.
  if viewer.exit_type != :NORMAL
    viewer.destroy
    return -1
  end

  # Clean up and return the button index selected
  viewer.destroy
  return selected
end