void Start()
 {
     canvas = transform.GetComponent<Canvas> ();
     terminal = transform.FindChild ("Terminal").GetComponent<ConsoleTerminal> ();
     prompt = transform.FindChild ("Prompt").GetComponent<ConsolePrompt> ();
     prompt.console = this;
 }
Ejemplo n.º 2
0
        public MainWindow()
        {
            //The following two lines of code is to reset the PromptForFeedbackSettings to true
            //Please uncomment it, build it, before actual release
            // Properties.Settings.Default["PromptForFeedback"] = true;
            //  Properties.Settings.Default.Save();

            InitializeComponent();
            Global.MainWindow = this;
            Global.MainFrame  = MainFrame;
            Global.Snackbar   = Snackbar;
            var firstPage = new Page_Introduction();

            MainFrame.Navigate(firstPage);
            ConsoleTerminal.Initialize(new ConsoleTerminalModel(new List <IConsoleCommand>
            {
                new LoadTestDataCommand(this),
                new HideConsoleCommand(DrawerHost),
                new LoadDataFromTestServerCommand(this),
                new ResetDataCommand(Global.InputSlotList),
                new SaveLoadedHtmlCommand(Global.Toggles.SaveLoadedHtmlToggle),
                new ThrowExceptionCommand(null),
                new StatsCommand(Global.InputSlotList)
            }));
            CheckIfThisVersionIsUpToDate();
        }
Ejemplo n.º 3
0
 private void OpenConsoleButton_OnClick(object sender, RoutedEventArgs e)
 {
     DrawerHost.IsBottomDrawerOpen = true;
     ConsoleTerminal.Focus();
 }
Ejemplo n.º 4
0
 public TerminalCommand(Monitor monitor, ConsoleTerminal console) : base(monitor, "terminal", "manipulates the active terminal.", "term")
 {
     this.console = console;
 }
Ejemplo n.º 5
0
		public static void Run(string[] args)
		{
			ITerminal terminal = new ConsoleTerminal();
			//LineBuffer.Abstract editor = new LineBuffer.Simple(terminal);
			//LineBuffer.Abstract editor = new LineBuffer.Interactive(terminal);
			LineBuffer.Abstract editor = new LineBuffer.InteractiveWithHistory(terminal);
			editor.Prompt = ":>";
			Tuple<string, string>[] completionDescription = new Tuple<string, string>[]
			{
				Tuple.Create<string, string>("fish", "Fish are a paraphyletic group of organisms."),
				Tuple.Create<string, string>("firefox", "Mozilla Firefox is a free and open source web browser."),
				Tuple.Create<string, string>("foot", "The foot is an anatomical structure found in many vertebrates."),
			};
		   
			editor.Complete = text =>
			{
				string result = text;
				string[] parts = text.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
				int hits = 0;
				
				if (parts.Length > 0)
				{
					string last = parts[parts.Length - 1];
					string found = null;
					foreach (Tuple<string, string> word in completionDescription)
						if (word.Item1.StartsWith(last))
						{
							found = word.Item1;
							hits++;
						}
					if (hits == 1)
						result = text.Remove(text.Length - last.Length) + found;
				}
				return result;
			};
			Kean.Collection.IDictionary<string, Action> commands = new Kean.Collection.Dictionary<string, Action>();
			commands["play"] = () => Console.WriteLine("play it again");
			commands["beep"] = () => Console.Beep();
			commands["now"] = () => Console.WriteLine("now again");
			
			editor.Execute = text =>
			{
				string[] parts = text.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
				bool correct = true;
				foreach (string part in parts)
					correct &= commands.Contains(part);
				if (correct)
					foreach (string part in parts)
						commands[part]();
				return correct;
			};
			editor.Help = text =>
			{
				System.Text.StringBuilder result = new System.Text.StringBuilder();
				string[] parts = text.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
				if (parts.Length > 0)
				{
					string last = parts[parts.Length - 1];
					foreach (Tuple<string, string> word in completionDescription)
						if (word.Item1.StartsWith(last))
							result.AppendLine(word.Item1 + " " + word.Item2);
				}
				return result.ToString();   
			};
			/*
			System.Timers.Timer timer = new System.Timers.Timer(4000);
			timer.Elapsed += (object sender, System.Timers.ElapsedEventArgs elapsedArguments) =>
			{
				editor.WriteLine("Hello");
			};
			timer.Start();
			*/
			editor.Read();
		}
