Exemplo n.º 1
0
        public void BindAnalyzer(IOProvider io)
        {
            this.io      = io;
            io.ByteRead += b => UART.WriteChar((byte)b);

            Action <byte> writeAction = (b =>
            {
                lock (lockObject)
                {
                    io.Write(b);
                }
            });

            var mre = new ManualResetEventSlim();

            Task.Run(() =>
            {
                lock (lockObject)
                {
                    mre.Set();
                    RepeatHistory();
                    UART.CharReceived += writeAction;
                    actionsDictionary.Add(io, writeAction);
                }
            });
            mre.Wait();
        }
Exemplo n.º 2
0
        public void BindAnalyzer(IOProvider io)
        {
            this.io      = io;
            io.ByteRead += b =>
            {
                if (!TimeDomainsManager.Instance.TryGetVirtualTimeStamp(out var vts))
                {
                    // it happens when writing from uart analyzer
                    vts = new TimeStamp(default(TimeInterval), EmulationManager.ExternalWorld);
                }

                UART.GetMachine().HandleTimeDomainEvent(UART.WriteChar, (byte)b, vts);
            };

            Action <byte> writeAction = (b =>
            {
                lock (lockObject)
                {
                    io.Write(b);
                }
            });

            var mre = new ManualResetEventSlim();

            Task.Run(() =>
            {
                lock (lockObject)
                {
                    mre.Set();
                    RepeatHistory();
                    UART.CharReceived += writeAction;
                    actionsDictionary.Add(io, writeAction);
                }
            });
            mre.Wait();
        }
Exemplo n.º 3
0
        public TerminalWidget(Func <bool> focusProvider)
        {
            var shortcutDictionary = new Dictionary <KeyEventArgs, Action>
            {
                { CreateKey(Key.C, ModifierKeys.Shift | ModifierKeys.Control), CopyMarkedField },
                { CreateKey(Key.V, ModifierKeys.Shift | ModifierKeys.Control), PasteMarkedField },
                { CreateKey(Key.Insert, ModifierKeys.Shift), PasteMarkedField },
                { CreateKey(Key.PageUp, ModifierKeys.Shift), () => terminal.PageUp() },
                { CreateKey(Key.PageDown, ModifierKeys.Shift), () => terminal.PageDown() },
                { CreateKey(Key.Plus, ModifierKeys.Shift | ModifierKeys.Control), FontSizeUp },
                { CreateKey(Key.Minus, ModifierKeys.Control), FontSizeDown },
                { CreateKey(Key.NumPadAdd, ModifierKeys.Control), FontSizeUp },
                { CreateKey(Key.NumPadSubtract, ModifierKeys.Control), FontSizeDown },
                { CreateKey(Key.K0, ModifierKeys.Control), SetDefaultFontSize },
                { CreateKey(Key.NumPad0, ModifierKeys.Control), SetDefaultFontSize }
            };

            modifyLineEndings         = ConfigurationManager.Instance.Get("termsharp", "append-CR-to-LF", false);
            terminal                  = new Terminal(focusProvider);
            terminalInputOutputSource = new TerminalIOSource(terminal);
            IO              = new IOProvider(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();

            // We set the default font as a fall-back option.
            terminal.CurrentFont = Xwt.Drawing.Font.SystemMonospaceFont;
#if EMUL8_PLATFORM_LINUX
            // Here we try to load the robot font; unfortunately it doesn't work on OSX and Windows. Moreover, on some versions of
            // OSX it passes with no error (and no effect), on the others - it hangs. That's why we try to set the font and then
            // we check if we succeeded.
            var fontFile = typeof(TerminalWidget).Assembly.FromResourceToTemporaryFile("RobotoMono-Regular.ttf");
            Xwt.Drawing.Font.RegisterFontFromFile(fontFile);
#endif
            var fontFace = ConfigurationManager.Instance.Get("termsharp", "font-face", "Roboto Mono");
            defaultFontSize = ConfigurationManager.Instance.Get("termsharp", "font-size", (int)PredefinedFontSize, x => x >= MinFontSize);
            var font = Xwt.Drawing.Font.FromName(fontFace);
            if (!font.Family.Contains(fontFace))
            {
                Logger.Log(LogLevel.Warning, "The font '{0}' defined in the config file cannot be loaded.", fontFace);
                font = terminal.CurrentFont;
            }
            terminal.CurrentFont = font.WithSize(defaultFontSize);

            if (!FirstWindowAlreadyShown)
            {
                terminal.AppendRow(new LogoRow());
                FirstWindowAlreadyShown = true;
                firstWindow             = true;
            }
            else
            {
                terminal.AppendRow(new MonospaceTextRow(""));
            }

            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);
                }

                foreach (var entry in shortcutDictionary)
                {
                    if (modifiers == entry.Key.Modifiers)
                    {
                        if (a.Key == entry.Key.Key)
                        {
                            entry.Value();
                            return;
                        }
                    }
                }
                encoder.Feed(a.Key, modifiers);
            };
            Content = terminal;
        }