/// <summary>
/// Starts running a new container or dialog box.
/// </summary>
/// <remarks>
/// Use this method if you want to start the dialog, but
/// you want to control the main loop execution manually
/// by calling the RunLoop method (for example, to start
/// the dialog, but continuing to process events).
///
/// Use the returned value as the argument to RunLoop
/// and later to the End method to remove the container
/// from the screen.
/// </remarks>
public static RunState Begin(Container container)
{
if (container == null)
throw new ArgumentNullException ("container");
var rs = new RunState (container);
Init (false);
Curses.timeout (-1);
toplevels.Add (container);
container.Prepare ();
container.SizeChanged ();
container.FocusFirst ();
Redraw (container);
container.PositionCursor ();
Curses.refresh ();
return rs;
}