Class: RubyCurses::Field

Inherits:
Widget show all
Defined in:
lib/rbcurse/core/widgets/rwidget.rb

Overview

Text edit field NOTE: To get value use getvalue() TODO - test text_variable TODO: some methods should return self, so chaining can be done. Not sure if the return value of the

fire_handler is being checked.
NOTE: i have just added repain_required check in Field before repaint
this may mean in some places field does not paint. repaint_require will have to be set
to true in those cases. this was since field was overriding a popup window that was not modal.

Since:

  • 1.2.0

Direct Known Subclasses

ComboBox

Instance Attribute Summary collapse

Attributes inherited from Widget

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

Instance Method Summary collapse

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #leave, #move, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn

Methods included from Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #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 = nil, config = {}, &block) ⇒ Field

Returns a new instance of Field.

Since:

  • 1.2.0



2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2110

def initialize form=nil, config={}, &block
  @form = form
  @buffer = String.new
  #@type=config.fetch("type", :varchar)
  @row = 0
  @col = 0
  #@bgcolor = $def_bg_color
  #@color = $def_fg_color
  @editable = true
  @focusable = true
  @event_args = {}             # arguments passed at time of binding, to use when firing event
  map_keys 
  init_vars
  @_events ||= []
  @_events.push(:CHANGE)
  super
  @display_length ||= 20
  @maxlen ||= @display_length
end

Instance Attribute Details

#bufferObject (readonly)

actual buffer being used for storage

Since:

  • 1.2.0



2072
2073
2074
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2072

def buffer
  @buffer
end

#datatypeObject

attr_reader :curpos # cursor position in buffer current, in WIDGET

Since:

  • 1.2.0



2099
2100
2101
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2099

def datatype
  @datatype
end

#field_colObject (readonly)

Since:

  • 1.2.0



2103
2104
2105
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2103

def field_col
  @field_col
end

#formObject (readonly)

Since:

  • 1.2.0



2095
2096
2097
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2095

def form
  @form
end

#handlerObject (readonly)

event handler

Since:

  • 1.2.0



2096
2097
2098
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2096

def handler
  @handler
end

#original_valueObject (readonly)

value on entering field

Since:

  • 1.2.0



2100
2101
2102
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2100

def original_value
  @original_value
end

#overwrite_modeObject

true or false INSERT OVERWRITE MODE

Since:

  • 1.2.0



2101
2102
2103
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2101

def overwrite_mode
  @overwrite_mode
end

#type(dtype) ⇒ Object (readonly)

define a datatype, currently only influences chars allowed integer and float. what about allowing a minus sign?

Since:

  • 1.2.0



2097
2098
2099
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2097

def type
  @type
end

Instance Method Details

#addcol(num) ⇒ Object

add a column to cursor position. Field

Since:

  • 1.2.0



2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2493

def addcol num
  if num < 0
    if @form.col <= @col + @col_offset
     # $log.debug " error trying to cursor back #{@form.col}"
      return -1
    end
  elsif num > 0
    if @form.col >= @col + @col_offset + @display_length
  #    $log.debug " error trying to cursor forward #{@form.col}"
      return -1
    end
  end
  @form.addcol num
end

#cursor_backwardObject

$log.debug “ crusor FORWARD cp:#@curpos pcol:#@pcol b.l:#RubyCurses::Field.@[email protected] d_l:#@display_length fc:#RubyCurses::Field.@[email protected]

Since:

  • 1.2.0



2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2453

def cursor_backward
  if @curpos > 0
    @curpos -= 1
    if @pcol > 0 and @form.col == @col + @col_offset
      @pcol -= 1
    end
    addcol -1
  elsif @pcol > 0 #  added 2008-11-26 23:05 
    @pcol -= 1   
  end
 #   $log.debug " crusor back cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}"
=begin
# this is perfect if not scrolling, but now needs changes
  if @curpos > 0
    @curpos -= 1
    addcol -1
  end
=end
end

#cursor_endObject

goto end of field, “end” is a keyword so could not use it.

