Class: RubyCurses::MessageBox
- Includes:
- BorderTitle, Utils
- Defined in:
- lib/rbcurse/core/widgets/rmessagebox.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #command(*args, &blk) ⇒ Object
-
#initialize(config = {}, &block) ⇒ MessageBox
constructor
dsl_accessor :message you can also set button_orientation : :right, :left, :center.
- #item(widget) ⇒ Object (also: #add)
-
#message(message) { ... } ⇒ Object
(also: #message=)
Pass a short message to be printed.
- #repaint ⇒ Object
-
#run ⇒ Object
returns button index Call this after instantiating the window.
-
#text(message) {|message_label| ... } ⇒ Object
(also: #text=)
This is for larger messages, or messages where the size is not known.
-
#widget(n) ⇒ Object
returns a widget based on offset, or name (if you gave it a :name) e.g.
-
#widgets ⇒ Object
returns array of widgets declared for querying.
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 BorderTitle
#bordertitle_init, #print_borders, #print_title
Constructor Details
#initialize(config = {}, &block) ⇒ MessageBox
dsl_accessor :message you can also set button_orientation : :right, :left, :center
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 45 def initialize config={}, &block h = config.fetch(:height, nil) w = config.fetch(:width, nil) t = config.fetch(:row, nil) l = config.fetch(:col, nil) if h && w && t && l @window = VER::Window.new :height => h, :width => w, :top => t, :left => l @graphic = @window end @form = Form.new @window config.each_pair { |k,v| instance_variable_set("@#{k}",v) } @config = config @row = 0 @col = 0 @row_offset = 1 @col_offset = 2 #bordertitle_init @color ||= :black @bgcolor ||= :white @maxrow = 3 #instance_eval &block if block_given? yield_or_eval &block if block_given? end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
33 34 35 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 33 def form @form end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
34 35 36 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 34 def window @window end |
Instance Method Details
#command(*args, &blk) ⇒ Object
352 353 354 355 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 352 def command *args, &blk @command = blk @args = args end |
#item(widget) ⇒ Object Also known as: add
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 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 72 def item # remove from existing form if set FIXME if .form f = .form f. end @maxrow ||= 3 .set_form @form .row ||= 0 .col ||= 0 if .row == 0 .row = [@maxrow+1, 3].max if .row == 0 else .row += @row_offset end if .col === 0 .col = 5 if .col === 0 else # i don't know button_offset as yet .col += @col_offset end # in most cases this override is okay, but what if user has set it # The problem is that widget and field are doing a default setting so i don't know # if user has set or widget has done a default setting. NOTE .color ||= @color # we are overriding colors, how to avoid since widget sets it .bgcolor ||= @bgcolor .attr = @attr if @attr # we are overriding what user has put. DARN ! @maxrow = .row if .row > @maxrow @suggested_h = @height || @maxrow+6 @suggested_w ||= 0 @suggested_w = .col + 15 if .col > @suggested_w # if w's given col is > width then add to suggested_w or text.length end |
#message(message) { ... } ⇒ Object Also known as: message=
Pass a short message to be printed. This creates a label for a short message, and a field for a long one.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 138 def # yield label or field being used for display for further customization @suggested_h = @height || 10 = .gsub(/[\n\r\t]/,' ') rescue = 5 @suggested_w = @width || [.size + 8 + , FFI::NCurses.COLS-2].min r = 3 len = .length @suggested_w = len + 8 + if len < @suggested_w - 8 - display_length = @suggested_w-8 display_length -= = 2 clr = @color || :white bgclr = @bgcolor || :black # trying this out. sometimes very long labels get truncated, so i give a field in wchich user # can use arrow key or C-a and C-e if .size > display_length = RubyCurses::Field.new @form, {:text => , :name=>"message_label", :row => r, :col => , :display_length => display_length, :bgcolor => bgclr , :color => clr, :editable => false} else = RubyCurses::Label.new @form, {:text => , :name=>"message_label", :row => r, :col => , :display_length => display_length, :height => , :bgcolor => bgclr , :color => clr} end @maxrow = 3 yield if block_given? end |
#repaint ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 114 def repaint _create_window unless @window acolor = get_color $reverscolor # this implicitly uses color and bgcolor fooling me often $log.debug " MESSAGE BOX bg:#{@bgcolor} , co:#{@color} , colorpair:#{acolor}" @window.wbkgd(Ncurses.COLOR_PAIR(acolor)); # does not work on xterm-256color #print_borders unless @suppress_borders # do this once only, unless everything changes #@window.print_border_mb 1,2, @height, @width, $normalcolor, FFI::NCurses::A_REVERSE @color_pair = get_color($datacolor) bordercolor = @border_color || @color_pair borderatt = @border_attrib || Ncurses::A_NORMAL @window.wattron(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL)) @window.print_border_mb 1,2, @height, @width, bordercolor, borderatt @window.wattroff(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL)) @title ||= "+-+" title = " "+@title+" " @window.printstring(@row=1,@col=(@width-title.length)/2,title, color=$normalcolor) #print_message if @message unless @action_buttons end |
#run ⇒ Object
returns button index Call this after instantiating the window
108 109 110 111 112 113 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 108 def run repaint @form.repaint @window.wrefresh return handle_keys end |
#text(message) {|message_label| ... } ⇒ Object Also known as: text=
This is for larger messages, or messages where the size is not known. A textview object is created and yielded.
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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 172 def text @suggested_w = @width || (FFI::NCurses.COLS * 0.80).floor @suggested_h = @height || (FFI::NCurses.LINES * 0.80).floor = 3 r = 2 display_length = @suggested_w-4 display_length -= clr = @color || :white bgclr = @bgcolor || :black if .is_a? Array l = longest_in_list if l > @suggested_w if l < FFI::NCurses.COLS #@suggested_w = l @suggested_w = FFI::NCurses.COLS-2 else @suggested_w = FFI::NCurses.COLS-2 end display_length = @suggested_w-6 end # reduce width and height if you can based on array contents else = wrap_text(, display_length).split("\n") end = .size + 8 # reduce if possible if its not required. # r1 = (FFI::NCurses.LINES-@suggested_h)/2 r1 = r1.floor w = @suggested_w c1 = (FFI::NCurses.COLS-w)/2 c1 = c1.floor @suggested_row = r1 @suggested_col = c1 brow = @button_row || @suggested_h-4 available_ht = brow - r + 1 = [, available_ht].min require 'rbcurse/core/widgets/rtextview' = RubyCurses::TextView.new @form, {:name=>"message_label", :text => , :row => r, :col => , :width => display_length, :suppress_borders => true, :height => , :bgcolor => bgclr , :color => clr} #message_label.set_content message yield if block_given? end |
#widget(n) ⇒ Object
returns a widget based on offset, or name (if you gave it a :name) e.g. a list was declared and we wish to know the selected_indices
362 363 364 365 366 367 368 369 370 371 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 362 def n case n when Fixnum @form.[n] when String, Symbol @form.by_name[n] else raise "messagebox.widget can't handle #{n.class} " end end |
#widgets ⇒ Object
returns array of widgets declared for querying
357 358 359 |
# File 'lib/rbcurse/core/widgets/rmessagebox.rb', line 357 def @form. end |