Top Level Namespace

Includes:
BorderTitle, Canis, Canis::ListBindings, Canis::Utils, Io, RubyCurses

Defined Under Namespace

Modules: Canis, Kernel, ListEditable, Ncurses, RubyCurses Classes: AbstractChunkLine, AbstractLayout, DefaultFileRenderer, FlowLayout, Integer, Module, Object, Split, SplitLayout, StackLayout, StatusWindow, String, 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.

THESE are now obsolete since we are moving to string based return values else they should be updated.

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
BOLD =

2013-03-21 - 187compat removed ||

FFI::NCurses::A_BOLD
REVERSE =
FFI::NCurses::A_REVERSE
UNDERLINE =
FFI::NCurses::A_UNDERLINE
NORMAL =
FFI::NCurses::A_NORMAL

Constants included from Canis

Canis::CANIS_DOCPATH, Canis::VERSION

Instance Method Summary collapse

Methods included from Canis::ListBindings

#bindings, #edit_external, #saveas, #saveas!

Methods included from Canis::Utils

#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping

Methods included from Canis

#_new_layout, #_update_default_settings, #choose_file, #command_list, #display_list, #display_text, #numbered_menu, #repaint_old, start_ncurses, startup, stop_ncurses

Methods included from Canis::ColorMap

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

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



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

def alert text, config={}

  if text.is_a? Canis::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:



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/canis/core/util/rdialogs.rb', line 210

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

  mb = Canis::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



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/canis/core/util/rdialogs.rb', line 579

def display_app_help form=@form
  raise "This is now deprecated, pls use @form.help_manager.display_help "
  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
      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

#display_submenu(hash, config = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/canis/core/util/rdialogs.rb', line 768

def display_submenu hash, config={}, &block
  raise ArgumentError, "Nil list / hash received by popuplist" unless hash
  if hash.is_a? Hash
    list = hash.keys
  else
    list = hash
  end
  raise ArgumentError, "Nil list received by popuplist" unless list

  max_visible_items = config[:max_visible_items]
  # FIXME have to ensure that row and col don't exceed FFI::NCurses.LINES and cols that is the window
  # should not FINISH outside or padrefresh will fail.
  row = config[:row] || 1
  col = config[:col] || 0
  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
  extra = 2 # trying to space the popup slightly, too narrow
  width = config[:width] || longest_in_list(list)+4 # borders take 2
  if config[:title]
    width = config[:title].size + 4 if width < config[:title].size + 4
  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 = Canis::Window.new(layout)
  window.name = "WINDOW:popuplist"
  window.wbkgd(Ncurses.COLOR_PAIR($reversecolor));
  form = Canis::Form.new window

  less = 0 # earlier 0
  listconfig = config[:listconfig] || {}
  listconfig[:list] = list
  listconfig[:width] = width - less
  listconfig[:height] = height
  listconfig[:selection_mode] ||= :single
  listconfig.merge!(config)
  listconfig.delete(:row); 
  listconfig.delete(:col); 
  # trying to pass populists block to listbox
  lb = Canis::Listbox.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.wrefresh
  Ncurses::Panel.update_panels
  form.repaint
  window.wrefresh
  return window, lb
end

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

Yields:

  • (Field)

    field created by messagebox



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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/canis/core/util/rdialogs.rb', line 86

