Top Level Namespace

Defined Under Namespace

Modules: BorderTitle, Chunks, ColorMap, Io, Kernel, ListEditable, ListScrollable, Ncurses, RubyCurses, VER, ViEditable Classes: AnsiParser, DefaultColorParser, Fixnum, Module, Object, OrderedHash, PadReader, Rbcurse, StatusWindow, TabbedWindow, TreeSelectionEvent

Constant Summary collapse

KEY_TAB =

some common definition that we use throughout app. Do not add more, only what is common. I should not have added Sh-F9 and C-left since they are rare, but only to show they exist.

9
KEY_F1 =
FFI::NCurses::KEY_F1
KEY_F10 =
FFI::NCurses::KEY_F10
KEY_ENTER =

FFI::NCurses::KEY_ENTER gives 343

13
KEY_RETURN =

FFI gives 10 too

10
KEY_BTAB =

nc gives same

353
KEY_DELETE =
330
KEY_BACKSPACE =

Nc gives 263 for BACKSPACE

KEY_BSPACE = 127
KEY_CC =

C-c

3
KEY_LEFT =
FFI::NCurses::KEY_LEFT
KEY_RIGHT =
FFI::NCurses::KEY_RIGHT
KEY_UP =
FFI::NCurses::KEY_UP
KEY_DOWN =
FFI::NCurses::KEY_DOWN
C_LEFT =
18168
C_RIGHT =
18167
S_F9 =
17949126
META_KEY =
128

Instance Method Summary collapse

Methods included from RubyCurses::ListBindings

#bindings

Methods included from BorderTitle

#bordertitle_init, #print_borders, #print_title

Methods included from ColorMap

colors, get_color, get_color_const, get_colors_for_pair, install_color, is_color?, setup

Methods included from Io

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

Methods included from RubyCurses::Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #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 RubyCurses

#app_header, #check_prow, #dock, #repaint_old, startup, #status_line

Instance Method Details

#alert(text, config = {}) ⇒ Object

– moving to the new Messagebox 2011-11-19 v 1.5.0 Alert user with a one line message



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rbcurse/core/util/rdialogs.rb', line 28

def alert text, config={}

  if text.is_a? RubyCurses::Variable 
    text = text.get_value
  end
  _title = config[:title] || "Alert"
    tp = MessageBox.new config do
      title _title
      button_type :ok
      message text
      #text mess
    end
    tp.run
end

#confirm(text, config = {}) {|Label| ... } ⇒ Object

Yields:



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rbcurse/core/util/rdialogs.rb', line 113

def confirm text, config={}, &block
  title = config['title'] || "Confirm"
  config[:default_button] ||= 0

  mb = RubyCurses::MessageBox.new config  do
    title title
    message text, &block 
    button_type :yes_no
  end
  index = mb.run
  return index == 0
end

#display_app_help(form = @form) ⇒ Object

earlier in app.rb



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/rbcurse/core/util/rdialogs.rb', line 464

def display_app_help form=@form
  if form
    hm = form.help_manager
    if !hm.help_text 
      arr = nil
      # these 2 only made sense from app.rb and should be removed, too implicit
      if respond_to? :help_text
        arr = help_text
      elsif @_help_text
        arr = @_help_text
      end
      hm.help_text(arr) if arr
    end
    form.help_manager.display_help
  else
    raise "Form needed by display_app_help. Use form.help_manager instead"
  end
end

#get_string(label, config = {}) {|Field| ... } ⇒ Object

Yields:

  • (Field)

    field created by messagebox



66
67
68
69
70
71
72
73
74
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
# File 'lib/rbcurse/core/util/rdialogs.rb', line 66

def get_string label, config={} # yield Field
  config[:title] ||= "Entry"
  label_config = config[:label_config] || {}
  label_config[:row] ||= 2
  label_config[:col] ||= 2
  label_config[:text] = label

  field_config = config[:field_config] || {}
  field_config[:row] ||= 3
  field_config[:col] ||= 2
  field_config[:attr] = :reverse
  field_config[:maxlen] ||= config[:maxlen]
  field_config[:display_length] ||= config[:display_length]
  field_config[:default] ||= config[:default]
  field_config[:default] = field_config[:default].chomp if field_config[:default]
  field_config[:name] = :name
  #field_config[:display_length] ||= 50  # i want it to extend since i don't know the actual width
  #field_config[:width] ||= 50  # i want it to extend since i don't know the actual width
  field_config[:width] ||= (field_config[:display_length] || 50)

  defwid = config[:default].nil? ? 30 : config[:default].size + 13
  w = [label.size + 8, defwid, field_config[:width]+13 ].max
  config[:width] ||= w
  #$log.debug "XXX:  FIELD SIZE #{w} "
  #$log.debug "XXX:  FIELD CONFIG #{field_config} "
  tp = MessageBox.new config do
    button_type :ok_cancel
    default_button 0
    item Label.new nil, label_config
    item Field.new nil, field_config
  end
  # added yield to override settings
  yield tp.form.by_name[:name] if block_given?
  index = tp.run
  if index == 0 # OK
    return tp.form.by_name[:name].text
  else # CANCEL
    # Should i use nil or blank. I am currently opting for nil, as this may imply to caller
    # that user does not wish to override whatever value is being prompted for.
    return nil
  end
