Ejemplo 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;
		}
Ejemplo n.º 2
0
		public ApplicationContainer(Container container)
		{
			Container = container;
			Container.Container = this;
		}
Ejemplo n.º 3
0
        static void ProcessChar(Container container)
        {
            int ch = Curses.getch ();

            if ((ch == -1) || (ch == Curses.KeyResize)){
                if (Curses.CheckWinChange ()){
                    EmptyContainer.Clear ();
                    foreach (Container c in toplevels)
                        c.SizeChanged ();
                    Refresh ();
                }
                return;
            }

            if (ch == Curses.KeyMouse){
                Curses.MouseEvent ev;

                Curses.console_sharp_getmouse (out ev);
                container.ProcessMouse (ev);
                return;
            }

            if (ch == 27){
                Curses.timeout (100);
                int k = Curses.getch ();
                if (k != Curses.ERR && k != 27)
                    ch = Curses.KeyAlt | k;
                Curses.timeout (-1);
            }

            if (container.ProcessHotKey (ch))
                return;

            if (container.ProcessKey (ch))
                return;

            if (container.ProcessColdKey (ch))
                return;

            // Control-c, quit the current operation.
            if (ch == 3){
                container.Running = false;
                return;
            }

            // Control-z, suspend execution, then repaint.
            if (ch == 26){
                Curses.console_sharp_sendsigtstp ();
                Window.Standard.redrawwin ();
                Curses.refresh ();
            }

            //
            // Focus handling
            //
            if (ch == 9 || ch == Curses.KeyDown || ch == Curses.KeyRight){
                if (!container.FocusNext ())
                    container.FocusNext ();
                Curses.refresh ();
            } else if (ch == Curses.KeyUp || ch == Curses.KeyLeft){
                if (!container.FocusPrev ())
                    container.FocusPrev ();
                Curses.refresh ();
            }
        }
Ejemplo n.º 4
0
 static void Redraw(Container container)
 {
     container.Redraw ();
     Curses.refresh ();
 }
Ejemplo n.º 5
0
 /// <summary>
 ///   Runs the main loop on the given container.
 /// </summary>
 /// <remarks>
 ///   This method is used to start processing events
 ///   for the main application, but it is also used to
 ///   run modal dialog boxes.
 /// </remarks>
 public static void Run(Container container)
 {
     var runToken = Begin (container);
     RunLoop (runToken);
     End (runToken);
 }