Since:

  • 1.2.0



2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2406

def cursor_end
  blen = @buffer.rstrip.length
  if blen < @display_length
    set_form_col blen
  else
    # there is a problem here FIXME. 
    @pcol = blen-@display_length
    #set_form_col @display_length-1
    set_form_col blen
  end
  @curpos = blen # this is position in array where editing or motion is to happen regardless of what you see
                 # regardless of pcol (panning)
  #  $log.debug " crusor END cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}"
  #set_form_col @buffer.length
end

#cursor_forwardObject

Since:

  • 1.2.0



2444
2445
2446
2447
2448
2449
2450
2451
2452
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2444

def cursor_forward
  if @curpos < @buffer.length 
    if addcol(1)==-1  # go forward if you can, else scroll
      @pcol += 1 if @pcol < @display_length 
    end
    @curpos += 1
  end
 # $log.debug " crusor FORWARD cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}"
end

#cursor_homeObject

position cursor at start of field

Since:

  • 1.2.0



2399
2400
2401
2402
2403
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2399

def cursor_home
  @curpos = 0
  @pcol = 0
  set_form_col 0
end

#delete_at(index = @curpos) ⇒ Object

Since:

  • 1.2.0



2219
2220
2221
2222
2223
2224
2225
2226
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2219

def delete_at index=@curpos
  return -1 if !@editable 
  char = @buffer.slice!(index,1)
  #$log.debug " delete at #{index}: #{@buffer.length}: #{@buffer}"
  @modified = true
  #fire_handler :CHANGE, self    # 2008-12-09 14:51 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, char)     # 2010-09-11 13:01 
end

#delete_curr_charObject

# this is perfect if not scrolling, but now needs changes

if @curpos > 0
  @curpos -= 1
  addcol -1
end

Since:

  • 1.2.0



2472
2473
2474
2475
2476
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2472

def delete_curr_char
  return -1 unless @editable
  delete_at
  set_modified 
end

#delete_eolObject

Since:

  • 1.2.0



2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2434

def delete_eol
  return -1 unless @editable
  pos = @curpos-1
  @delete_buffer = @buffer[@curpos..-1]
  # if pos is 0, pos-1 becomes -1, end of line!
  @buffer = pos == -1 ? "" : @buffer[0..pos]
  #fire_handler :CHANGE, self    # 2008-12-09 14:51 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, 0, @delete_buffer)     # 2010-09-11 13:01 
  return @delete_buffer
end

#delete_prev_charObject

Since:

  • 1.2.0



2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2477

def delete_prev_char
  return -1 if !@editable 
  return if @curpos <= 0
  # if we've panned, then unpan, and don't move cursor back
  # Otherwise, adjust cursor (move cursor back as we delete)
  adjust = true
  if @pcol > 0
    @pcol -= 1
    adjust = false
  end
  @curpos -= 1 if @curpos > 0
  delete_at
  addcol -1 if adjust # move visual cursor back
  set_modified 
end

#getvalueObject

converts back into original type

changed to convert on 2009-01-06 23:39

Since:

  • 1.2.0



2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2255

def getvalue
  dt = @datatype || String
  case dt.to_s
  when "String"
    return @buffer
  when "Fixnum"
    return @buffer.to_i
  when "Float"
    return @buffer.to_f
  else
    return @buffer.to_s
  end
end

#handle_key(ch) ⇒ Object

field

Since:

  • 1.2.0



2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2375

def handle_key ch
  @repaint_required = true 
  #map_keys unless @keys_mapped # moved to init
  case ch
  when 32..126
    #$log.debug("FIELD: ch #{ch} ,at #{@curpos}, buffer:[#{@buffer}] bl: #{@buffer.to_s.length}")
    putc ch
  when 27 # cannot bind it
    set_buffer @original_value 
  else
    ret = super
    return ret
  end
  0 # 2008-12-16 23:05 without this -1 was going back so no repaint
end

#init_varsObject

Since:

  • 1.2.0



2129
2130
2131
2132
2133
2134
2135
2136
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2129

