示例#1
0
        public TerminalWidget()
        {
            terminal = new Terminal();
            terminalInputOutputSource = new TerminalIOSource(terminal);
            IO              = new DetachableIO(terminalInputOutputSource);
            IO.BeforeWrite += b =>
            {
                // we do not check if previous byte was '\r', because it should not cause any problem to
                // send it twice
                if (ModifyLineEndings && b == '\n')
                {
                    IO.Write((byte)'\r');
                }
            };

            terminal.InnerMargin    = new WidgetSpacing(5, 5, 5, 5);
            terminal.Cursor.Enabled = true;
            terminal.ContextMenu    = CreatePopupMenu();

            var fontFile = typeof(TerminalWidget).Assembly.FromResourceToTemporaryFile("RobotoMono-Regular.ttf");

            Xwt.Drawing.Font.RegisterFontFromFile(fontFile);
            terminal.CurrentFont = Xwt.Drawing.Font.FromName("Roboto Mono").WithSize(10);

            var encoder = new TermSharp.Vt100.Encoder(x =>
            {
                terminal.ClearSelection();
                terminal.MoveScrollbarToEnd();
                terminalInputOutputSource.HandleInput(x);
            });

            terminal.KeyPressed += (s, a) =>
            {
                a.Handled = true;

                var modifiers = a.Modifiers;
                if (!Misc.IsOnOsX)
                {
                    modifiers &= ~(ModifierKeys.Command);
                }

                if (modifiers == ModifierKeys.Shift)
                {
                    if (a.Key == Key.PageUp)
                    {
                        terminal.PageUp();
                        return;
                    }
                    if (a.Key == Key.PageDown)
                    {
                        terminal.PageDown();
                        return;
                    }
                }
                encoder.Feed(a.Key, modifiers);
            };
            Content = terminal;
        }
示例#2
0
        public StdInOutHandler(DetachableIO io, Monitor monitor, bool plainOutput = false)
        {
            this.io = io;
            commandHandler = monitor;

            buffer = new StringBuilder();
            CommandInteraction = new StdInOutInteraction(plainOutput);
            monitor.Interaction = CommandInteraction;
        }
示例#3
0
        public StdInOutHandler(DetachableIO io, Monitor monitor, bool plainOutput = false)
        {
            this.io        = io;
            commandHandler = monitor;

            buffer              = new StringBuilder();
            CommandInteraction  = new StdInOutInteraction(plainOutput);
            monitor.Interaction = CommandInteraction;
        }
示例#4
0
        public TerminalWidget()
        {
            terminal = new Terminal();
            terminalInputOutputSource = new TerminalIOSource(terminal);
            IO = new DetachableIO(terminalInputOutputSource);
            IO.BeforeWrite += b =>
            {
                // we do not check if previous byte was '\r', because it should not cause any problem to 
                // send it twice
                if(ModifyLineEndings && b == '\n')
                {
                    IO.Write((byte)'\r');
                }
            };

            terminal.InnerMargin = new WidgetSpacing(5, 5, 5, 5);
            terminal.Cursor.Enabled = true;
            terminal.ContextMenu = CreatePopupMenu();

            var fontFile = typeof(TerminalWidget).Assembly.FromResourceToTemporaryFile("RobotoMono-Regular.ttf");
            Xwt.Drawing.Font.RegisterFontFromFile(fontFile);
            terminal.CurrentFont = Xwt.Drawing.Font.FromName("Roboto Mono").WithSize(10);

            var encoder = new TermSharp.Vt100.Encoder(x =>
            {
                terminal.ClearSelection();
                terminal.MoveScrollbarToEnd();
                terminalInputOutputSource.HandleInput(x);
            });

            terminal.KeyPressed += (s, a) =>
            {
                a.Handled = true;

                var modifiers = a.Modifiers;
                if(!Misc.IsOnOsX)
                {
                    modifiers &= ~(ModifierKeys.Command);
                }

                if(modifiers == ModifierKeys.Shift)
                {
                    if(a.Key == Key.PageUp)
                    {
                        terminal.PageUp();
                        return;
                    }
                    if(a.Key == Key.PageDown)
                    {
                        terminal.PageDown();
                        return;
                    }
                }
                encoder.Feed(a.Key, modifiers);
            };
            Content = terminal;
        }
示例#5
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (IO != null)
            {
                IO.Dispose();
                IO = null;
            }
        }
示例#6
0
 // this constructor is needed by the monitor; do not remove it
 public UARTWindowBackendAnalyzer()
 {
     preferredTerminal = ConfigurationManager.Instance.Get("general", "terminal", TerminalTypes.XTerm);
     if (preferredTerminal == TerminalTypes.Termsharp)
     {
         terminalWidget = new TerminalWidget();
         IO             = terminalWidget.IO;
     }
     else
     {
         var stream = new PtyUnixStream();
         IO = new DetachableIO(new StreamIOSource(stream, stream.Name));
     }
 }
