class Canis::KeyLabelPrinter

This paints labels for various keys at the bottom of the screen, in 2 rows. This is based on alpines last 2 rows. Modes are supported so that the labels change as you enter a widget. For an example, see dbdemo.rb or rfe.rb NOTE: applications using 'App' use a shortcut “dock” to create this.

The most minimal keylabel to print one label in first row, and none in second is:

[["F1", "Help"], nil]

To print 2 labels, one over the other:

[["F1", "Help"], ["F10", "Quit"]]

Attributes

key_labels[R]

Public Class Methods

new(form, key_labels, config={}) click to toggle source

attr_accessor :row_relative # lets only advertise this when we've tested it out

Calls superclass method
# File lib/canis/core/widgets/keylabelprinter.rb, line 28
def initialize form, key_labels, config={}, &block

  @name = "dock"
  case key_labels
  when Hash
    raise "KeyLabelPrinter: KeyLabels cannot be a hash, Array of key labels required. Perhaps you did not pass labels"
  when Array
  else
    raise "KeyLabelPrinter: Array of key labels required. Perhaps you did not pass labels"
  end
  super form, config, &block
  @mode ||= :normal
  #@key_labels = key_labels
  @key_hash = {}
  @key_hash[@mode] = key_labels
  @editable = false
  @focusable = false
  unless @row
    @row_relative = -2
    @row = Ncurses.LINES + @row_relative
  end
  @col ||= 0
  # if negativ row passed we store as relative to bottom, so we can maintain that.
  if @row < 0
    @row_relative = @row
    @row = Ncurses.LINES - @row
  else
    @row_relative = (Ncurses.LINES - @row) * -1
  end
  @cols ||= Ncurses.COLS-1
  @repaint_required = true
  @footer_color_pair ||= $bottomcolor
  @footer_mnemonic_color_pair ||= $reversecolor #2
end

Public Instance Methods

append_key_label(key, label, mode=@mode) click to toggle source

?? does not use mode, i think key_labels is unused. a hash is now used 2011-10-11 XXX FIXME WARNING, i have not tested this after changing it.

# File lib/canis/core/widgets/keylabelprinter.rb, line 96
def append_key_label key, label, mode=@mode
  #@key_labels << [key, label] if !@key_labels.include? [key, label]
  @key_hash[mode] << [key, label] if !@key_hash[mode].include? [key, label]
  @repaint_required = true
end
get_current_keys() click to toggle source

returns the keys as printed. these may or may not help in validation depedign on what you passed as zeroth index

# File lib/canis/core/widgets/keylabelprinter.rb, line 67
def get_current_keys
  a = []
  @key_hash[@mode].each do |arr|
    a << arr[0] unless arr.nil?
  end
  return a
end
getvalue() click to toggle source
# File lib/canis/core/widgets/keylabelprinter.rb, line 74
def getvalue
  @key_hash
end
insert_application_key_label(index, display_code, text) click to toggle source

inserts an application label at given index to add the key, use create_datakeys to add bindings remember to call restore_application_key_labels after updating/inserting

# File lib/canis/core/widgets/keylabelprinter.rb, line 187
def insert_application_key_label(index, display_code, text)
  @repaint_required = true
  labels = key_labels()
  labels.insert(index, [display_code , text] )
end
print_key_labels(arr = key_labels(), mode=@mode) click to toggle source
print_key_labels_row(posy, posx, arr) click to toggle source
repaint() click to toggle source

XXX need to move wrapping etc up and done once.

# File lib/canis/core/widgets/keylabelprinter.rb, line 83
def repaint
  return unless @repaint_required
  r,c = rowcol
  # this should only happen if there's a change in window
  if @row_relative
    @row = Ncurses.LINES+@row_relative
  end
  arr = key_labels()
  print_key_labels(arr, mode=@mode)
  @repaint_required = false
end
set_key_labels(_key_labels, mode=:normal) click to toggle source
# File lib/canis/core/widgets/keylabelprinter.rb, line 77
def set_key_labels _key_labels, mode=:normal
  @key_hash[mode] = _key_labels
end
update(display_code, new_display_code, text)
update_application_key_label(display_code, new_display_code, text) click to toggle source

updates existing label with a new one. @return true if updated, else false @example update “C-x”, “C-x”, “Disable”

# File lib/canis/core/widgets/keylabelprinter.rb, line 167
def update_application_key_label(display_code, new_display_code, text)
  @repaint_required = true
  labels = key_labels()
  raise "labels are nil !!!" unless labels
  labels.each_index do |ix|
    lab = labels[ix]
    next if lab.nil?
    if lab[0] == display_code
      labels[ix] = [new_display_code , text]
      $log.debug("updated #{labels[ix]}")
      return true
    end
  end
  return false
end
Also aliased as: update