def init_vars
  @pcol = 0                    # needed for horiz scrolling
  @curpos = 0                  # current cursor position in buffer
                               # this is the index where characters are put or deleted
  #                            # when user edits
  @modified = false
  @repaint_required = true
end

#map_keysObject

Since:

  • 1.2.0



2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2357

def map_keys
  return if @keys_mapped
  bind_key(FFI::NCurses::KEY_LEFT, :cursor_backward )
  bind_key(FFI::NCurses::KEY_RIGHT, :cursor_forward )
  bind_key(FFI::NCurses::KEY_BACKSPACE, :delete_prev_char )
  bind_key(127, :delete_prev_char )
  bind_key(330, :delete_curr_char )
  bind_key(?\C-a, :cursor_home )
  bind_key(?\C-e, :cursor_end )
  bind_key(?\C-k, :delete_eol )
  bind_key(?\C-_, :undo_delete_eol )
  #bind_key(27){ set_buffer @original_value }
  bind_key(?\C-g, 'revert'){ set_buffer @original_value } # 2011-09-29 V1.3.1 ESC did not work
  @keys_mapped = true
end

#modified?Boolean

overriding widget, check for value change

2009-01-18 12:25

Returns:

  • (Boolean)

Since:

  • 1.2.0



2551
2552
2553
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2551

def modified?
  getvalue() != @original_value
end

#on_enterObject

save original value on enter, so we can check for modified.

2009-01-18 12:25 
 2011-10-9 I have changed to take @buffer since getvalue returns a datatype
 and this causes a crash in set_original on cursor forward.

Since:

  • 1.2.0



2543
2544
2545
2546
2547
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2543

def on_enter
  #@original_value = getvalue.dup rescue getvalue
  @original_value = @buffer.dup # getvalue.dup rescue getvalue
  super
end

#on_leaveObject

upon leaving a field returns false if value not valid as per values or valid_regex 2008-12-22 12:40 if null_allowed, don’t validate, but do fire_handlers

Since:

  • 1.2.0



2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2510

def on_leave
  val = getvalue
  #$log.debug " FIELD ON LEAVE:#{val}. #{@values.inspect}"
  valid = true
  if val.to_s.empty? && @null_allowed
    #$log.debug " empty and null allowed"
  else
    if !@values.nil?
      valid = @values.include? val
      raise FieldValidationException, "Field value (#{val}) not in values: #{@values.join(',')}" unless valid
    end
    if !@valid_regex.nil?
      valid = @valid_regex.match(val.to_s)
      raise FieldValidationException, "Field not matching regex #{@valid_regex}" unless valid
    end
    # added valid_range for numerics 2011-09-29 
    if !@valid_range.nil?
      valid = @valid_range.include?(val.to_i)
      raise FieldValidationException, "Field not matching range #{@valid_range}" unless valid
    end
  end
  # here is where we should set the forms modified to true - 2009-01
  if modified?
    set_modified true
  end
  # if super fails we would have still set modified to true
  super
  #return valid
end

#position_labelObject

FIXME this may not work since i have disabled -1, now i do not set row and col

Since:

  • 1.2.0



2295
2296
2297
2298
2299
2300
2301
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2295

def position_label
  $log.debug "XXX: LABEL row #{@label.row}, #{@label.col} "
  @label.row  @row unless @label.row #if @label.row == -1
  @label.col  @col-(@label.name.length+1) unless @label.col #if @label.col == -1
  @label.label_for(self) # this line got deleted when we redid stuff !
  $log.debug "   XXX: LABEL row #{@label.row}, #{@label.col} "
end

#putc(c) ⇒ Object

TODO : sending c>=0 allows control chars to go. Should be >= ?A i think.

Since:

  • 1.2.0



2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2203

def putc c
  if c >= 0 and c <= 127
    ret = putch c.chr
    if ret == 0
      if addcol(1) == -1  # if can't go forward, try scrolling
        # scroll if exceeding display len but less than max len
        if @curpos > @display_length && @curpos <= @maxlen
          @pcol += 1 if @pcol < @display_length 
        end
      end
      set_modified 
      return 0 # 2010-09-11 12:59 else would always return -1
    end
  end
  return -1