示例#7
0
        public void BindAnalyzer(DetachableIO io)
        {
            this.io      = io;
            io.ByteRead += UART.WriteChar;

            Task.Run(() =>
            {
                RepeatHistory();

                UART.CharReceived += b =>
                {
                    lock (history)
                    {
                        io.Write(b);
                    }
                };
            });
        }
示例#8
0
        public static Shell GenerateShell(DetachableIO io, Monitor monitor, bool forceVCursor = false, bool clearScreen = true)
        {
            var settings = new ShellSettings {
                NormalPrompt       = new Prompt("(monitor) ", ConsoleColor.DarkRed),
                Banner             = VersionCommand.VersionString,
                UseBuiltinQuit     = false,
                UseBuiltinHelp     = false,
                UseBuiltinSave     = false,
                ForceVirtualCursor = forceVCursor,
                ClearScreen        = clearScreen,
                HistorySavePath    = ConfigurationManager.Instance.Get("general", "history-path", Path.Combine(Misc.GetUserDirectory(), "history"))
            };

            var shell = new Shell(io, monitor, settings);

            var startupCommand = Environment.GetEnvironmentVariable(Monitor.StartupCommandEnv);

            if (!string.IsNullOrEmpty(startupCommand) && shell != null)
            {
                shell.StartupCommand = startupCommand;
            }

            return(shell);
        }
        public static void Run(string[] args)
        {
            var options = new Options();
            var optionsParser = new OptionsParser();
            if(!optionsParser.Parse(options, args))
            {
                return;
            }

            using(var context = ObjectCreator.OpenContext())
            {
                var monitor = new Emul8.UserInterface.Monitor();
                context.RegisterSurrogate(typeof(Emul8.UserInterface.Monitor), monitor);

                // we must initialize plugins AFTER registering monitor surrogate
                // as some plugins might need it for construction
                TypeManager.Instance.PluginManager.Init("CLI");

                Logger.AddBackend(ConsoleBackend.Instance, "console");

                EmulationManager.Instance.ProgressMonitor.Handler = new CLIProgressMonitor();

                var crashHandler = new CrashHandler();
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => crashHandler.HandleCrash(e);

                var resetEvent = new ManualResetEventSlim();
                if(options.StdInOut)
                {
                    Logger.AddBackend(new FileBackend("logger.log"), "file");
                    var world = new StreamIOSource(Console.OpenStandardInput(), Console.OpenStandardOutput());
                    var io = new DetachableIO(world);
                    monitor.Quitted += resetEvent.Set;
                    var handler = new StdInOutHandler(io, monitor, options.Plain);
                    handler.Start();
                }
                else
                {
                    Shell shell = null;
                    Type preferredUARTAnalyzer = null;
                    if(options.Port > 0)
                    {
                        var io = new DetachableIO(new SocketIOSource(options.Port));
                        shell = ShellProvider.GenerateShell(io, monitor, true, false);
                        shell.Quitted += resetEvent.Set;
                    }
                    else if(options.ConsoleMode)
                    {
                        preferredUARTAnalyzer = typeof(UARTMultiplexedBackendAnalyzer);

                        var stream = new PtyUnixStream("/proc/self/fd/1");
                        var world = new StreamIOSource(stream, stream.Name);

                        Logger.AddBackend(new FileBackend("logger.log"), "file");
                        var consoleTerm = new ConsoleTerminal(world);
                        UARTMultiplexedBackendAnalyzer.Multiplexer = consoleTerm;
                   
                        monitor.Console = consoleTerm;

                        shell = ShellProvider.GenerateShell(monitor);
                        consoleTerm.AttachTerminal("shell", shell.Terminal);

                        shell.Quitted += resetEvent.Set;
                    }
                    else
                    {
                        preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);

                        var stream = new PtyUnixStream();
                        var dio = new DetachableIO(new StreamIOSource(stream, stream.Name));
                        var terminal = new UARTWindowBackendAnalyzer(dio);
                        shell = ShellProvider.GenerateShell(dio, monitor);     

                        shell.Quitted += resetEvent.Set;
                        monitor.Quitted += shell.Stop;

                        try
                        {
                            terminal.Show();
                        }
                        catch(InvalidOperationException ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine(ex.Message);
                            resetEvent.Set();
                        }
                    }

                    if(preferredUARTAnalyzer != null)
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        };
                    }
                    monitor.Interaction = shell.Writer;
                    monitor.UseConsole = options.ConsoleMode;
                    monitor.MachineChanged += emu => shell.SetPrompt(emu != null ? new Prompt(string.Format("({0}) ", emu), ConsoleColor.DarkYellow) : null);

                    if(options.Execute != null)
                    {
                        shell.Started += s => s.InjectInput(string.Format("{0}\n", options.Execute));
                    }
                    else if(!string.IsNullOrEmpty(options.ScriptPath))
                    {
                        shell.Started += s => s.InjectInput(string.Format("i $CWD/{0}\n", options.ScriptPath));
                    }

                    new Thread(x => shell.Start(true)) { IsBackground = true, Name = "Shell thread" }.Start();
                }

                resetEvent.Wait();
                EmulationManager.Instance.Clear();
                TypeManager.Instance.Dispose();
                Logger.Dispose();
            }
        }
