Module: CDK

Defined in:
lib/cdk.rb,
lib/cdk/draw.rb,
lib/cdk/screen.rb,
lib/cdk/display.rb,
lib/cdk/cdk_objs.rb,
lib/cdk/traverse.rb,
lib/cdk/constants.rb,
lib/cdk/helpers/file.rb,
lib/cdk/helpers/types.rb,
lib/cdk/helpers/window.rb,
lib/cdk/mixins/borders.rb,
lib/cdk/components/menu.rb,
lib/cdk/mixins/bindings.rb,
lib/cdk/mixins/movement.rb,
lib/cdk/components/entry.rb,
lib/cdk/components/graph.rb,
lib/cdk/components/label.rb,
lib/cdk/components/radio.rb,
lib/cdk/components/scale.rb,
lib/cdk/mixins/focusable.rb,
lib/cdk/mixins/has_title.rb,
lib/cdk/components/button.rb,
lib/cdk/components/dialog.rb,
lib/cdk/components/dscale.rb,
lib/cdk/components/fscale.rb,
lib/cdk/components/matrix.rb,
lib/cdk/components/mentry.rb,
lib/cdk/components/scroll.rb,
lib/cdk/components/slider.rb,
lib/cdk/components/uscale.rb,
lib/cdk/components/viewer.rb,
lib/cdk/mixins/alignments.rb,
lib/cdk/mixins/converters.rb,
lib/cdk/mixins/has_screen.rb,
lib/cdk/components/fselect.rb,
lib/cdk/components/fslider.rb,
lib/cdk/components/marquee.rb,
lib/cdk/components/swindow.rb,
lib/cdk/components/uslider.rb,
lib/cdk/mixins/formattable.rb,
lib/cdk/components/calendar.rb,
lib/cdk/components/itemlist.rb,
lib/cdk/components/scroller.rb,
lib/cdk/components/template.rb,
lib/cdk/mixins/list_support.rb,
lib/cdk/mixins/window_hooks.rb,
lib/cdk/mixins/window_input.rb,
lib/cdk/components/alphalist.rb,
lib/cdk/components/buttonbox.rb,
lib/cdk/components/histogram.rb,
lib/cdk/components/selection.rb,
lib/cdk/mixins/justifications.rb,
lib/cdk/mixins/common_controls.rb,
lib/cdk/mixins/exit_conditions.rb

Defined Under Namespace

Modules: Alignments, Bindings, Borders, CommonControls, Converters, Display, Draw, ExitConditions, Focusable, Formattable, HasScreen, HasTitle, Justifications, ListSupport, Movement, Traverse, WindowHooks, WindowInput 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

ALL_SCREENS =

some useful global values

[]
ALL_OBJECTS =
[]
VERSION_MAJOR =
0
VERSION_MINOR =
10
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 =
CTRL('L')
PASTE =
CTRL('V')
COPY =
CTRL('Y')
ERASE =
CTRL('U')
CUT =
CTRL('X')
BEGOFLINE =
CTRL('A')
ENDOFLINE =
CTRL('E')
BACKCHAR =
CTRL('B')
FORCHAR =
CTRL('F')
TRANSPOSE =
CTRL('T')
NEXT =
CTRL('N')
PREV =
CTRL('P')
DELETE =
"\177".ord
KEY_ESC =
"\033".ord
KEY_RETURN =
"\012".ord
KEY_TAB =
"\t".ord

Class Method Summary collapse

Class Method Details

.alpha?(character) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/cdk/helpers/types.rb', line 6

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

.BeepObject

This beeps then flushes the stdout stream



49
50
51
52
# File 'lib/cdk.rb', line 49

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

.CTRL(c) ⇒ Object



28
29
30
# File 'lib/cdk/constants.rb', line 28

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

.deleteCursesWindow(window) ⇒ Object

This safely deletes a given window.



11
12
13
14
15
16
# File 'lib/cdk/helpers/window.rb', line 11

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

  eraseCursesWindow(window)
  window.delwin
end

.digit?(character) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/cdk/helpers/types.rb', line 2

def self.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



40
41
42
# File 'lib/cdk/helpers/file.rb', line 40

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

.eraseCursesWindow(window) ⇒ Object

This safely erases a given window



3
4
5
6
7
8
# File 'lib/cdk/helpers/window.rb', line 3

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

  window.werase
  SCREEN.wrefresh(window)
end

.getDirectoryContents(directory, list) ⇒ Object

This opens the current directory and reads the contents.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cdk/helpers/file.rb', line 23

def self.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

.isChar(c) ⇒ Object



10
11
12
# File 'lib/cdk/helpers/types.rb', line 10

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

.KEY_F(n) ⇒ Object



54
55
56
# File 'lib/cdk.rb', line 54

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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cdk/helpers/window.rb', line 20

def self.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.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cdk/helpers/file.rb', line 3

def self.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

.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.



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

def self.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



49
50
51
52
53
# File 'lib/cdk/constants.rb', line 49

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