end

#putch(char) ⇒ Fixnum

add a char to field, and validate NOTE: this should return self for chaining operations and throw an exception if disabled or exceeding size

Parameters:

  • a (char)

    character to add

Returns:

  • (Fixnum)

    0 if okay, -1 if not editable or exceeding length

Since:

  • 1.2.0



2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2173

def putch char
  return -1 if !@editable 
  return -1 if !@overwrite_mode && (@buffer.length >= @maxlen)
  if @chars_allowed != nil
    return if char.match(@chars_allowed).nil?
  end
  # added insert or overwrite mode 2010-03-17 20:11 
  oldchar = nil
  if @overwrite_mode
    oldchar = @buffer[@curpos] 
    @buffer[@curpos] = char
  else
    @buffer.insert(@curpos, char)
  end
  oldcurpos = @curpos
  $log.warn "XXX:  FIELD CURPOS #{@curpos} "
  @curpos += 1 if @curpos < @maxlen
  @modified = true
  #$log.debug " FIELD FIRING CHANGE: #{char} at new #{@curpos}: bl:#{@buffer.length} buff:[#{@buffer}]"
  # i have no way of knowing what change happened and what char was added deleted or changed
  #fire_handler :CHANGE, self    # 2008-12-09 14:51 
  if @overwrite_mode
    fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :DELETE, 0, oldchar) # 2010-09-11 12:43 
  end
  fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, 0, char) # 2010-09-11 12:43 
  0
end

#repaintObject

Note that some older widgets like Field repaint every time the form.repaint + is called, whether updated or not. I can’t remember why this is, but + currently I’ve not implemented events with these widgets. 2010-01-03 15:00

Since:

  • 1.2.0



2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2307

def repaint
  return unless @repaint_required  # 2010-11-20 13:13 its writing over a window i think TESTING
  if @label_unattached
    alert "came here unattachd"
    @label.set_form(@form)
  end
  if @label_unplaced
    alert "came here unplaced"
    position_label
  end
  @bgcolor ||= $def_bg_color
  @color   ||= $def_fg_color
  $log.debug("repaint FIELD: #{id}, #{name}, #{row} #{col},pcol:#{@pcol},  #{focusable} st: #{@state} ")
  #return if display_length <= 0 # added 2009-02-17 00:17 sometimes editor comp has 0 and that
  # becomes negative below, no because editing still happens
  @display_length = 1 if display_length == 0
  printval = getvalue_for_paint().to_s # added 2009-01-06 23:27 
  printval = show()*printval.length unless @show.nil?
  if !printval.nil? 
    if printval.length > display_length # only show maxlen
      printval = printval[@pcol..@pcol+display_length-1] 
    else
      printval = printval[@pcol..-1]
    end
  end

  acolor = @color_pair || get_color($datacolor, @color, @bgcolor)
  if @state == :HIGHLIGHTED
    _bgcolor = @highlight_background || @bgcolor
    _color = @highlight_foreground || @color
    acolor = get_color(acolor, _color, _bgcolor)
  end
  @graphic = @form.window if @graphic.nil? ## cell editor listbox hack 
  #$log.debug " Field g:#{@graphic}. r,c,displen:#{@row}, #{@col}, #{@display_length} c:#{@color} bg:#{@bgcolor} a:#{@attr} :#{@name} "
  r = row
  c = col
  if label.is_a? String
    lcolor = @label_color_pair || $datacolor # this should be the same color as window bg XXX
    lattr = @label_attr || NORMAL
    @graphic.printstring row, col, label, lcolor, lattr
    c += label.length + 2
    @col_offset = c-@col            # required so cursor lands in right place
  end
  @graphic.printstring r, c, sprintf("%-*s", display_length, printval), acolor, @attr
  @field_col = c
  @repaint_required = false
end

#restore_original_valueObject

silently restores value without firing handlers, use if exception and you want old value

