static void CommandScreenshot(CommandArg[] args)
        {
            var filePath  = Path.Combine(Application.persistentDataPath, "screenshots", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff"));
            var superSize = 1;

            if (args.Length > 0)
            {
                superSize = args[0].Int;
            }

            if (args.Length > 1)
            {
                var name = args[1].String;
                if (Path.IsPathRooted(name))
                {
                    filePath = name;
                }
                else
                {
                    filePath = Path.Combine(Application.persistentDataPath, "screenshots", name);
                }
            }

            filePath = filePath.Replace('\\', '/'); // this is mostly so that the Terminal.Log message looks consistent on Windows
            filePath = Path.ChangeExtension(filePath, ".png");
            string folderPath = new DirectoryInfo(filePath).Parent.FullName;

            Directory.CreateDirectory(folderPath);

            ScreenCapture.CaptureScreenshot(filePath, superSize);
            Terminal.Log($"saved screenshot as {filePath} (supersize {superSize})");
        }
        static void CommandTime(CommandArg[] args)
        {
            var sw = new Stopwatch();

            sw.Start();

            Terminal.Shell.RunCommand(JoinArguments(args));

            sw.Stop();
            Terminal.Log("Time: {0}ms", (double)sw.ElapsedTicks / 10000);
        }
Example #3
0
        static void CommandSet(CommandArg[] args)
        {
            if (args.Length == 0)
            {
                foreach (var v in Terminal.Shell.Variables)
                {
                    Terminal.Log("{0}: {1}", v.PadRight(16), Terminal.Shell.GetVariable(v));
                }
                return;
            }

            string variable_name = args[0].String;

            Terminal.Shell.SetVariable(variable_name, JoinArguments(args, 1));
        }
        static void CommandTrace(CommandArg[] args)
        {
            int log_count = Terminal.Buffer.Logs.Count;

            if (log_count - 2 < 0)
            {
                Terminal.Log("Nothing to trace.");
                return;
            }

            var log_item = Terminal.Buffer.Logs[log_count - 2];

            if (log_item.stack_trace == "")
            {
                Terminal.Log("{0} (no trace)", log_item.message);
            }
            else
            {
                Terminal.Log(log_item.stack_trace);
            }
        }
        /// <summary>
        /// Parses an input line into a command and runs that command.
        /// </summary>
        public void RunCommand(string line)
        {
            Terminal.Log(line, TerminalLogType.Input);

            string remaining = line;

            IssuedErrorMessage = null;
            arguments.Clear();

            while (remaining != "")
            {
                var argument = EatArgument(ref remaining);

                if (argument.String != "")
                {
                    string variable_name = argument.String.Substring(1).ToUpper();

                    arguments.Add(argument);
                }
            }

            if (arguments.Count == 0)
            {
                // Nothing to run
                return;
            }

            string command_name = arguments[0].String.ToUpper();

            arguments.RemoveAt(0); // Remove command name from arguments

            if (!commands.ContainsKey(command_name))
            {
                IssueErrorMessage("Command {0} could not be found", command_name);
                return;
            }

            RunCommand(command_name, arguments.ToArray());
        }
        static void CommandHelp(CommandArg[] args)
        {
            if (args.Length == 0)
            {
                foreach (var command in Terminal.Shell.Commands)
                {
                    if (!command.Value.secret)
                    {
                        Terminal.Log("{0}: {1}", command.Key.PadRight(16), command.Value.help);
                    }
                }
                return;
            }

            string command_name = args[0].String.ToUpper();

            if (!Terminal.Shell.Commands.ContainsKey(command_name))
            {
                Terminal.Shell.IssueErrorMessage("Command {0} could not be found.", command_name);
                return;
            }

            var info = Terminal.Shell.Commands[command_name];

            if (info.help == null)
            {
                Terminal.Log("{0} does not provide any help documentation.", command_name);
            }
            else if (info.usage == null)
            {
                Terminal.Log(info.help);
            }
            else
            {
                Terminal.Log("{0}\nUsage: {1}", info.help, info.usage);
            }
        }
 static void CommandPrint(CommandArg[] args)
 {
     Terminal.Log(JoinArguments(args));
 }