Ejemplo n.º 6
0
        private static void TerminalTest()
        {
            ConsoleWriter.Default.PrintCaption("Terminal Sample");

            var terminal = new ConsoleTerminal("My Terminal", new Dictionary <string, Action <string[]> >
            {
                {
                    "",
                    delegate
                    {
                        ConsoleWriter.Default.WritePaddedText(
                            $"Write `loading` for multi thread loading test;\r\n`log` for multi thread logging;\r\n`table` for multi thread table redraw;\r\nand `terminal` to open a child terminal.\r\nEnter `exit` or `quit` to exit test.",
                            10, ConsoleColor.Green);
                    }
                },
                {
                    "terminal",
                    strings =>
                    {
                        new ConsoleTerminal("Inner Terminal", (commandName, commandArguments) =>
                        {
                            Console.WriteLine("You wrote `{0}` with arguments `{1}`; write `quit` or `exit` to exit.",
                                              commandName, string.Join(" ", commandArguments));
                        }).RunTerminal();
                    }
                },
                {
                    "loading",
                    delegate
                    {
                        Timer timer  = null;
                        var progress = 0;
                        timer        = new Timer(state =>
                        {
                            Console.CursorLeft = 0;
                            ConsoleWriter.Default.WriteColoredText(progress + "% complete", ConsoleColor.Red);
                            progress += 10;

                            if (progress <= 100)
                            {
                                // ReSharper disable once AccessToModifiedClosure
                                timer?.Change(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                            }
                            else
                            {
                                Console.CursorLeft = 0;
                                Console.CursorTop += 1;

                                ConsoleWriter.Default.WriteColoredTextLine("Done.", ConsoleColor.DarkRed);
                            }
                        }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                    }
                },
                {
                    "log",
                    delegate
                    {
                        Timer timer = null;
                        var eventId = 0;
                        timer       = new Timer(state =>
                        {
                            ConsoleWriter.Default.WriteColoredTextLine(
                                $"Event {eventId}: logged some message. Adding more char to make it long. Adding more char to make it long. Adding more char to make it long.",
                                ConsoleColor.Yellow);

                            eventId++;

                            if (eventId <= 10)
                            {
                                // ReSharper disable once AccessToModifiedClosure
                                timer?.Change(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                            }
                            else
                            {
                                ConsoleWriter.Default.WriteColoredTextLine("No more event.", ConsoleColor.DarkYellow);
                            }
                        }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                    }
                },
                {
                    "table",
                    delegate
                    {
                        Timer timer = null;
                        var draws   = 0;
                        timer       = new Timer(state =>
                        {
                            Console.Clear();
                            Console.CursorTop  = 0;
                            Console.CursorLeft = 0;
                            new ConsoleTable(new[] { "Header 1", "Header 2", "Header 3" }).Write(new[]
                            {
                                new[] { "Row 1.1", "Row 1.2", "Row 1.3" },
                                new[] { "Row 2.1", "Row 2.2", "Row 2.3" },
                                new[] { "Row 3.1", "Row 3.2", "Row 3.3" }
                            });

                            draws++;

                            if (draws <= 10)
                            {
                                // ReSharper disable once AccessToModifiedClosure
                                timer?.Change(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                            }
                            else
                            {
                                ConsoleWriter.Default.WriteColoredTextLine("End of table redraws.",
                                                                           ConsoleColor.DarkCyan);
                            }
                        }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));
                    }
                }
            });

            terminal.RunTerminal();
            ConsoleWriter.Default.PrintSuccess("End of test execution");
            ConsoleWriter.Default.PrintSeparator();
        }
Ejemplo n.º 7
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();
            }
        }