Class: RubyCurses::BasicListbox

Inherits:
Widget show all
Extended by:
Forwardable
Includes:
ListScrollable, NewListSelectable
Defined in:
lib/rbcurse/rbasiclistbox.rb

Overview

scrollable, selectable list of items

- @selected contains indices of selected objects.

A readonly control for displaying a list of data or values. Although user editing is not allowed, but the list may be repopulated as in a directory listing, or a list dependent on some other control’s value. This is not a drop-in replacement for Listbox as it drops many methods that are redundant. Default selection is single, as opposed to Listbox.

Since:

  • 1.2.0

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

Attributes included from ListScrollable

#find_offset, #find_offset1, #search_found_ix, #show_caret

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #state

selection related collapse

Instance Method Summary collapse

Methods included from NewListSelectable

#add_selection_interval, #add_to_selection, #ask_select, #clear_selection, #get_matching_indices, #insert_index_interval, #invert_row_selection, #invert_selection, #is_row_selected, #list_bindings, #list_init_vars, #paint_selector, #remove_selection_interval, #select_all, #select_values, #selected_rows, #toggle_row_selection, #unselect_values

Methods included from ListScrollable

#_find_next, #_find_prev, #ask_search, #bounds_check, #find_more, #find_next, #find_prev, #focussed_index, #forward_char, #forward_word, #goto_bottom, #goto_last_position, #goto_top, #install_keys, #next_match, #next_row, #previous_row, #scroll_backward, #scroll_forward, #scroll_left, #scroll_right, #selected_item, #set_focus_on, #set_form_row, #set_selection_for_char, #show_caret_func

Methods inherited from Widget

#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #leave, #modified?, #move, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #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_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr, #warn

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(form, config = {}, &block) ⇒ BasicListbox

basic listbox constructor

Since:

  • 1.2.0



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
# File 'lib/rbcurse/rbasiclistbox.rb', line 75

def initialize form, config={}, &block
  @focusable = true
  @editable = false
  @sanitization_required = true # cleanup control and non print chars
  @truncation_required = true
  @suppress_borders = false #to_print_borders = 1
  @row_selected_symbol = ''
  @row = 0
  @col = 0
  # data of listbox this is not an array, its a pointer to the  listdatamodel
  @list = nil 
  # any special attribs such as status to be printed in col1, or color (selection)
  @list_attribs = {}
  @current_index = 0
  @selected_indices = []
  @selected_index = nil
  @row_offset = @col_offset = 1
  super
  @_events.push(*[:ENTER_ROW, :LEAVE_ROW, :LIST_SELECTION_EVENT, :PRESS])
  @selection_mode ||= :multiple # default is multiple, anything else given becomes single
  @win = @graphic    # 2010-01-04 12:36 BUFFERED  replace form.window with graphic
  @win_left = 0
  @win_top = 0

  # next 2 lines carry a redundancy
  #select_default_values   
  # when the combo box has a certain row in focus, the popup should have the same row in focus

  init_vars

  if @list && !@selected_index.nil?  # XXX
    set_focus_on @selected_index # the new version
  end
end

Instance Attribute Details

#current_indexObject

Since:

  • 1.2.0



47
48
49
# File 'lib/rbcurse/rbasiclistbox.rb', line 47

def current_index
  @current_index
end

#one_key_selectionObject

please set these in he constructor block. Settin them later will have no effect since i would have bound them to actions

Since:

  • 1.2.0



58
59
60
# File 'lib/rbcurse/rbasiclistbox.rb', line 58

def one_key_selection
  @one_key_selection
end

#selected_indexObject

index of selected row

Since:

  • 1.2.0



68
69
70
# File 'lib/rbcurse/rbasiclistbox.rb', line 68

def selected_index
  @selected_index
end

#selected_indicesObject (readonly)

index of selected rows, if multiple selection asked for

Since:

  • 1.2.0



70
71
72
# File 'lib/rbcurse/rbasiclistbox.rb', line 70

def selected_indices
  @selected_indices
end

#toprowObject (readonly)

dsl_accessor :list # the array of data to be sent by user

Since:

  • 1.2.0



44
45
46
# File 'lib/rbcurse/rbasiclistbox.rb', line 44

def toprow
  @toprow
end

Instance Method Details

#[](off0) ⇒ Object

get element at

Parameters:

  • index (Fixnum)

    for element

Returns:

Since:

  • 1.2.0 2010-09-06 14:33 making life easier for others.



