/// <summary>
 ///     Clears current line.
 /// </summary>
 private void ClearLine(bool fullClear = false, int fromRelativeX = 0)
 {
     if (fullClear)
     {
         ConsoleUI.ClearLine();
     }
     else if (settings.SingleLineMode)
     {
         ConsoleUI.ClearLine(settings.Prompt.Length + fromRelativeX);
     }
     else
     {
         Console.CursorLeft = 0;
         DrawCurrentLineNumber();
         ConsoleUI.ClearLine(CliEditorSettings.LineNumberWidth + fromRelativeX);
     }
 }
Example #2
0
        private static void EnterInteractiveMode()
        {
            Logger.Info(
                "Axion code editor & interpreter mode.\n"
                + "Type 'exit' or 'quit' to exit mode, 'cls' to clear screen."
                );
            while (true)
            {
                // code editor header
                string rawInput = ConsoleUI.Read("i>> ");
                string input    = rawInput.Trim().ToUpper();

                switch (input)
                {
                case "":
                    // skip empty commands
                    ConsoleUI.ClearLine();
                    continue;

                case "EXIT":
                case "QUIT":
                    // exit from interpreter to main loop
                    Logger.Info("\nInteractive interpreter closed.");
                    return;
                }

                // TODO (UI) parse "help(module)" argument

                // initialize editor
                var editor = new ConsoleCodeEditor(
                    false,
                    true,
                    firstCodeLine: rawInput,
                    highlighter: new AxionSyntaxHighlighter()
                    );
                string[] codeLines = editor.RunSession();
                // interpret as source code and output result
                Process(new SourceUnit(codeLines), SourceProcessingMode.Interpret);
            }
        }
Example #3
0
        public static void Init(string[] arguments)
        {
            if (!Directory.Exists(OutputDirectory))
            {
                Directory.CreateDirectory(OutputDirectory);
            }

            PrintIntro();

            // main processing loop
            while (true)
            {
                if (arguments.Length > 0)
                {
                    cliParser
                    .ParseArguments <CommandLineArguments>(arguments)
                    .MapResult(
                        options => {
                        Verbose = options.Verbose;

                        if (options.Exit)
                        {
                            Environment.Exit(0);
                        }

                        if (options.ClearScreen)
                        {
                            Console.Clear();
                            PrintIntro();
                            return(0);
                        }

                        if (options.Version)
                        {
                            ConsoleUI.WriteLine(Version);
                            return(0);
                        }

                        if (options.Help)
                        {
                            ConsoleUI.WriteLine(CommandLineArguments.HelpText);
                            return(0);
                        }

                        if (options.Interactive)
                        {
                            EnterInteractiveMode();
                            return(0);
                        }

                        ProcessSources(options);
                        return(0);
                    },
                        errors => {
                        foreach (Error e in errors)
                        {
                            Logger.Error(e.ToString());
                        }

                        return(0);
                    }
                        );
                }

                // wait for next command
                // TODO (UI) add console commands history (up-down)
                string command = ConsoleUI.Read(">>> ");
                while (command.Length == 0)
                {
                    ConsoleUI.ClearLine();
                    command = ConsoleUI.Read(">>> ");
                }

                ConsoleUI.WriteLine();
                arguments = Utilities.SplitLaunchArguments(command).ToArray();
            }

            // It is infinite loop, breaks only by 'exit' command.
            // ReSharper disable once FunctionNeverReturns
        }