end

#install_help_text(text) ⇒ Object



450
451
452
453
454
455
456
# File 'lib/rbcurse/core/util/rdialogs.rb', line 450

def install_help_text text
  @_help_text = text
  if @form
    hm = @form.help_manager
    hm.help_text = text
  end
end

#longest_in_list(list) ⇒ Object

returns length of longest

Raises:

  • (ArgumentError)


441
442
443
444
445
446
447
# File 'lib/rbcurse/core/util/rdialogs.rb', line 441

def longest_in_list list  #:nodoc:
  raise ArgumentError, "rdialog.rb: longest_in_list recvd nil list" unless list
  longest = list.inject(0) do |memo,word|
    memo >= word.length ? memo : word.length
  end    
  longest
end

#ORIGdisplay_app_helpObject



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/rbcurse/core/util/rdialogs.rb', line 482

def ORIGdisplay_app_help
  filename = File.dirname(__FILE__) + "/../docs/index.txt"
  # defarr contains default help
  if File.exists?(filename)
    defarr = File.open(filename,'r').readlines
  else
    arr = []
    arr << "    NO HELP SPECIFIED FOR APP "
    arr << "    "
    arr << "     --- General help ---          "
    arr << "    F10         -  exit application "
    arr << "    Alt-x       -  select commands  "
    arr << "    : (or M-:)  -  select commands  "
    arr << "    ? (or M-?)  -  current widget key bindings  "
    arr << "    "
    defarr = arr
  end
  defhelp = true
  if respond_to? :help_text
    arr = help_text()
    defhelp = false
  elsif @_help_text
    arr = @_help_text
    defhelp = false
  else
    arr = defarr
  end
  case arr
  when String
    arr = arr.split("\n")
  when Array
  end
  #w = arr.max_by(&:length).length
  h = FFI::NCurses.LINES - 4
  w = FFI::NCurses.COLS - 10

    require 'rbcurse/core/util/viewer'
    RubyCurses::Viewer.view(arr, :layout => [2, 4, h, w],:close_key => KEY_F10, :title => "[ Help ]", :print_footer => true) do |t|
      # you may configure textview further here.
      #t.suppress_borders true
      #t.color = :black
      #t.bgcolor = :white
      # or
      #t.attr = :reverse

      # help was provided, so default help is provided in second buffer
      unless defhelp
        t.add_content defarr, :title => ' General Help '
      end
    end
end

#popuplist(list, config = {}, &block) ⇒ Object

@since 1.4.1 2011-11-1

Raises:

  • (ArgumentError)


366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
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
# File 'lib/rbcurse/core/util/rdialogs.rb', line 366

def popuplist list, config={}, &block
  raise ArgumentError, "Nil list received by popuplist" unless list
  require 'rbcurse/core/widgets/rlist'

  max_visible_items = config[:max_visible_items]
  row = config[:row] || 5
  col = config[:col] || 5
  relative_to = config[:relative_to]
  if relative_to
    layout = relative_to.form.window.layout
    row += layout[:top]
    col += layout[:left]
  end
  config.delete :relative_to
  width = config[:width] || longest_in_list(list)+2 # borders take 2
  if config[:title]
    width = config[:title].size + 2 if width < config[:title].size
  end
  height = config[:height]
  height ||= [max_visible_items || 10+2, list.length+2].min 
  #layout(1+height, width+4, row, col) 
  layout = { :height => 0+height, :width => 0+width, :top => row, :left => col } 
  window = VER::Window.new(layout)
  form = RubyCurses::Form.new window

  listconfig = config[:listconfig] || {}
  listconfig[:list] = list
  listconfig[:width] = width
  listconfig[:height] = height
  listconfig[:selection_mode] ||= :single
  listconfig.merge!(config)
  listconfig.delete(:row); 
  listconfig.delete(:col); 
  # trying to pass populists block to listbox
  lb = RubyCurses::List.new form, listconfig, &block
  #
  # added next line so caller can configure listbox with 
  # events such as ENTER_ROW, LEAVE_ROW or LIST_SELECTION_EVENT or PRESS
  # 2011-11-11 
  #yield lb if block_given? # No it won't work since this returns
  window.bkgd(Ncurses.COLOR_PAIR($reversecolor));
  window.wrefresh
  Ncurses::Panel.update_panels
  form.repaint
  window.wrefresh
  begin
    while((ch = window.getchar()) != 999 )
      case ch
      when -1
        next
      when ?\C-q.getbyte(0)
        break
      else
        lb.handle_key ch
        form.repaint
        if ch == 13 || ch == 10
          return lb.current_index if lb.selection_mode != :multiple

          x = lb.selected_indices
          return x if x
          x = lb.current_index unless x
          return [x]
          # if multiple selection, then return list of selected_indices and don't catch 32
        elsif ch == 32      # if single selection
          return lb.current_index if lb.selection_mode != :multiple
        end
        #yield ch if block_given?
      end
    end
  ensure
    window.destroy  
  end
  return nil