示例#10
0
 public UARTWindowBackendAnalyzer(DetachableIO io)
 {
     IO = io;
 }
示例#11
0
 public UARTMultiplexedBackendAnalyzer()
 {
     IO = new DetachableIO();
 }
示例#12
0
        public static void Run(string[] args)
        {
            var options       = new Options();
            var optionsParser = new OptionsParser();

            if (!optionsParser.Parse(options, args))
            {
                return;
            }

            using (var context = ObjectCreator.OpenContext())
            {
                var monitor = new Emul8.UserInterface.Monitor();
                context.RegisterSurrogate(typeof(Emul8.UserInterface.Monitor), monitor);

                // we must initialize plugins AFTER registering monitor surrogate
                // as some plugins might need it for construction
                TypeManager.Instance.PluginManager.Init("CLI");

                Logger.AddBackend(ConsoleBackend.Instance, "console");

                EmulationManager.Instance.ProgressMonitor.Handler = new CLIProgressMonitor();

                var crashHandler = new CrashHandler();
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => crashHandler.HandleCrash(e);

                var resetEvent = new ManualResetEventSlim();
                if (options.StdInOut)
                {
                    Logger.AddBackend(new FileBackend("logger.log"), "file");
                    var world = new StreamIOSource(Console.OpenStandardInput(), Console.OpenStandardOutput());
                    var io    = new DetachableIO(world);
                    monitor.Quitted += resetEvent.Set;
                    var handler = new StdInOutHandler(io, monitor, options.Plain);
                    handler.Start();
                }
                else
                {
                    Shell shell = null;
                    Type  preferredUARTAnalyzer = null;
                    if (options.Port > 0)
                    {
                        var io = new DetachableIO(new SocketIOSource(options.Port));
                        shell          = ShellProvider.GenerateShell(io, monitor, true, false);
                        shell.Quitted += resetEvent.Set;
                    }
                    else if (options.ConsoleMode)
                    {
                        preferredUARTAnalyzer = typeof(UARTMultiplexedBackendAnalyzer);

                        var stream = new PtyUnixStream("/dev/fd/1");
                        var world  = new StreamIOSource(stream, stream.Name);

                        Logger.AddBackend(new FileBackend("logger.log"), "file");
                        var consoleTerm = new ConsoleTerminal(world);
                        UARTMultiplexedBackendAnalyzer.Multiplexer = consoleTerm;

                        monitor.Console = consoleTerm;

                        shell = ShellProvider.GenerateShell(monitor);
                        consoleTerm.AttachTerminal("shell", shell.Terminal);

                        shell.Quitted += resetEvent.Set;
                    }
                    else
                    {
                        preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);

                        var stream   = new PtyUnixStream();
                        var dio      = new DetachableIO(new StreamIOSource(stream, stream.Name));
                        var terminal = new UARTWindowBackendAnalyzer(dio);
                        shell = ShellProvider.GenerateShell(dio, monitor);

                        shell.Quitted   += resetEvent.Set;
                        monitor.Quitted += shell.Stop;

                        try
                        {
                            terminal.Show();
                        }
                        catch (InvalidOperationException ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine(ex.Message);
                            resetEvent.Set();
                        }
                    }

                    if (preferredUARTAnalyzer != null)
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        };
                    }
                    monitor.Interaction     = shell.Writer;
                    monitor.UseConsole      = options.ConsoleMode;
                    monitor.MachineChanged += emu => shell.SetPrompt(emu != null ? new Prompt(string.Format("({0}) ", emu), ConsoleColor.DarkYellow) : null);

                    if (options.Execute != null)
                    {
                        shell.Started += s => s.InjectInput(string.Format("{0}\n", options.Execute));
                    }
                    else if (!string.IsNullOrEmpty(options.ScriptPath))
                    {
                        shell.Started += s => s.InjectInput(string.Format("i {0}{1}\n", Path.IsPathRooted(options.ScriptPath) ? "@" : "$CWD/", options.ScriptPath));
                    }

                    new Thread(x => shell.Start(true))
                    {
                        IsBackground = true, Name = "Shell thread"
                    }.Start();
                }

                resetEvent.Wait();
                EmulationManager.Instance.Clear();
                TypeManager.Instance.Dispose();
                Logger.Dispose();
            }
        }
示例#13
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if(IO != null)
            {
                IO.Dispose();
                IO = null;
            }
        }
        public UARTWindowBackendAnalyzer()
        {
            var stream = new PtyUnixStream();

            IO = new DetachableIO(new StreamIOSource(stream, stream.Name));
        }
示例#15
0
 public void AttachTerminal(string name, DetachableIO io)
 {
     AttachTerminal(name, new BasicTerminalEmulator(io));
 }
示例#16
0
 public void AttachTerminal(string name, DetachableIO io)
 {
     AttachTerminal(name, new BasicTerminalEmulator(io));
 }