
import sys
import errors
import window

def msgbox (win, prompt, waitforkey=True):

    lines = prompt.split ('\n')
    # Determine size of needed window
    rows = len (lines)
    cols = 0
    for l in lines:
        if len (l) > cols: cols = len (l)
        pass

    # Center on screen
    y = win.height/2 - rows/2
    x = win.width/2 - cols/2
    subwin = win.newwin (rows+2, cols+2, y, x)
        
    subwin.border ()
    lidx = 0
    for ltxt in lines:
        subwin.addstr (1+lidx,1,ltxt)
        lidx += 1
        pass

    if waitforkey: subwin.getch ()
    return

def test (scr):
    msgbox (scr, sys.argv[1])
    msgbox (scr, "Multiple\nline\ntest")
    pass
        
if __name__ == "__main__":
    window.start (test)
    pass