def get_string label, config={} # yield Field
  config[:title] ||= "Entry"
  config[:title_color] ||= $reversecolor
  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[:color] ||= :black
  field_config[:bgcolor] ||= :cyan
  field_config[:maxlen] ||= config[:maxlen]
  field_config[:default] ||= config[:default]
  field_config[:default] = field_config[:default].chomp if field_config[:default]
  field_config[:name] = :name
  #field_config[:width] ||= 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[:width] || 50)

  defwid = config[:default].nil? ? 30 : config[:default].size + 13
  w = [label.size + 8, defwid, field_config[:width]+13 ].max
  config[:width] ||= w
  ## added history 2013-03-06 - 14:25 : we could keep history based on prompt
  $get_string_history ||= []
  #$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
    fld = Field.new nil, field_config
    item fld
    ## added field history 2013-03-06 - 14:24 
        require 'canis/core/include/rhistory'
        fld.extend(FieldHistory)
        # We need to manually set history each time, since the field is recreated
        # with the messagebox. Otherwise, field can on its own handle history
        fld.history($get_string_history)
  end
  # added yield to override settings
  yield tp.form.by_name[:name] if block_given?
  index = tp.run
  if index == 0 # OK
    ## added field history 2013-03-06 - 14:24 
    t = tp.form.by_name[:name].text
    $get_string_history << t if t && !$get_string_history.include?(t)
    return t
  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

#get_text(label, config = {}) {|textarea| ... } ⇒ Object

Yields:

  • (textarea)

    field created by messagebox



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/canis/core/util/rdialogs.rb', line 145

def get_text label, config={} # yield TextArea
  config[:title] ||= "Entry"
  config[:title_color] ||= $reversecolor
  label_config = config[:label_config] || {}
  label_config[:row] ||= 1
  label_config[:col] ||= 2
  label_config[:text] = label

  # I am not changing the name from field to text in case user wishes to swtch between the two
  field_config = config[:field_config] || {}
  field_config[:row] ||= 2
  field_config[:col] ||= 2
  #field_config[:attr] = :reverse
  field_config[:color] ||= :black
  field_config[:bgcolor] ||= :cyan
  #field_config[:maxlen] ||= config[:maxlen]
  #field_config[:text] ||= config[:default]
  #field_config[:default] = field_config[:default].chomp if field_config[:default]
  field_config[:name] = :name
  #field_config[:width] ||= 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

  defwid = config[:default].nil? ? 30 : config[:default].size + 13
  #w = [label.size + 8, defwid, field_config[:width]+13 ].max
  #config[:width] ||= w
  w = config[:width] = Ncurses.COLS - 5
  h = config[:height] = Ncurses.LINES - 5
  row = ((FFI::NCurses.LINES-h)/2).floor
  col = ((FFI::NCurses.COLS-w)/2).floor
  config[:row] = row
  config[:col] = col
  field_config[:width] ||= w - 7
  field_config[:height] ||= h - 6
  field_config[:suppress_borders] = true
  ## added history 2013-03-06 - 14:25 : we could keep history based on prompt
  $get_string_history ||= []
  #$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
    fld = TextArea.new nil, field_config
    item fld
    ## added field history 2013-03-06 - 14:24 
  end
  # added yield to override settings
  yield tp.form.by_name[:name] if block_given?
  index = tp.run
  if index == 0 # OK
    ## added field history 2013-03-06 - 14:24 
    t = tp.form.by_name[:name].text
    #$get_string_history << t if t && !$get_string_history.include?(t)
    return t
  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

#longest_in_list(list) ⇒ Object

returns length of longest

Raises:

  • (ArgumentError)


565
566
567
568
569
570
571
# File 'lib/canis/core/util/rdialogs.rb', line 565

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

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

2014-04-15 - 17:05 replaced rlist with listbox

Raises:

  • (ArgumentError)


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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/canis/core/util/rdialogs.rb', line 484

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

  max_visible_items = config[:max_visible_items]
  # FIXME have to ensure that row and col don't exceed FFI::NCurses.LINES and cols that is the window
  # should not FINISH outside or padrefresh will fail.
  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
  extra = 2 # trying to space the popup slightly, too narrow
  width = config[:width] || longest_in_list(list)+4 # borders take 2
  if config[:title]
    width = config[:title].size + 4 if width < config[:title].size + 4
  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 = Canis::Window.new(layout)
  window.name = "WINDOW:popuplist"
  window.wbkgd(Ncurses.COLOR_PAIR($reversecolor));
  form = Canis::Form.new window

  less = 0 # earlier 0
  listconfig = config[:listconfig] || {}
  listconfig[:list] = list
  listconfig[:width] = width - less
  listconfig[:height] = height
  listconfig[:selection_mode] ||= :single
  listconfig.merge!(config)
  listconfig.delete(:row); 
  listconfig.delete(:col); 
  # trying to pass populists block to listbox
  lb = Canis::Listbox.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.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
          # now returns empty array not nil
          return x if x and !x.empty?
          x = lb.current_index
          return [x]
          # if multiple selection, then return list of selected_indices and don't catch 32
        elsif ch == $row_selector      # if single selection, earlier 32
          return lb.current_index if lb.selection_mode != :multiple
        end
        #yield ch if block_given?
      end
    end
  ensure
    window.destroy  
  end
  return nil