Ejemplo n.º 6
0
 // Called by the Dispose handler.
 internal static void End(Container container)
 {
     toplevels.Remove (container);
     if (toplevels.Count == 0)
         Shutdown ();
     else
         Refresh ();
 }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
        /// <summary>
        ///    Initializes the runtime.   The boolean flag
        ///   indicates whether we are forcing color to be off.
        /// </summary>
        public static void Init(bool disable_color)
        {
            if (inited)
                return;
            inited = true;

            empty_container = new Container (0, 0, Application.Cols, Application.Lines);

            try {
                main_window = Curses.initscr ();
            } catch (Exception e){
                Console.WriteLine ("Curses failed to initialize, the exception is: " + e);
                throw new Exception ("Application.Init failed");
            }
            Curses.raw ();
            Curses.noecho ();
            //Curses.nonl ();
            Window.Standard.keypad (true);

            #if BREAK_UTF8_RENDERING
            Curses.Event old = 0;
            MouseEventsAvailable = Curses.console_sharp_mouse_mask (
                Curses.Event.Button1Clicked | Curses.Event.Button1DoubleClicked, out old);
            #endif

            UsingColor = false;
            if (!disable_color)
                UsingColor = Curses.has_colors ();

            Curses.start_color ();
            Curses.use_default_colors ();
            if (UsingColor){
                ColorNormal = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLUE);
                ColorFocus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                ColorHotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLUE);
                ColorHotFocus = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);

                ColorMenu = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_CYAN);
                ColorMenuHot = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
                ColorMenuSelected = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLACK);
                ColorMenuHotSelected = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLACK);

                ColorMarked = ColorHotNormal;
                ColorMarkedSelected = ColorHotFocus;

                ColorDialogNormal    = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                ColorDialogFocus     = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                ColorDialogHotNormal = MakeColor (Curses.COLOR_BLUE,  Curses.COLOR_WHITE);
                ColorDialogHotFocus  = MakeColor (Curses.COLOR_BLUE,  Curses.COLOR_CYAN);

                ColorError = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_RED);
                ColorErrorFocus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                ColorErrorHot = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_RED);
                ColorErrorHotFocus = ColorErrorHot;
            } else {
                ColorNormal = Curses.A_NORMAL;
                ColorFocus = Curses.A_REVERSE;
                ColorHotNormal = Curses.A_BOLD;
                ColorHotFocus = Curses.A_REVERSE | Curses.A_BOLD;

                ColorMenu = Curses.A_REVERSE;
                ColorMenuHot = Curses.A_NORMAL;
                ColorMenuSelected = Curses.A_BOLD;
                ColorMenuHotSelected = Curses.A_NORMAL;

                ColorMarked = Curses.A_BOLD;
                ColorMarkedSelected = Curses.A_REVERSE | Curses.A_BOLD;

                ColorDialogNormal = Curses.A_REVERSE;
                ColorDialogFocus = Curses.A_NORMAL;
                ColorDialogHotNormal = Curses.A_BOLD;
                ColorDialogHotFocus = Curses.A_NORMAL;

                ColorError = Curses.A_BOLD;
            }
            ColorBasic = MakeColor (-1, -1);
            mainloop = new MainLoop ();
            mainloop.AddWatch (0, MainLoop.Condition.PollIn, x => {
                Container top = toplevels.Count > 0 ? toplevels [toplevels.Count-1] : null;
                if (top != null)
                    ProcessChar (top);

                return true;
            });
        }
Ejemplo n.º 9
0
 /// <summary>
 ///   Public constructor for widgets
 /// </summary>
 /// <remarks>
 ///   <para>
 ///      Constructs a widget that starts at positio (x,y) and has width w and height h.
 ///      These parameters are used by the methods <see cref="Clear"/> and <see cref="Redraw"/>
 ///   </para>
 /// </remarks>
 public Widget(int x, int y, int w, int h)
 {
     this.x = x;
     this.y = y;
     this.w = w;
     this.h = h;
     Container = Application.EmptyContainer;
 }
Ejemplo n.º 10
0
 public virtual void Dispose(bool disposing)
 {
     if (Container != null){
         Application.End (Container);
         Container = null;
     }
 }
Ejemplo n.º 11
0
 internal RunState(Container container)
 {
     Container = container;
 }