end

new version with a window created on 2011-10-1 12:30 AM Now can be separate from window class, needing nothing, just a util class Why are we dealing with $error_message, that was due to old idea which failed scrap it and send the message.

Parameters:

  • text (String)

    to print

  • config: (Hash)

    :color :bgcolor :color_pair :wait (numbr of seconds to wait for a key press and then close) if not givn will keep waiting for keypress (the default)



163
164
165
# File 'lib/rbcurse/core/util/rdialogs.rb', line 163

def print_error_message text, aconfig={}, &block
  _print_message :error, text, aconfig, &block
end

new version with a window created on 2011-10-1 12:37 AM Now can be separate from window class, needing nothing, just a util class prints a status message and pauses for a char

Parameters:

  • text (String)

    to print

  • config: (Hash)

    :color :bgcolor :color_pair :wait (numbr of seconds to wait for a key press and then close) if not givn will keep waiting for keypress (the default)



150
151
152
# File 'lib/rbcurse/core/util/rdialogs.rb', line 150

def print_status_message text, aconfig={}, &block
  _print_message :status, text, aconfig, &block
end

#progress_dialog(aconfig = {}, &block) ⇒ Object

the line, I might overwrite the box



354
355
356
357
358
359
360
# File 'lib/rbcurse/core/util/rdialogs.rb', line 354

def progress_dialog aconfig={}, &block
  aconfig[:layout] = [10,60,10,20]
  window = status_window aconfig
  height = 10; width = 60
  window.win.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
  return window
end

#rb_confirm(text, aconfig = {}, &block) ⇒ Object Also known as: confirm_window



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/rbcurse/core/util/rdialogs.rb', line 221

def rb_confirm text, aconfig={}, &block
  # backward compatibility with agree()
  if aconfig == true || aconfig == false
    default = aconfig
    aconfig = {}
  else 
    default = aconfig[:default]
  end
  case text
  when RubyCurses::Variable # added 2011-09-20 incase variable passed
    text = text.get_value
  when Exception
    text = text.to_s
  end
  ewin = _create_footer_window
  r = 0; c = 1;
  #aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
  # changed on 2011-12-6 
  color = aconfig[:color]
  bgcolor = aconfig[:bgcolor]
  color ||= :white
  bgcolor ||= :black
  color_pair = get_color($promptcolor, color, bgcolor)
  ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
  ewin.printstring r, c, text, color_pair
  ewin.printstring r+1, c, "[y/n]", color_pair
  ewin.wrefresh
  #retval = :NO # consistent with confirm  # CHANGE TO TRUE FALSE NOW 
  retval = false
  begin
    ch =  ewin.getchar 
    retval = (ch == 'y'.ord || ch == 'Y'.ord )
    # if caller passed a default value and user pressed ENTER return that
    # can be true or false so don't change this to "if default". 2011-12-8 
    if !default.nil?
      if ch == 13 || ch == KEY_ENTER
        retval = default
      end
    end
    #retval = :YES if ch.chr == 'y' 
  ensure
    ewin.destroy
  end
  retval
end

#status_window(aconfig = {}, &block) ⇒ Object

statuses during some process



348
349
350
# File 'lib/rbcurse/core/util/rdialogs.rb', line 348

def status_window aconfig={}, &block
  return StatusWindow.new aconfig
end

#textdialog(mess, config = {}) ⇒ Object

Alert user with a block of text. This will popup a textview in which the user can scroll Use this if you are not sure of the size of the text, such as printing a stack trace, exception

2011-12-25 just pass in an exceptino object and we do the rest


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rbcurse/core/util/rdialogs.rb', line 47

def textdialog mess, config={}
  if mess.is_a? Exception
    mess = [mess.to_s, *mess.backtrace]
    config[:title] ||= "Exception"
  end
  config[:title] ||= "Alert"
  tp = MessageBox.new config do
    button_type :ok
    text mess
  end
  tp.run
end