200
201
202
# File 'lib/rbcurse/rbasiclistbox.rb', line 200

def [](off0)
  @list[off0]
end

#ask_search_backwardObject

gets string to search and calls data models find prev

Since:

  • 1.2.0



363
364
365
366
367
368
369
370
371
372
# File 'lib/rbcurse/rbasiclistbox.rb', line 363

def ask_search_backward
  regex =  get_string("Enter regex to search (backward)")
  @last_regex = regex
  ix = @list.find_prev regex, @current_index
  if ix.nil?
    alert("No matching data for: #{regex}")
  else
    set_focus_on(ix)
  end
end

#ask_search_forwardObject

Since:

  • 1.2.0



353
354
355
356
357
358
359
360
361
# File 'lib/rbcurse/rbasiclistbox.rb', line 353

def ask_search_forward
    regex =  get_string("Enter regex to search")
    ix = @list.find_match regex
    if ix.nil?
      alert("No matching data for: #{regex}")
    else
      set_focus_on(ix)
    end
end

#ask_selection_for_charObject

get a keystroke from user and go to first item starting with that key

Since:

  • 1.2.0



346
347
348
349
350
351
352
# File 'lib/rbcurse/rbasiclistbox.rb', line 346

def ask_selection_for_char
  ch = @graphic.getch
  if ch < 0 || ch > 255
    return :UNHANDLED
  end
  ret = set_selection_for_char ch.chr
end

#cell_renderer(*val) ⇒ Object

getter and setter for cell_renderer

Since:

  • 1.2.0



393
394
395
396
397
398
399
# File 'lib/rbcurse/rbasiclistbox.rb', line 393

def cell_renderer(*val)
  if val.empty?
    @cell_renderer ||= create_default_cell_renderer
  else
    @cell_renderer = val[0] 
  end
end

#convert_value_to_text(value, crow) ⇒ Object

the idea here is to allow users who subclass Listbox to easily override parts of the cumbersome repaint method. This assumes your List has some data, but you print a lot more. Now you don’t need to change the data in the renderer, or keep formatted data in the list itself. e.g. @list contains file names, or File objects, and this converts to a long listing. If the renderer did that, the truncation would be on wrong data.

Since:

  • 1.2.0



479
480
481
482
483
484
485
486
# File 'lib/rbcurse/rbasiclistbox.rb', line 479

def convert_value_to_text value, crow
  case value
  when TrueClass, FalseClass
    value
  else
    value.to_s if value
  end
end

#create_default_cell_rendererObject

Since:

  • 1.2.0



400
401
402
403
# File 'lib/rbcurse/rbasiclistbox.rb', line 400

def create_default_cell_renderer
  return ListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-2-@left_margin}
  #return BasicListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-2-@left_margin}
end

#current_valueObject Also known as: current_row, text

return object under cursor Note: this should not be confused with selected row/s. User may not have selected this. This is only useful since in some demos we like to change a status bar as a user scrolls down

Since:

  • 1.2.0 2010-09-06 14:33 making life easier for others.



207
208
209
# File 'lib/rbcurse/rbasiclistbox.rb', line 207

def current_value
  @list[@current_index]
end

#data=(val) ⇒ Object

conv method to insert data, trying to keep names same across along with Tabular, TextView, TextArea and listbox. Don;t use this till i am certain.

Since:

  • 1.2.0



193
194
195
# File 'lib/rbcurse/rbasiclistbox.rb', line 193

def data=(val)
  list(val)
end

#fire_action_eventObject

Since:

  • 1.2.0



340
341
342
343
344
# File 'lib/rbcurse/rbasiclistbox.rb', line 340

def fire_action_event
  require 'rbcurse/ractionevent'
  # should have been callled :ACTION_EVENT !!!
  fire_handler :PRESS, ActionEvent.new(self, :PRESS, text)
end

#get_contentObject

START FOR scrollable ###

Since:

  • 1.2.0



238
239
240
241
# File 'lib/rbcurse/rbasiclistbox.rb', line 238

def get_content
  @list 
  #@list_variable && @list_variable.value || @list 
end

#get_selected_indicesObject

Returns selected indices Indices are often required since the renderer may modify the values displayed

Since:

  • 1.2.0



619
# File 'lib/rbcurse/rbasiclistbox.rb', line 619

def get_selected_indices; @selected_indices; end

#get_selected_valuesObject Also known as: selected_values

Returns selected values

Since:

  • 1.2.0



