예제 #1
0
        public void Stop()
        {
            this.loop = new Loop();

            Prepare prepare = this.loop.CreatePrepare();

            prepare.Start(this.PrepareCallback);

            Timer timer = this.loop.CreateTimer();

            timer.Start(this.TimerCallback, 100, 100);

            this.loop.RunDefault();
            Assert.Equal(1, this.timerCalled);

            this.loop.RunNoWait();
            Assert.True(this.prepareCalled > 1);

            this.loop.RunDefault();
            Assert.Equal(10, this.timerCalled);
            Assert.Equal(10, this.prepareCalled);
        }
예제 #2
0
        static void BaseRun(Container container, Action run)
        {
            Debug.Log("Application Start");

            Debug.Log("Application ThreadId: " + System.Threading.Thread.CurrentThread.ManagedThreadId);
            try {
                container = new ApplicationContainer(container);

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

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

                // draw everything and refresh curses
                Debug.Log("Terminal width: {0} Terminal height: {1}", Curses.Terminal.Width, Curses.Terminal.Height);
                container.SetDim(0, 0, Curses.Terminal.Width, Curses.Terminal.Height);

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

                keyaction = (key) => {
                    if (key == QuitKey)
                    {
                        Exit();
                    }
                    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();
                        container.Invalid = true;
                        Curses.Refresh();
                    }
                    else
                    {
                        container.ProcessKey(key);
                    }
                };

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

                stdin        = new Poll(Loop, 0);
                stdin.Event += (_) => {
                    keyaction(Curses.getch());
                };
                stdin.Start(PollEvent.Read);

                prepare = new Prepare();
                prepare.Start(() => {
                    if (container.Invalid)
                    {
                        keyaction(-2);
                    }
                });

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

                run?.Invoke();

                OnEnd();
            } finally {
                Window.End();
                Running = false;

                Loop = null;
                Debug.Log("Application End");
            }
        }