Esempio n. 1
0
        private void HistoryDown()
        {
            if (!IsOpen())
            {
                return;
            }

            inputField.text = ConsoleBackend.HistoryDown();
            SetInputFieldCaretPos(inputField.text.Length);
        }
Esempio n. 2
0
        private void AutoCompleteConsole()
        {
            if (!IsOpen())
            {
                return;
            }

            inputField.text = ConsoleBackend.AutoComplete(inputField.text);
            SetInputFieldCaretPos(inputField.text.Length);
        }
        private Task HandleInputs()
        {
            while (isRunning)
            {
                string input = System.Console.ReadLine();
                unityThread.Post(state => ConsoleBackend.ExecuteCommand(input), null);
            }

            return(Task.CompletedTask);
        }
Esempio n. 4
0
        private static void HandleInput(string value)
        {
            Logger.Info($"cmd>: {value}");

            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            ConsoleBackend.ExecuteCommand(value);
        }
Esempio n. 5
0
        public static void HelpCommand(string[] args)
        {
            Stopwatch     stopwatch = Stopwatch.StartNew();
            List <string> helpList  = new List <string>();

            foreach (KeyValuePair <string, ConsoleCommand> command in ConsoleBackend.GetAllCommands())
            {
                helpList.Add($"\n`{command.Key}` - {command.Value.CommandSummary}");
            }

            helpList.Sort(string.Compare);

            Logger.Info(string.Join("", helpList));

            stopwatch.Stop();
            Logger.Debug("Took {Time}ms to build help menu.", stopwatch.Elapsed.TotalMilliseconds);
        }
Esempio n. 6
0
        public void UpdateConsole()
        {
            //Return if there is no key available
            if (!System.Console.KeyAvailable)
            {
                return;
            }

            //Read the key
            ConsoleKeyInfo keyInfo = System.Console.ReadKey();

            switch (keyInfo.Key)
            {
            //Enter in input
            case ConsoleKey.Enter:
                string value = System.Console.ReadLine();
                Logger.Info($"cmd>: {value}");
                ConsoleBackend.ExecuteCommand(value);

                break;
            }
        }
        private void Start()
        {
            if (ConsoleUI != null)
            {
                Destroy(gameObject);
                Logger.Warn("You should only ever load this script on a bootloader scene!");
                return;
            }

            //If we are headless we need to create a console UI using the OS's terminal
            //I really which Unity would have this included...
            if (Game.IsHeadless)
            {
#if UNITY_STANDALONE_WIN
                ConsoleUI = new ConsoleWindows($"{Application.productName} Server");
#elif UNITY_STANDALONE_LINUX
                ConsoleUI = new ConsoleLinux($"{Application.productName} Server");
#elif UNITY_STANDALONE_OSX
                //TODO: Add console for OSX
#endif
            }
            else
            {
                GameObject consoleUiPrefab =
                    Addressables.LoadAssetAsync <GameObject>(ConsoleUiPrefabPath).WaitForCompletion();

                //Create in-game console GUI
                ConsoleUI = Instantiate(consoleUiPrefab, transform).GetComponent <ConsoleGUI>();
            }

            //Init the console
            ConsoleUI.Init();

            //Init the backend of the console
            ConsoleBackend.InitConsoleBackend();

            //Exec autoexec
            ConsoleBackend.ExecuteFileCommand(new[] { "autoexec" });
        }
Esempio n. 8
0
        public void UpdateConsole()
        {
            //Return if there is no key available
            if (!System.Console.KeyAvailable)
            {
                return;
            }

            //Read the key
            ConsoleKeyInfo keyInfo = System.Console.ReadKey();

            switch (keyInfo.Key)
            {
            //Enter in input
            case ConsoleKey.Enter:
                ConsoleBackend.ExecuteCommand(currentLine);
                currentLine = "";

                break;

            //Remove last input
            case ConsoleKey.Backspace:
                if (currentLine.Length > 0)
                {
                    currentLine = currentLine.Substring(0, currentLine.Length - 1);
                    System.Console.SetCursorPosition(0, System.Console.BufferHeight - 1);
                    ClearLine();
                    System.Console.Write(currentLine);
                }

                break;

            //Enter in key char
            default:
                currentLine += keyInfo.KeyChar;
                break;
            }
        }
Esempio n. 9
0
        public void UpdateConsole()
        {
            //Return if there is no key available
            if (!System.Console.KeyAvailable)
            {
                return;
            }

            //Read the key
            ConsoleKeyInfo keyInfo = System.Console.ReadKey();

            switch (keyInfo.Key)
            {
            //Enter in input
            case ConsoleKey.Enter:
                DrawInputLine("\n");
                ConsoleBackend.ExecuteCommand(currentLine);
                currentLine = "";

                break;

            //Remove last input
            case ConsoleKey.Backspace:
                if (currentLine.Length > 0)
                {
                    currentLine = currentLine.Substring(0, currentLine.Length - 1);
                }
                RemoveLastInput();

                break;

            //Attempt to auto complete
            case ConsoleKey.Tab:
                ClearLine();
                currentLine = ConsoleBackend.AutoComplete(currentLine);
                System.Console.Write(currentLine);

                break;

            //Go up in history of commands
            case ConsoleKey.PageUp:
            case ConsoleKey.UpArrow:
                ClearLine();
                currentLine = ConsoleBackend.HistoryUp(currentLine);
                System.Console.Write(currentLine);

                break;

            //Go back in history of commands
            case ConsoleKey.PageDown:
            case ConsoleKey.DownArrow:
                ClearLine();
                currentLine = ConsoleBackend.HistoryDown();
                System.Console.Write(currentLine);

                break;

            //Enter in key char
            default:
                currentLine += keyInfo.KeyChar;
                DrawInputLine(keyInfo.KeyChar.ToString());
                break;
            }
        }