623
624
625
626
627
# File 'lib/rbcurse/rbasiclistbox.rb', line 623

def get_selected_values
  selected = []
  @selected_indices.each { |i| selected << @list[i] }
  return selected
end

#get_windowObject

Since:

  • 1.2.0



242
243
244
# File 'lib/rbcurse/rbasiclistbox.rb', line 242

def get_window #:nodoc:
  @graphic 
end

#getvalueObject

END FOR scrollable ### override widgets text returns indices of selected rows

Since:

  • 1.2.0



248
249
250
# File 'lib/rbcurse/rbasiclistbox.rb', line 248

def getvalue
  selected_rows
end

#goto_next_selectionObject

Since:

  • 1.2.0



602
603
604
605
606
607
608
# File 'lib/rbcurse/rbasiclistbox.rb', line 602

def goto_next_selection
  return if selected_rows().length == 0 
  row = selected_rows().sort.find { |i| i > @current_index }
  row ||= @current_index
  @current_index = row
  @repaint_required = true # fire list_select XXX
end

#goto_prev_selectionObject

Since:

  • 1.2.0



609
610
611
612
613
614
615
# File 'lib/rbcurse/rbasiclistbox.rb', line 609

def goto_prev_selection
  return if selected_rows().length == 0 
  row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @current_index }
  row ||= @current_index
  @current_index = row
  @repaint_required = true # fire list_select XXX
end

#handle_key(ch) ⇒ Object

Listbox

Since:

  • 1.2.0



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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/rbcurse/rbasiclistbox.rb', line 252

def handle_key(ch) #:nodoc:
  map_keys unless @keys_mapped
  @current_index ||= 0
  @toprow ||= 0
  h = scrollatrow()
  rc = row_count
  $log.debug " basiclistbox got ch #{ch}"
  #$log.debug " when kps #{@KEY_PREV_SELECTION}  "
  case ch
  when KEY_UP  # show previous value
    return previous_row
  when KEY_DOWN  # show previous value
    return next_row
  when 32
    return if is_popup and @selection_mode == 'single' # not allowing select this way since there will be a difference 
    toggle_row_selection @current_index #, @current_index
    @repaint_required = true
  when 0 # c-space
    add_to_selection
  when @KEY_NEXT_SELECTION # ?'
    $log.debug "insdie next selection"
    @oldrow = @current_index
    do_next_selection 
    bounds_check
  when @KEY_PREV_SELECTION # ?"
    @oldrow = @current_index
    $log.debug "insdie prev selection"
    do_prev_selection 
    bounds_check
  when @KEY_CLEAR_SELECTION
    clear_selection 
    @repaint_required = true
  when 27, ?\C-c.getbyte(0)
    #editing_canceled @current_index if @cell_editing_allowed
    #cancel_block # block NW XXX don't think its required. 2011-09-9  FFI
    $multiplier = 0
  when @KEY_ASK_FIND_FORWARD
  # ask_search_forward
  when @KEY_ASK_FIND_BACKWARD
  # ask_search_backward
  when @KEY_FIND_NEXT
  # find_next
  when @KEY_FIND_PREV
  # find_prev
  when @KEY_ASK_FIND
    ask_search
  when @KEY_FIND_MORE
    find_more
  when @KEY_BLOCK_SELECTOR
    mark_block #selection
  #when ?\C-u.getbyte(0)
    # multiplier. Series is 4 16 64
    # TESTING @multiplier = (@multiplier == 0 ? 4 : @multiplier *= 4)
  #  return 0
  when ?\C-c.getbyte(0)
    @multiplier = 0
    return 0
  else
    # this has to be fixed, if compo does not handle key it has to continue into next part FIXME
    ret = :UNHANDLED # changed on 2009-01-27 13:14 not going into unhandled, tab not released
    if ret == :UNHANDLED
      # beware one-key eats up numbers. we'll be wondering why
      if @one_key_selection
        case ch
        #when ?A.getbyte(0)..?Z.getbyte(0), ?a.getbyte(0)..?z.getbyte(0), ?0.getbyte(0)..?9.getbyte(0)
        when ?A.getbyte(0)..?Z.getbyte(0), ?a.getbyte(0)..?z.getbyte(0)
          # simple motion, key press defines motion
          ret = set_selection_for_char ch.chr
        else
          ret = process_key ch, self
          @multiplier = 0
          return :UNHANDLED if ret == :UNHANDLED
        end
      else
        # no motion on single key, we can freak out like in vim, pref f <char> for set_selection
        case ch
        when ?0.getbyte(0)..?9.getbyte(0)
          $multiplier *= 10 ; $multiplier += (ch-48)
          #$log.debug " setting mult to #{$multiplier} in list "
          return 0
        end
        ret = process_key ch, self
        return :UNHANDLED if ret == :UNHANDLED
      end
    end
  end
  $multiplier = 0