Ejemplo n.º 12
0
        /// <summary>
        ///   Runs the main loop on the given container.
        /// </summary>
        /// <remarks>
        ///   This method is used to start processing events
        ///   for the main application, but it is also used to
        ///   run modal dialog boxes.
        /// </remarks>
        public static void Run(Container container)
        {
            Init (false);

            Curses.timeout (-1);
            if (toplevels.Count == 0)
                InitApp ();

            toplevels.Add (container);

            container.Prepare ();
            container.SizeChanged ();
            container.FocusFirst ();
            Redraw (container);
            container.PositionCursor ();

            int ch;
            Curses.timeout (Timeout);

            for (container.Running = true; container.Running; ){
                ch = Curses.getch ();

                if (Iteration != null)
                    Iteration (null, EventArgs.Empty);

                if (ch == -1){
                    if (Curses.CheckWinChange ()){
                        EmptyContainer.Clear ();
                        foreach (Container c in toplevels)
                            c.SizeChanged ();
                        Refresh ();
                    }
                    continue;
                }

                if (ch == Curses.KeyMouse){
                    Curses.MouseEvent ev;

                    Curses.console_sharp_getmouse (out ev);
                    container.ProcessMouse (ev);
                    continue;
                }

                if (ch == 27){
                    Curses.timeout (100);
                    int k = Curses.getch ();
                    if (k != Curses.ERR && k != 27)
                        ch = Curses.KeyAlt | k;
                    Curses.timeout (Timeout);
                }

                if (container.ProcessHotKey (ch))
                    continue;

                if (container.ProcessKey (ch))
                    continue;

                if (container.ProcessColdKey (ch))
                    continue;

                // Control-c, quit the current operation.
                if (ch == 3)
                    break;

                // Control-z, suspend execution, then repaint.
                if (ch == 26){
                    Curses.console_sharp_sendsigtstp ();
                    Window.Standard.redrawwin ();
                    Curses.refresh ();
                }

                //
                // Focus handling
                //
                if (ch == 9 || ch == Curses.KeyDown || ch == Curses.KeyRight){
                    if (!container.FocusNext ())
                        container.FocusNext ();
                    continue;
                } else if (ch == Curses.KeyUp || ch == Curses.KeyLeft){
                    if (!container.FocusPrev ())
                        container.FocusPrev ();
                    continue;
                }

            }

            toplevels.Remove (container);
            if (toplevels.Count == 0)
                Shutdown ();
            else
                Refresh ();
        }
Ejemplo n.º 13
0
        /// <summary>
        ///    Initializes the runtime.   The boolean flag
        ///   indicates whether we are forcing color to be off.
        /// </summary>
        public static void Init(bool disable_color)
        {
            empty_container = new Container (0, 0, Application.Cols, Application.Lines);

            try {
                main_window = Curses.initscr ();
            } catch (Exception e){
                Console.WriteLine ("Curses failed to initialize, the exception is: " + e);
                throw new Exception ("Application.Init failed");
            }

            if (inited)
                return;
            inited = true;

            Curses.Event old = 0;
            MouseEventsAvailable = Curses.console_sharp_mouse_mask (
                Curses.Event.Button1Clicked | Curses.Event.Button1DoubleClicked, out old);

            UsingColor = false;
            if (!disable_color)
                UsingColor = Curses.has_colors ();

            Curses.start_color ();
            Curses.use_default_colors ();
            if (UsingColor){
                ColorNormal = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLUE);
                ColorFocus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                ColorHotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLUE);
                ColorHotFocus = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);

                ColorMenu = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_CYAN);
                ColorMenuHot = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
                ColorMenuSelected = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLACK);
                ColorMenuHotSelected = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLACK);

                ColorMarked = ColorHotNormal;
                ColorMarkedSelected = ColorHotFocus;

                ColorDialogNormal    = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_WHITE);
                ColorDialogFocus     = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
                ColorDialogHotNormal = MakeColor (Curses.COLOR_BLUE,  Curses.COLOR_WHITE);
                ColorDialogHotFocus  = MakeColor (Curses.COLOR_BLUE,  Curses.COLOR_CYAN);

                ColorError = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_RED);
            } else {
                ColorNormal = Curses.A_NORMAL;
                ColorFocus = Curses.A_REVERSE;
                ColorHotNormal = Curses.A_BOLD;
                ColorHotFocus = Curses.A_REVERSE | Curses.A_BOLD;

                ColorMenu = Curses.A_REVERSE;
                ColorMenuHot = Curses.A_NORMAL;
                ColorMenuSelected = Curses.A_BOLD;
                ColorMenuHotSelected = Curses.A_NORMAL;

                ColorMarked = Curses.A_BOLD;
                ColorMarkedSelected = Curses.A_REVERSE | Curses.A_BOLD;

                ColorDialogNormal = Curses.A_REVERSE;
                ColorDialogFocus = Curses.A_NORMAL;
                ColorDialogHotNormal = Curses.A_BOLD;
                ColorDialogHotFocus = Curses.A_NORMAL;

                ColorError = Curses.A_BOLD;
            }
            ColorBasic = MakeColor (-1, -1);
        }