Example #1
0
        public void Run()
        {
            Thread m_signalThread = new Thread(SignalThread);

            m_signalThread.Start();

            Pollfd[] fds = new Pollfd[2];

            while (m_exit == false)
            {
                fds[0].fd      = Mono.Unix.UnixStream.StandardInputFileDescriptor;
                fds[0].events  = PollEvents.POLLIN;
                fds[0].revents = 0;

                fds[1].fd      = m_netPipe.Reading.Handle;
                fds[1].events  = PollEvents.POLLIN;
                fds[1].revents = 0;

                int ret = Syscall.poll(fds, -1);

                if (ret == 0)
                {
                    //ChiConsole.Prompt = String.Format("pr{0}> ", z++);
                    ChiConsole.WriteLine("timeout");
                }
                else if (ret > 0)
                {
                    if (fds[0].revents != 0)
                    {
                        m_textConsole.ReadChars();

                        string str;
                        while ((str = m_textConsole.GetLine()) != null)
                        {
                            //m_textConsole.WriteLine("Tuli {0}", str);
                            HandleInput(str);
                        }
                    }

                    if (fds[1].revents != 0)
                    {
                        m_netPipe.Reading.ReadByte();
                        m_synchronizedInvoke.DispatchInvokes();
                    }
                }
            }

            Dbg.WriteLine("Exiting");

            m_sigThreadStop = true;
            if (m_signalThread.Join(1000) == false)
            {
                m_signalThread.Abort();
            }

            m_textConsole.UnInit();
        }
Example #2
0
        void HandleSigTstp()
        {
            Dbg.WriteLine("SIGTSTP");

            m_textConsole.CleanupAfterSigStop();

            Stdlib.raise(Signum.SIGSTOP);

            m_textConsole.RestoreAfterSigStop();

            Dbg.WriteLine("cont");
        }
Example #3
0
        void RedrawOutputLines()
        {
            if (m_paragraphContainer.Count == 0)
            {
                return;
            }

            int p = m_paragraphContainer.Count - 1;
            int l = 0;

            /* find the bottom paragraph */
            while (p > 0 && l < m_currentLine)
            {
                l += m_paragraphContainer[p].m_lines;
                p--;
            }

            int bottomPara  = p;                        // bottom full para
            int bottomLines = l - m_currentLine;        // lines shown of the bottom partial para

            Dbg.WriteLine("Bottom paragraph {0}, lines {1}", bottomPara, bottomLines);

            l = bottomLines;

            /* find the top paragraph */
            while (p >= 0 && l < m_outputLines)
            {
                l += m_paragraphContainer[p].m_lines;
                p--;
            }

            p++;

            int topPara    = p;                 // top full or partial para
            int topLines   = 0;                 // lines hidden of the top partial para
            int emptyLines = 0;

            if (l - m_outputLines < 0)
            {
                emptyLines = Math.Abs(l - m_outputLines);
            }
            else
            {
                topLines = l - m_outputLines;
            }

            Dbg.WriteLine("Top paragraph {0}, lines {1}, emptyLines {2}", topPara, topLines, emptyLines);

            RedrawOutputLines2();
        }
Example #4
0
        void Load()
        {
            GNUReadLine.read_history(System.IO.Path.Combine(Program.ConfigPath, "history"));
            int l = GNUReadLine.mono_history_get_length();

            if (l > 0)
            {
                GNUReadLine.history_set_pos(l);

                IntPtr strptr = GNUReadLine.mono_history_get(l);
                string str    = IntPtrToString(strptr);
                m_lastLine = str;
                Dbg.WriteLine("lastline was '{0}'", str);
            }
        }
Example #5
0
        public void UnInit()
        {
            D("UnInit");

            if (!m_initialized)
            {
                Dbg.WriteLine("WARNING Terminal not initialized");
                return;
            }

            GNUReadLine.rl_callback_handler_remove();
            TermInfo.UnInit();
            m_initialized = false;

            Save();
        }
Example #6
0
        void SignalThread()
        {
            Dbg.WriteLine("Starting Signal Thread");

            UnixSignal sigint   = new UnixSignal(Signum.SIGINT);
            UnixSignal sigtstp  = new UnixSignal(Signum.SIGTSTP);
            UnixSignal sigwinch = new UnixSignal(Signum.SIGWINCH);

            UnixSignal[] signals = { sigint, sigtstp, sigwinch };

            while (true)
            {
                // We need timeout to be able to stop this thread
                int s = UnixSignal.WaitAny(signals, 100);

                if (m_sigThreadStop)
                {
                    Dbg.WriteLine("Stopping Signal Thread");
                    return;
                }

                SignalDelegate del;

                if (s == 0)
                {
                    del = HandleSigInt;
                }
                else if (s == 1)
                {
                    del = HandleSigTstp;
                }
                else if (s == 2)
                {
                    del = HandleSigWinch;
                }
                else
                {
                    continue;
                }

                m_synchronizedInvoke.BeginInvoke(del, null);

                signals[s].Reset();
            }
        }
Example #7
0
        static void InputHandler(IntPtr strptr)
        {
            string str = IntPtrToString(strptr);

            Dbg.WriteLine("Tuli: '{0}'", str == null ? "<null>" : str);

            if (str == null)
            {
                return;
            }

            if (str.Length > 0 && str != s_textConsole.m_lastLine)
            {
                GNUReadLine.add_history(strptr);
            }
            else
            {
                Dbg.WriteLine("skipping {0}", str);
            }

            s_textConsole.m_lastLine = str;

            s_textConsole.m_textQueue.Enqueue(str);
        }
Example #8
0
 void HandleSigInt()
 {
     m_exit = true;
     Dbg.WriteLine("SIGINT");
 }
Example #9
0
 void D(string format, params object[] args)
 {
     Dbg.WriteLine("TextConsole: " + format, args);
 }
Example #10
0
 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     Dbg.WriteLine(e.ExceptionObject.ToString());
     TextConsole.Singleton.UnInit();
     Console.WriteLine(e.ExceptionObject);
 }