end

#init_varsObject

this is called several times, from constructor and when list data changed, so only put relevant resets here.

Since:

  • 1.2.0



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rbcurse/rbasiclistbox.rb', line 111

def init_vars
  @repaint_required = true
  @toprow = @pcol = 0
  if @show_selector
    @row_selected_symbol ||= '>'
    @row_unselected_symbol ||= ' '
    @left_margin ||= @row_selected_symbol.length
  end
  #@left_margin ||= 0
  @one_key_selection = false if @one_key_selection.nil?
  @row_offset = @col_offset = 0 if @suppress_borders

end

#list(*val) ⇒ ListDataModel

provide data to List in the form of an Array or Variable or ListDataModel. This will create a default ListSelectionModel.

CHANGE as on 2010-09-21 12:53: If explicit nil passed then dummy datamodel and selection model created From now on, constructor will call this, so this can always happen.

NOTE: sometimes this can be added much after its painted. Do not expect this to be called from constructor, although that is the usual case. it can be dependent on some other list or tree.

Parameters:

Returns:

Since:

  • 1.2.0



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/rbcurse/rbasiclistbox.rb', line 172

def list *val
  return @list if val.empty?
  alist = val[0]
  case alist
  when Array
      @list = alist
      @current_index = 0
  when NilClass
      @list = [] # or nil ?
  when Variable
    @list = alist.value
  else
    raise ArgumentError, "Listbox list(): do not know how to handle #{alist.class} " 
  end
  clear_selection

  @repaint_required = true
  @list
end

#list_data_changedObject

be informed when data has changed. required here, was being called by listdatamodel earlier

Since:

  • 1.2.0



520
521
522
523
524
525
526
527
# File 'lib/rbcurse/rbasiclistbox.rb', line 520

def list_data_changed
  if row_count == 0 # added on 2009-02-02 17:13 so cursor not hanging on last row which could be empty
    init_vars
    @current_index = 0
    set_form_row
  end
  @repaint_required = true
end

#map_keysObject

Since:

  • 1.2.0



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rbcurse/rbasiclistbox.rb', line 124

def map_keys
  return if @keys_mapped
  bind_key(?f){ ask_selection_for_char() }
  bind_key(?\M-v){ @one_key_selection = false }
  bind_key(?j){ next_row() }
  bind_key(?k){ previous_row() }
  bind_key(?\C-d){ scroll_forward() }
  bind_key(?\C-b){ scroll_backward() }
  bind_key(?G){ goto_bottom() }
  bind_key([?g,?g]){ goto_top() }
  bind_key([?',?']){ goto_last_position() }
  bind_key(?/){ ask_search() }
  bind_key(?n){ find_more() }
  bind_key(32){ toggle_row_selection() }
  bind_key(10){ fire_action_event }
  bind_key(13){ fire_action_event }
  list_bindings
  @keys_mapped = true

end

#OLDadd_to_selectionObject

Only for multiple mode. add an item to selection, if selection mode is multiple if item already selected, it is deselected, else selected typically bound to Ctrl-Space

Since:

  • 1.2.0



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/rbcurse/rbasiclistbox.rb', line 571

def OLDadd_to_selection
  crow = @current_index
  case @selection_mode 
  when :multiple
    if @selected_indices.include? @current_index
      @selected_indices.delete @current_index
      lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
      fire_handler :LIST_SELECTION_EVENT, lse
    else
      @selected_indices << @current_index
      lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
      fire_handler :LIST_SELECTION_EVENT, lse
    end
  else
  end
  @repaint_required = true
end

#OLDclear_selectionObject

clears selected indices

Since:

  • 1.2.0



589
590
591
592
# File 'lib/rbcurse/rbasiclistbox.rb', line 589

def OLDclear_selection
  @selected_indices = []
  @repaint_required = true
end

#OLDis_row_selected(crow = @current_index) ⇒ Object

Since:

  • 1.2.0



593
594
595
596
597
598
599
600
# File 'lib/rbcurse/rbasiclistbox.rb', line 593

