Class: RubyCurses::KeyLabelPrinter
- Defined in:
- lib/rbcurse/keylabelprinter.rb
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary collapse
-
#key_labels(mode = @mode) ⇒ Object
readonly
Returns the value of attribute key_labels.
Attributes inherited from Widget
#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state
Instance Method Summary collapse
- #append_key_label(key, label, mode = @mode) ⇒ Object
-
#get_current_keys ⇒ Object
returns the keys as printed.
- #getvalue ⇒ Object
-
#initialize(form, key_labels, config = {}, &block) ⇒ KeyLabelPrinter
constructor
A new instance of KeyLabelPrinter.
-
#insert_application_key_label(index, display_code, text) ⇒ Object
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.
- #print_key_labels(arr = key_labels(), mode = @mode) ⇒ Object
- #print_key_labels_row(posy, posx, arr) ⇒ Object
-
#repaint ⇒ Object
XXX need to move wrapping etc up and done once.
- #set_key_labels(_key_labels, mode = :normal) ⇒ Object
-
#update_application_key_label(display_code, new_display_code, text) ⇒ Object
updates existing label with a new one.
Methods inherited from Widget
#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #getvalue_for_paint, #handle_key, #height, #height=, #hide, #init_vars, #is_double_buffered?, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(form, key_labels, config = {}, &block) ⇒ KeyLabelPrinter
Returns a new instance of KeyLabelPrinter.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rbcurse/keylabelprinter.rb', line 9 def initialize form, key_labels, config={}, &block super form, config, &block @mode ||= :normal #@key_labels = key_labels @key_hash = {} @key_hash[@mode] = key_labels @editable = false @focusable = false @cols ||= Ncurses.COLS-1 @row ||= Ncurses.LINES-3 @col ||= 0 @repaint_required = true @footer_color_pair ||= $bottomcolor @footer_mnemonic_color_pair ||= $reversecolor #2 end |
Instance Attribute Details
#key_labels(mode = @mode) ⇒ Object (readonly)
Returns the value of attribute key_labels.
6 7 8 |
# File 'lib/rbcurse/keylabelprinter.rb', line 6 def key_labels @key_labels end |
Instance Method Details
#append_key_label(key, label, mode = @mode) ⇒ Object
52 53 54 55 |
# File 'lib/rbcurse/keylabelprinter.rb', line 52 def append_key_label key, label, mode=@mode @key_labels << [key, label] if !@key_labels.include? [key, label] @repaint_required = true end |
#get_current_keys ⇒ Object
returns the keys as printed. these may or may not help in validation depedign on what you passed as zeroth index
30 31 32 33 34 35 36 |
# File 'lib/rbcurse/keylabelprinter.rb', line 30 def get_current_keys a = [] @key_hash[@mode].each do |arr| a << arr[0] unless arr.nil? end return a end |
#getvalue ⇒ Object
37 38 39 |
# File 'lib/rbcurse/keylabelprinter.rb', line 37 def getvalue @key_hash end |
#insert_application_key_label(index, display_code, text) ⇒ Object
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
136 137 138 139 140 |
# File 'lib/rbcurse/keylabelprinter.rb', line 136 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) ⇒ Object
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 |
# File 'lib/rbcurse/keylabelprinter.rb', line 56 def print_key_labels(arr = key_labels(), mode=@mode) #return if !@show_key_labels # XXX @win ||= @form.window @padding = @cols / (arr.length/2) posx = 0 even = [] odd = [] arr.each_index { |i| if i % 2 == 0 #arr[i+1] = ['',''] if arr[i+1].nil? nextarr = arr[i+1] || ['', ''] keyw = [arr[i][0].length, nextarr[0].length].max labelw = [arr[i][1].length, nextarr[1].length].max even << [ sprintf("%*s", keyw, arr[i][0]), sprintf("%-*s", labelw, arr[i][1]) ] odd << [ sprintf("%*s", keyw, nextarr[0]), sprintf("%-*s", labelw, nextarr[1]) ] #$log.debug("loop even: #{even.inspect}") else end } #$log.debug("even: #{even.inspect}") #$log.debug("odd : #{odd.inspect}") #posy = @barrow-1 posy = @row print_key_labels_row(posy, posx, even) posy = @row+1 print_key_labels_row(posy, posx, odd) #@win.wrefresh # needed else secod row not shown after askchoice XXX end |
#print_key_labels_row(posy, posx, arr) ⇒ Object
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 110 111 112 113 114 115 |
# File 'lib/rbcurse/keylabelprinter.rb', line 85 def print_key_labels_row(posy, posx, arr) # FIXME: this logic of padding needs to take into account # width of window padding = 8 padding = 4 if arr.length > 5 padding = 2 if arr.length > 7 padding = 0 if arr.length > 9 #padding = @padding # XXX 2008-11-13 23:01 my_form_win = @win @win.printstring(posy,0, "%-*s" % [@cols," "], @footer_color_pair, @attr) arr.each do |kl| key = kl[0] lab = kl[1] if key !="" # don't print that white blank space for fillers color_pair= @footer_mnemonic_color_pair # $reversecolor #2 x = posx + (key.length - key.strip.length) my_form_win.attron(Ncurses.COLOR_PAIR(color_pair)) my_form_win.mvprintw(posy, x, "%s" % kl[0].strip ); my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair)) end color_pair=@footer_color_pair posx = posx + kl[0].length my_form_win.attron(Ncurses.COLOR_PAIR(color_pair)) #lab = sprintf(" %s %*s" , kl[1], padding, " "); lab = sprintf(" %s %s" , kl[1], " "*padding); my_form_win.mvprintw(posy, posx, lab) my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair)) posx = posx + lab.length end end |
#repaint ⇒ Object
XXX need to move wrapping etc up and done once.
46 47 48 49 50 51 |
# File 'lib/rbcurse/keylabelprinter.rb', line 46 def repaint return unless @repaint_required r,c = rowcol print_key_labels(arr = key_labels(), mode=@mode) @repaint_required = false end |
#set_key_labels(_key_labels, mode = :normal) ⇒ Object
40 41 42 |
# File 'lib/rbcurse/keylabelprinter.rb', line 40 def set_key_labels _key_labels, mode=:normal @key_hash[mode] = _key_labels end |
#update_application_key_label(display_code, new_display_code, text) ⇒ Object
updates existing label with a new one.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rbcurse/keylabelprinter.rb', line 119 def update_application_key_label(display_code, new_display_code, text) @repaint_required = true labels = key_labels() labels.each_index do |ix| lab = labels[ix] if lab[0] == display_code labels[ix] = [new_display_code , text] $log.debug("updated #{labels[ix]}") return true end end return false end |