Class: StatusWindow

Inherits:
Object show all
Defined in:
lib/rbcurse/rdialogs.rb

Overview

class created to display multiple messages without asking for user to hit a key returns a window to which one can keep calling printstring with 0 or 1 as row. destroy when finished. Also, one can pause if one wants, or linger. This is meant to be a replacement for the message_immediate and message_raw I was trying out in App.rb. 2011-10-1 1:27 AM Testing from test2.rb TODO: add option of putting progress_bar

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (StatusWindow) initialize(config = {}, &block)



263
264
265
266
267
268
# File 'lib/rbcurse/rdialogs.rb', line 263

def initialize config={}, &block
  @color_pair = config[:color_pair]
  @row_offset = config[:row_offset] || 0
  @col_offset = config[:col_offset] || 0
  create_window *config[:layout]
end

Instance Attribute Details

- (Object) color_pair

Returns the value of attribute color_pair



262
263
264
# File 'lib/rbcurse/rdialogs.rb', line 262

def color_pair
  @color_pair
end

- (Object) h (readonly)

height, width, top row, left col of window



260
261
262
# File 'lib/rbcurse/rdialogs.rb', line 260

def h
  @h
end

- (Object) left (readonly)

height, width, top row, left col of window



260
261
262
# File 'lib/rbcurse/rdialogs.rb', line 260

def left
  @left
end

- (Object) top (readonly)

height, width, top row, left col of window



260
261
262
# File 'lib/rbcurse/rdialogs.rb', line 260

def top
  @top
end

- (Object) w (readonly)

height, width, top row, left col of window



260
261
262
# File 'lib/rbcurse/rdialogs.rb', line 260

def w
  @w
end

- (Object) win (readonly)

Returns the value of attribute win



261
262
263
# File 'lib/rbcurse/rdialogs.rb', line 261

def win
  @win
end

Instance Method Details

- (Object) create_window(h = 2, w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0)



269
270
271
272
273
274
275
276
# File 'lib/rbcurse/rdialogs.rb', line 269

def create_window h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0
  return @win if @win
  @win = VER::Window.new(h, w , t, l)
  @h = h ; @w = w; @top = t ; @left = l
  @color_pair ||= get_color($promptcolor, 'white','black')
  @win.bkgd(Ncurses.COLOR_PAIR(@color_pair));
  @win
end

- (Object) destroy

caller must destroy after he's finished printing messages, unless user calls linger



320
# File 'lib/rbcurse/rdialogs.rb', line 320

def destroy; @win.destroy if @win; @win = nil;  end

- (Object) hide



321
322
323
324
# File 'lib/rbcurse/rdialogs.rb', line 321

def hide
  @win.hide
  @visible = false
end

- (Object) linger(caller_window = nil)

pauses with the message, but doesn't ask the user to press a key. If he does, the key should be used by underlying window. Do not call destroy if you call linger, it does the destroy.



306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/rbcurse/rdialogs.rb', line 306

def linger caller_window=nil
  begin
    if caller_window
      ch = @win.getchar
      caller_window.ungetch(ch) # will this be available to underlying window XXX i think not !!
    else
      sleep 1
    end
  ensure
    destroy
  end
end

- (Object) pause



302
# File 'lib/rbcurse/rdialogs.rb', line 302

def pause; @win.getchar; end

print given strings from first first column onwards



293
294
295
296
297
298
299
300
301
# File 'lib/rbcurse/rdialogs.rb', line 293

def print *textarray
  create_window unless @win
  show unless @visible
  c = 1
  textarray.each_with_index { |s, i|  
    @win.printstring i+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, s], @color_pair
  }
  @win.wrefresh
end

- (Object) printstring(r, c, text, color_pair = @color_pair)

end prints a string on given row (0 or 1)



282
283
284
285
286
287
288
289
290
291
# File 'lib/rbcurse/rdialogs.rb', line 282

def printstring r, c, text, color_pair=@color_pair
  create_window unless @win
  show unless @visible
  r = @h-1 if r > @h-1
  #@win.printstring r, c, ' '*@w, @color_pair
  # FIXME this padding overwrites the border and the offset means next line wiped
  # However, now it may now totally clear a long line.
  @win.printstring r+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, text], color_pair
  @win.wrefresh
end

- (Object) show



325
326
327
328
# File 'lib/rbcurse/rdialogs.rb', line 325

def show
  @win.show unless @visible
  @visible = true
end