def OLDis_row_selected crow=@current_index
  case @selection_mode 
  when :multiple
    @selected_indices.include? crow
  else
    crow == @selected_index
  end
end

#OLDtoggle_row_selection(crow = @current_index) ⇒ Object

change selection of current row on pressing space bar If mode is multiple, then other selections are cleared and this is added NOTE: 2011-10-8 allow multiple select on spacebar. Using C-Space was quite unfriendly although it will still work

Since:

  • 1.2.0



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/rbcurse/rbasiclistbox.rb', line 546

def OLDtoggle_row_selection crow=@current_index
  @repaint_required = true
  row = crow
  case @selection_mode 
  when :multiple
    add_to_selection
    #clear_selection
    #@selected_indices[0] = crow #@current_index
  else
    if @selected_index == crow #@current_index
      @selected_index = nil
      lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
      fire_handler :LIST_SELECTION_EVENT, lse
    else
      @selected_index = crow #@current_index
      lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
      fire_handler :LIST_SELECTION_EVENT, lse
    end
  end
end

#on_enterBoolean

please check for error before proceeding

Returns:

  • (Boolean)

    false if no data

Since:

  • 1.2.0



375
376
377
378
379
380
381
382
383
384
# File 'lib/rbcurse/rbasiclistbox.rb', line 375

def on_enter
  if @list.nil? || @list.size == 0
    Ncurses.beep
    return :UNHANDLED
  end
  super  # forgot this 2011-10-9 that's why events not firign
  on_enter_row @current_index
  set_form_row # added 2009-01-11 23:41 
  true
end

#on_enter_row(arow) ⇒ Object

Since:

  • 1.2.0



385
386
387
388
# File 'lib/rbcurse/rbasiclistbox.rb', line 385

def on_enter_row arow
  fire_handler :ENTER_ROW, self
  @repaint_required = true
end

#on_leave_row(arow) ⇒ Object

Since:

  • 1.2.0



389
390
391
# File 'lib/rbcurse/rbasiclistbox.rb', line 389

def on_leave_row arow
  fire_handler :LEAVE_ROW, self
end

:nodoc:

Since:

  • 1.2.0



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/rbcurse/rbasiclistbox.rb', line 219

def print_borders #:nodoc:
  width = @width
  height = @height-1 # 2010-01-04 15:30 BUFFERED HEIGHT
  window = @graphic  # 2010-01-04 12:37 BUFFERED
  startcol = @col 
  startrow = @row 
  #@color_pair = get_color($datacolor)
  bordercolor = @border_color || $datacolor
  borderatt = @border_attrib || Ncurses::A_NORMAL

  window.print_border startrow, startcol, height, width, bordercolor, borderatt
  print_title
end

:nodoc:

Since:

  • 1.2.0



232
233
234
235
236
# File 'lib/rbcurse/rbasiclistbox.rb', line 232

def print_title #:nodoc:
  @color_pair ||= get_color($datacolor)
  # TODO check title.length and truncate if exceeds width
  @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, @color_pair, @title_attrib) unless @title.nil?
end

#remove_allObject

Since:

  • 1.2.0



210
211
212
213
214
# File 'lib/rbcurse/rbasiclistbox.rb', line 210

def remove_all
  return if @list.nil? || @list.empty? 
  @list = []
  init_vars
end

#repaintObject

this method chops the data to length before giving it to the renderer, this can cause problems if the renderer does some processing. also, it pans the data horizontally giving the renderer a section of it.

Since:

  • 1.2.0



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
# File 'lib/rbcurse/rbasiclistbox.rb', line 409

