Exemplo n.º 1
0
		public static void Run(Container container)
		{
			container = new ApplicationContainer(container);

			if (Context == null) {
				throw new Exception("You have to initialize the application with a context");
			}

			if (container.CanFocus) {
				container.HasFocus = true;
			}

			// draw everything and refresh curses
			container.SetDim(0, 0, Curses.Terminal.Width, Curses.Terminal.Height);

			container.Redraw();
			container.SetCursorPosition();
			Curses.Refresh();

			sw = new SignalWatcher(Context, Signum.SIGWINCH , () => {
				Curses.resizeterm(Console.WindowHeight, Console.WindowWidth);
				keyaction(Curses.Key.Resize);
			});

			keyaction = (key) => {
				if (key == QuitKey) {
					sw.Stop();
					Context.Stop();
				} else if (key == -2) {
					container.Redraw();
					container.SetCursorPosition();
					Curses.Refresh();
				} else if (key == Curses.Key.Resize) {
					container.SetDim(0, 0, Curses.Terminal.Width, Curses.Terminal.Height);
					container.ProcessKey(Curses.Key.Resize);
					container.ForceRedraw();
					container.SetCursorPosition();
					Curses.Refresh();
				} else {
					container.ProcessKey(key);
				}
			};

			stdin = Context.OpenStdin();
			stdin.Ready(() => {
				keyaction(Curses.getch());
			});

			sw.Start();

			Context.CreateIdleWatcher(() => {
				if (container.Invalid) {
					keyaction(-2);
				}
			}).Start();

			if (colors != null) {
				Curses.Terminal.SetColors(colors);
			}

			Context.Start();
			Context.Dispose();
			OnEnd();

			Window.End();
			Running = false;

			Context = null;
		}