Since:

  • 1.4.0 2011-10-2



2230
2231
2232
2233
2234
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2230

def restore_original_value
  @buffer = @original_value.dup
  #@curpos = 0 # this would require restting setformcol
  @repaint_required = true
end

#set_buffer(value) ⇒ Object

should this do a dup ?? YES set value of Field fires CHANGE handler

Since:

  • 1.2.0



2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2239

def set_buffer value
  @repaint_required = true
  @datatype = value.class
  #$log.debug " FIELD DATA #{@datatype}"
  @delete_buffer = @buffer.dup
  @buffer = value.to_s.dup
  # don't allow setting of value greater than maxlen
  @buffer = @buffer[0,@maxlen] if @maxlen && @buffer.length > @maxlen
  @curpos = 0
  # hope @delete_buffer is not overwritten
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, @delete_buffer)     # 2010-09-11 13:01 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :INSERT, 0, @buffer)     # 2010-09-11 13:01 
  self # 2011-10-2 
end

#set_focusable(tf) ⇒ Object

Since:

  • 1.2.0



2354
2355
2356
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2354

def set_focusable(tf)
  @focusable = tf
end

#set_form_col(col1 = @curpos) ⇒ Object

sets the visual cursor on the window at correct place added here since we need to account for pcol. 2011-12-7 NOTE be careful of curpos - pcol being less than 0

Since:

  • 1.2.0



2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2424

def set_form_col col1=@curpos
  @curpos = col1 || 0 # NOTE we set the index of cursor here
  c = @col + @col_offset + @curpos - @pcol
  min = @col + @col_offset
  max = min + @display_length
  c = min if c < min
  c = max if c > max
  $log.debug " #{@name} FIELD set_form_col #{c}, curpos #{@curpos}  , #{@col} + #{@col_offset} pcol:#{@pcol} "
  setrowcol nil, c
end

#set_label(label) ⇒ Object

create a label linked to this field Typically one passes a Label, but now we can pass just a String, a label is created NOTE: 2011-10-20 when field attached to some container, label won’t be attached FIXME this may not work since i have disabled -1, now i do not set row and col 2011-11-5

Parameters:

  • label (Label, String)

    object to be associated with this field

Since:

  • 1.2.0



2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2275

def set_label label
  # added case for user just using a string
  case label
  when String
    # what if no form at this point
    @label_unattached = true unless @form
    label = Label.new @form, {:text => label}
  end
  @label = label
  # in the case of app it won't be set yet FIXME
  # So app sets label to 0 and t his won't trigger
  # can this be delayed to when paint happens XXX
  if @row
    position_label
  else
    @label_unplaced = true
  end
  label
end

#text(*val) ⇒ Object Also known as: default

Use this to set a default text to the field. This does not imply that if the field is left blank, this value will be used. It only provides this value for editing when field is shown.

Since:

  • 1.2.0



2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2558

def text(*val)
  if val.empty?
    return getvalue()
  else
    return unless val # added 2010-11-17 20:11, dup will fail on nil
    return unless val[0]
    s = val[0].dup
    set_buffer(s)
  end
end

#text=(val) ⇒ Object

Since:

  • 1.2.0



2569
2570
2571
2572
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2569

def text=(val)
  return unless val # added 2010-11-17 20:11, dup will fail on nil
  set_buffer(val.dup)
end

#text_variable(tv) ⇒ Object

Set Variable as value.

This allows using Field as a proxy
@param [Variable] variable containing text value

Since:

  • 1.2.0



2143
2144
2145
2146
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2143

def text_variable tv
  @text_variable = tv
  set_buffer tv.value
end

#undo_delete_eolObject

does an undo on delete_eol, not a real undo

Since:

  • 1.2.0



2391
2392
2393
2394
2395
2396
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2391

def undo_delete_eol
  return if @delete_buffer.nil?
  #oldvalue = @buffer
  @buffer.insert @curpos, @delete_buffer 
  fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, 0, @delete_buffer)     # 2010-09-11 13:01 
end