def repaint #:nodoc:
  return unless @repaint_required
  # not sure where to put this, once for all or repeat 2010-02-17 23:07 RFED16
  my_win = @form ? @form.window : @target_window
  @graphic = my_win unless @graphic
  raise " #{@name} neither form, nor target window given LB paint " unless my_win
  raise " #{@name} NO GRAPHIC set as yet                 LB paint " unless @graphic
  @win_left = my_win.left
  @win_top = my_win.top
  @left_margin ||= @row_selected_symbol.length
  # we are making sure display len does not exceed width XXX hope this does not wreak havoc elsewhere
  _dl = [@display_length || 100, @width-2].min # 2011-09-17 RK overwriting when we move grabbar in vimsplit

  $log.debug "basicrlistbox repaint  #{@name} graphic #{@graphic}"
  #$log.debug "XXX repaint to_print #{@to_print_borders} "
  print_borders unless @suppress_borders # do this once only, unless everything changes
  #maxlen = @maxlen || @width-2
  tm = list()
  rc = row_count
  @longest_line = @width
  $log.debug " rbasiclistbox #{row_count}, w:#{@width} , maxlen:#{@maxlen} "
  if rc > 0     # just added in case no data passed
    tr = @toprow
    acolor = get_color $datacolor
    h = scrollatrow()
    r,c = rowcol
    0.upto(h) do |hh|
      crow = tr+hh
      if crow < rc
        _focussed = @current_index == crow ? true : false  # row focussed ?
        focus_type = _focussed 
        focus_type = :SOFT_FOCUS if _focussed && !@focussed
        selected = is_row_selected crow
        content = tm[crow]   # 2009-01-17 18:37 chomp giving error in some cases says frozen
        content = convert_value_to_text content, crow # 2010-09-23 20:12 
        # by now it has to be a String
        if content.is_a? String
          content = content.dup
          sanitize content if @sanitization_required
          truncate content if @truncation_required
        end
        ## set the selector symbol if requested
        selection_symbol = ''
        if @show_selector
          if selected
            selection_symbol = @row_selected_symbol
          else
            selection_symbol =  @row_unselected_symbol
          end
          @graphic.printstring r+hh, c, selection_symbol, acolor,@attr
        end
        #renderer = get_default_cell_renderer_for_class content.class.to_s
        renderer = cell_renderer()
        renderer.display_length = _dl # 2011-09-17 RK overwriting when we move grabbar in vimsplit
        renderer.repaint @graphic, r+hh, c+@left_margin, crow, content, focus_type, selected
      else
        # clear rows
        @graphic.printstring r+hh, c, " " * (@width-2), acolor,@attr
      end
    end
  end # rc == 0
  #@table_changed = false
  @repaint_required = false
end

#row_countObject

returns count of row, needed by scrollbar and others.

Since:

  • 1.2.0



146
147
148
149
# File 'lib/rbcurse/rbasiclistbox.rb', line 146

def row_count
  return 0 if @list.nil?
  @list.length
end

#sanitize(content) ⇒ Object

takes a block, this way anyone extending this klass can just pass a block to do his job This modifies the string

Since:

  • 1.2.0



489
490
491
492
493
494
495
496
497
# File 'lib/rbcurse/rbasiclistbox.rb', line 489

def sanitize content #:nodoc:
  if content.is_a? String
    content.chomp!
    content.gsub!(/\t/, '  ') # don't display tab
    content.gsub!(/[^[:print:]]/, '')  # don't display non print characters
  else
    content
  end
end

#scrollatrowObject

start scrolling when user reaches this row

Since:

  • 1.2.0



151
152
153
154
155
156
157
# File 'lib/rbcurse/rbasiclistbox.rb', line 151

def scrollatrow #:nodoc:
  if @suppress_borders
    return @height - 1
  else
    return @height - 3
  end
end

#set_form_col(col1 = 0) ⇒ Object

set cursor column position if i set col1 to @curpos, i can move around left right if key mapped

Since:

  • 1.2.0



531
532
533
534
535
536
537
538
# File 'lib/rbcurse/rbasiclistbox.rb', line 531

def set_form_col col1=0               #:nodoc:
  @cols_panned ||= 0 
  # editable listboxes will involve changing cursor and the form issue
  win_col = 0 
  col2 = win_col + @col + @col_offset + col1 + @cols_panned + @left_margin
  $log.debug " set_form_col in rlistbox #{@col}+ left_margin #{@left_margin} ( #{col2} ) "
  setrowcol nil, col2 
end

#truncate(content) ⇒ Object

returns only the visible portion of string taking into account display length and horizontal scrolling. MODIFIES STRING

Since:

  • 1.2.0



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/rbcurse/rbasiclistbox.rb', line 500

def truncate content # :nodoc:
  maxlen = @maxlen || @width-2
  if maxlen == 0 # (otherwise it becoems -1 below)
    content.replace ""
    return
  end
  if !content.nil? 
    if content.length > maxlen # only show maxlen
      @longest_line = content.length if content.length > @longest_line
      #content = content[@pcol..@pcol+maxlen-1] 
      content.replace content[@pcol..@pcol+maxlen-1] 
    else
      # can this be avoided if pcol is 0 XXX
      content.replace content[@pcol..-1] if @pcol > 0
    end
  end
  content
end