end

#popupmenu(hash, config = {}, &block) ⇒ Object

this is a quick dirty menu/popup menu thing, hopnig to replace the complex menubar with something simpler. However, the cursor visually is confusing. since the display takes over the cursor visually. When we display on the right it looks as tho the right menu is active. When we actually move into it with RIGHT, it looks like the left on is active. OKAY, we temporarily fixed that by not opening it until you actually press RIGHT FIXME : there is the issue of when one level is destroyed then the main one has a blank. all need to be

repainted.

FIXME : when diong a LEFT, cursor shows at last row of previous , we need a curpos or setrow for that lb

Raises:

  • (ArgumentError)


604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/canis/core/util/rdialogs.rb', line 604

def popupmenu hash, config={}, &block
  if hash.is_a? Hash
    list = hash.keys
  else
    list = hash
  end
  raise ArgumentError, "Nil list received by popuplist" unless list
  #require 'canis/core/widgets/rlist'

  max_visible_items = config[:max_visible_items]
  # FIXME have to ensure that row and col don't exceed FFI::NCurses.LINES and cols that is the window
  # should not FINISH outside or padrefresh will fail.
  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
  extra = 2 # trying to space the popup slightly, too narrow
  width = config[:width] || longest_in_list(list)+4 # borders take 2
  if config[:title]
    width = config[:title].size + 4 if width < config[:title].size + 4
  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 = Canis::Window.new(layout)
  window.name = "WINDOW:popuplist"
  window.wbkgd(Ncurses.COLOR_PAIR($reversecolor));
  form = Canis::Form.new window

  right_actions = config[:right_actions] || {}
  config.delete(:right_actions)
  less = 0 # earlier 0
  listconfig = config[:listconfig] || {}
  listconfig[:list] = list
  listconfig[:width] = width - less
  listconfig[:height] = height
  listconfig[:selection_mode] ||= :single
  listconfig.merge!(config)
  listconfig.delete(:row); 
  listconfig.delete(:col); 
  # trying to pass populists block to listbox
  lb = Canis::Listbox.new form, listconfig, &block
  #lb.should_show_focus = true
  #$row_focussed_attr = REVERSE

  
  # 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.wrefresh
  Ncurses::Panel.update_panels
  form.repaint
  window.wrefresh
          display_on_enter = false
  begin
    windows = []
    lists = []
    hashes = []
    choices = []
    unentered_window = nil
    _list = nil
    while((ch = window.getchar()) != 999 )
      case ch
      when -1
        next
      when ?\C-q.getbyte(0)
        break
      else
        lb.handle_key ch
        lb.form.repaint
        if ch == Ncurses::KEY_DOWN or ch == Ncurses::KEY_UP
          if unentered_window
            unentered_window.destroy
            unentered_window = nil
          end
          # we need to update hash as we go along and back it up.
          if display_on_enter
            # removed since cursor goes in
          end
        elsif ch == Ncurses::KEY_RIGHT
          if hash.is_a? Hash
            val = hash[lb.current_value]
            if val.is_a? Hash or val.is_a? Array
              unentered_hash = val
              choices << lb.current_value
              unentered_window, _list = display_submenu val, :row => lb.current_index, :col => lb.width, :relative_to => lb, 
                :bgcolor => :cyan
            end
          else
            x = right_actions[lb.current_value]
            val = nil
            if x.respond_to? :call
              val = x.call
            elsif x.is_a? Symbol
              val = send(x)
            end
            if val
              choices << lb.current_value
              unentered_hash = val
              unentered_window, _list = display_submenu val, :row => lb.current_index, :col => lb.width, :relative_to => lb, 
                :bgcolor => :cyan
            end

          end
          # move into unentered
          if unentered_window
            lists << lb
            hashes << hash
            hash = unentered_hash
            lb = _list
            windows << unentered_window
            unentered_window = nil
            _list = nil
          end
        elsif ch == Ncurses::KEY_LEFT
          if unentered_window
            unentered_window.destroy
            unentered_window = nil
          end
          # close current window
          curr = nil
          curr = windows.pop unless windows.empty?
          curr.destroy if curr
          lb = lists.pop unless lists.empty?
          hash = hashes.pop unless hashes.empty?
          choices.pop unless choices.empty?
          unless windows.empty?
            #form = windows.last
            #lb - lists.pop
          end
        end
        if ch == 13 || ch == 10
          val = lb.current_value
          if hash.is_a? Hash
            val = hash[val]
            if val.is_a? Symbol
              #alert "got #{val}"
              #return val
              choices << val
              return choices
            end
          else
            #alert "got value #{val}"
            #return val
            choices << val
            return choices
          end
          break
        end
      end
    end
  ensure
    window.destroy   if window
    windows.each do |w| w.destroy if w ; end
  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

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)



