Ejemplo n.º 1
0
        public TextConsole()
        {
            D("Init");

            if (s_textConsole != null)
            {
                throw new Exception("Cannot create a new TextConsole");
            }

            m_outputStream = Console.OpenStandardOutput();

            //m_inputEncoding = Encoding.GetEncoding("ISO-8859-1");
            m_inputEncoding = Encoding.GetEncoding("UTF-8");

            s_textConsole = this;

            m_paragraphContainer = new ParagraphContainer();
            m_paragraphContainer.paragraphAddedEvent += ParagraphAdded;

            if (m_initialized)
            {
                throw new Exception("Terminal already initailized");
            }

            GNUReadLine.rl_initialize();
            GNUReadLine.rl_clear_signals();
            GNUReadLine.mono_rl_set_catch_signals(false);
            GNUReadLine.rl_set_signals();
            GNUReadLine.using_history();
            GNUReadLine.stifle_history(100);

            GNUReadLine.rl_bind_key(12, ClearScreenHandler);
            GNUReadLine.rl_bind_keyseq("\x1b[6~", PageDownHandler);
            GNUReadLine.rl_bind_keyseq("\x1b[5~", PageUpHandler);
            GNUReadLine.rl_bind_keyseq("\x1b[6;5~", PageDownCtrlHandler);
            GNUReadLine.rl_bind_keyseq("\x1b[5;5~", PageUpCtrlHandler);

            TermInfo.Init(m_visualMode);

            Redraw();

            GNUReadLine.rl_callback_handler_install(new byte[] { 0 }, InputHandler);

            Load();

            m_initialized = true;

/*
 *                      for(int i = 0; i < 200; i++)
 *                              m_paragraphContainer.Add(String.Format("kala {0} 1234567890 abcdefg hijklmn opqrstu vxyz 1234567890 abcdefg hijklmn opqrstu vxyz foobar {1}",
 *                                                                     i, i));
 */
        }
Ejemplo n.º 2
0
        public ClientCore()
        {
            s_clientCore = this;

            //Ansi.SendAnsiInit();

            m_synchronizedInvoke = new SynchronizedInvoke();

            // Services
            m_baseServicesDispatcher = new BaseServicesDispatcher();

            // Init console
            m_textConsole = new TextConsole();
            ChiConsole.SetChiConsole(m_textConsole);

            // Initialize ironpython
            IronPython.Compiler.Options.GenerateModulesAsSnippets = true;
            m_pythonEngine = new PythonEngine();

            ChiPythonStream s = new ChiPythonStream();

            m_pythonEngine.SetStandardOutput(s);
            m_pythonEngine.SetStandardError(s);
            m_pythonEngine.SetStandardInput(s);
            //m_pythonEngine.AddToPath(Environment.CurrentDirectory);
            //m_pythonEngine.AddToPath(Application.StartupPath + "/lib");
#if DEBUG
            m_pythonEngine.AddToPath(@"../../../scripts/lib");
#endif
            m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly);             // load BatClientBase
            m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly);      // load System.Drawing
            m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly);  // load System.Windows.Forms



            // Network
            m_telnet = new Telnet();
            m_telnet.connectEvent    += new Telnet.ConnectDelegate(_ConnectEvent);
            m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent);
            m_telnet.receiveEvent    += new Telnet.ReceiveDelegate(_ReceiveEvent);
            m_telnet.promptEvent     += new Telnet.PromptDelegate(_PromptEvent);
            m_telnet.telnetEvent     += new Telnet.TelnetDelegate(_TelnetEvent);

            m_netPipe = UnixPipes.CreatePipes();


            m_commandManager = new CommandManager(m_baseServicesDispatcher);
            AddBuiltinCommands();

            m_triggerManager = new TriggerManager(m_baseServicesDispatcher);

            m_keyManager = new KeyManager(m_baseServicesDispatcher);

            m_hiliteManager = new HiliteManager(m_triggerManager);

            PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this,
                                       m_textConsole, m_pythonEngine, m_keyManager, m_hiliteManager);

            // run init script

            Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Version baseVersion    = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version;
            ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2));
            ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString);

            try
            {
#if DEBUG
                PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc"));
#else
                PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc"));
#endif
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init_std.bc", e);
            }

/*
 *                      m_pythonEngine.Import("site");
 *
 *                      try
 *                      {
 *                              m_pythonEngine.ExecuteFile("init.py");
 *                      }
 *                      catch (Exception e)
 *                      {
 *                              ChiConsole.WriteError("Eval failed", e);
 *                      }
 */
        }