class StatusWindow

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

Attributes

color_pair[RW]
h[R]
left[R]
top[R]
w[R]
win[R]

Public Class Methods

new(config={}) click to toggle source
# File lib/canis/core/util/rdialogs.rb, line 377
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

Public Instance Methods

create_window(h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0) click to toggle source
# File lib/canis/core/util/rdialogs.rb, line 383
def create_window h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0
  return @win if @win
  @win = Canis::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
destroy() click to toggle source

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

# File lib/canis/core/util/rdialogs.rb, line 434
def destroy; @win.destroy if @win; @win = nil;  end
hide() click to toggle source
# File lib/canis/core/util/rdialogs.rb, line 435
def hide
  @win.hide
  @visible = false
end
linger(caller_window=nil) click to toggle source

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.

# File lib/canis/core/util/rdialogs.rb, line 420
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
pause() click to toggle source
# File lib/canis/core/util/rdialogs.rb, line 416
def pause; @win.getchar; end
print(*textarray) click to toggle source

print given strings from first first column onwards

printstring(r, c, text, color_pair=@color_pair) click to toggle source
creates a color pair based on given bg and fg colors as strings

def set_colors bgcolor, fgcolor='white' @color_pair = get_color($datacolor, 'white','black') end

prints a string on given row (0 or 1)
# File lib/canis/core/util/rdialogs.rb, line 396
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
show() click to toggle source
# File lib/canis/core/util/rdialogs.rb, line 439
def show
  @win.show unless @visible
  @visible = true
end