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, Fixnum, FlowLayout, 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
-
#alert(text, config = {}) ⇒ Object
– moving to the new Messagebox 2011-11-19 v 1.5.0 Alert user with a one line message.
- #confirm(text, config = {}) {|Label| ... } ⇒ Object
-
#display_app_help(form = @form) ⇒ Object
earlier in app.rb.
- #get_string(label, config = {}) {|Field| ... } ⇒ Object
-
#longest_in_list(list) ⇒ Object
returns length of longest.
-
#popuplist(list, config = {}, &block) ⇒ Object
2014-04-15 - 17:05 replaced rlist with listbox.
-
#print_error_message(text, aconfig = {}, &block) ⇒ Object
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.
-
#print_status_message(text, aconfig = {}, &block) ⇒ Object
(also: #rb_puts, #say)
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.
-
#progress_dialog(aconfig = {}, &block) ⇒ Object
the line, I might overwrite the box.
- #rb_confirm(text, aconfig = {}, &block) ⇒ Object (also: #agree)
-
#status_window(aconfig = {}, &block) ⇒ Object
returns instance of a status_window for sending multiple statuses during some process TODO FIXME block got ignored.
-
#textdialog(mess, config = {}) ⇒ Object
Alert user with a block of text.
Methods included from Canis::ListBindings
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 :ok text #text mess end tp.run end |
#confirm(text, config = {}) {|Label| ... } ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/canis/core/util/rdialogs.rb', line 127 def confirm text, config={}, &block title = config['title'] || "Confirm" config[:default_button] ||= 0 mb = Canis::MessageBox.new config do title title text, &block :yes_no end index = mb.run return index == 0 end |
#display_app_help(form = @form) ⇒ Object
earlier in app.rb
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/canis/core/util/rdialogs.rb', line 489 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 |
#get_string(label, config = {}) {|Field| ... } ⇒ Object
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/canis/core/util/rdialogs.rb', line 69 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[: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 :ok_cancel 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 |
#longest_in_list(list) ⇒ Object
returns length of longest
475 476 477 478 479 480 481 |
# File 'lib/canis/core/util/rdialogs.rb', line 475 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
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 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 473 |
# File 'lib/canis/core/util/rdialogs.rb', line 397 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 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 = Canis::Window.new(layout) form = Canis::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 = 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.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 # 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 |
#print_error_message(text, aconfig = {}, &block) ⇒ Object
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
176 177 178 |
# File 'lib/canis/core/util/rdialogs.rb', line 176 def text, aconfig={}, &block :error, text, aconfig, &block end |
#print_status_message(text, aconfig = {}, &block) ⇒ Object Also known as: rb_puts, say
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
164 165 166 |
# File 'lib/canis/core/util/rdialogs.rb', line 164 def text, aconfig={}, &block :status, text, aconfig, &block end |
#progress_dialog(aconfig = {}, &block) ⇒ Object
the line, I might overwrite the box
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/canis/core/util/rdialogs.rb', line 374 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 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
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 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/canis/core/util/rdialogs.rb', line 234 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 = 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
362 363 364 365 366 367 368 369 370 |
# File 'lib/canis/core/util/rdialogs.rb', line 362 def status_window aconfig={}, &block sw = StatusWindow.new aconfig 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 :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 |