259
260
261
# File 'lib/canis/core/util/rdialogs.rb', line 259

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)



247
248
249
# File 'lib/canis/core/util/rdialogs.rb', line 247

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



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/canis/core/util/rdialogs.rb', line 460

def progress_dialog aconfig={}, &block
  aconfig[:layout] = [10,60,10,20]
  # since we are printing a border
  aconfig[:row_offset] ||= 4
  aconfig[:col_offset] ||= 5
  window = status_window aconfig
  window.win.name = "WINDOW::progress_dialog"
  height = 10; width = 60
  window.win.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
  return window unless block_given?
  begin
    yield window
  ensure
    window.destroy if window
  end
end

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



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/canis/core/util/rdialogs.rb', line 318

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 Canis::Variable # added 2011-09-20 incase variable passed
    text = text.get_value
  when Exception
    text = text.to_s
  end
  ewin = _create_footer_window
  ewin.name = "WINDOW::rb_confirm"
  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

returns instance of a status_window for sending multiple statuses during some process TODO FIXME block got ignored



447
448
449
450
451
452
453
454
455
456
# File 'lib/canis/core/util/rdialogs.rb', line 447

def status_window aconfig={}, &block
  sw = StatusWindow.new aconfig
  sw.win.name = "WINDOW::status_window"
  return sw unless block_given?
  begin
    yield sw
  ensure
    sw.destroy if sw
  end
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


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/canis/core/util/rdialogs.rb', line 48

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
  tv = tp.form.by_name["message_label"]
  # 2014-04-15 so that ENTER can hit okay without tabbing to button. FIX IN RBC
  tv.unbind_key(KEY_ENTER)
  tp.run
end

#treedialog(hash, config = {}) ⇒ Object

Used to popup and view a hash in a dialog. User may press ENTER or o to expand nodes

and other keys such as "x" to close nodes.


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/canis/core/util/rdialogs.rb', line 66

def treedialog hash, config={}
  config[:title] ||= "Alert"
  tp = MessageBox.new config do
    button_type :ok
    tree hash
  end
  # Not having as default means i can only press SPACE and that is confusing since we are used to pressing
  #  ENTER on textdialog
  #tp.default_button = 10  # i don't want a default since ENTER is trapped by tree
  #tv = tp.form.by_name["message_label"]
  # 2014-04-15 so that ENTER can hit okay without tabbing to button. FIX IN RBC
  #tv.unbind_key(KEY_ENTER)
  tp.run
end