Example #1
0
            async Task <(bool, int)> doALine(string?line)
            {
                if (line != null)
                {
                    ParseResult result = replParser.Parse(line);
                    int exitCode;
                    ICommand currentCommand = result.CommandResult.Command;
                    if (currentCommand == replCommand)
                    {
                        exitCode = await replParser.InvokeAsync(result, terminal);
                    }
                    else
                    {
                        if (currentCommand is Command command && commands.Contains(command))     // extension command
                        {
                            IExtension ext           = commands.GetExtension(command);
                            string?targetCommandName = commands.GetProvider(command).GetType().FullName;

                            context.Logs.Debug($"Command {targetCommandName} from extension {ext.Publisher}.{ext.Name} invoking.");

                            {
                                PipelineContext subContext = new PipelineContext(context.Services.CreateExtensionScope(), context.Logs.CreateScope(targetCommandName ?? "sub", context.Logs.Level));
                                Parser subParser           = CommandLines.CreateDefaultParser(replCommand, subContext);
                                exitCode = await subParser.InvokeAsync(result, terminal);
                            }

                            context.Logs.Debug($"Command {targetCommandName} invoked with {exitCode}.");
                        }
                        else
                        {
                            exitCode = await replParser.InvokeAsync(result, terminal);
                        }
                    }
        private void AddCommandLineExecute()
        {
            PrimitiveViewModel <string> commandLine = string.Empty;

            commandLine.RemoveRequested += HandleCommandLineRemoveRequested;
            CommandLines.Add(commandLine);
        }
Example #3
0
        // Buttons for Debug
        void Button01(object sender, EventArgs args)
        {
            prolog.Reset();

            CommandLines.Last().Command = "[test.txt].";
            CommandLines.Last().CommandLabel.Text = CommandLines.Last().Command;
            CommandLines.Last().CommandEntry.Focus();

            //Label label = new Label();

            //string code = File.ReadAllText("/Users/atsu/Projects/Xamarin/App/Prolog/Prolog/SyntaxChecker.pl");
            //string code = File.ReadAllText(WorkingDir + "test.txt");

            //label.Text = code;
            //Console.Children.Add(label);

            //if (SetClause(prolog, code))
            //    StatusLabel.Text = "Set Clauses";


            //List<Solution> solutions = GetSolutions(prolog, query);
            //label.Text += SolutionsString(solutions);

            //var solution = prolog.GetAllSolutions("test.prolog", query);
            //foreach(var s in solution.NextSolution)
            //    label.Text += s.ToString();

            //Console.Children.Add(label);

            //prolog.Reset();
            //AddPrompt(GetPromptText(prolog.Prompt));
        }
Example #4
0
        public static async Task <PipelineResult <Wrapper <int> > > UseSampleCommandInvoker(IWorkspace workspace, Command command, string[] origin, string input = "", PipelineOperation <string[], Wrapper <int> >?before = null, PipelineOperation <string[], Wrapper <int> >?after = null)
        {
            using MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(input));
            using StreamReader sr = new StreamReader(ms);
            PipelineBuilder <string[], Wrapper <int> > builder = CreatePipelineBuilder(new TestTerminal(), sr, workspace);

            if (before != null)
            {
                _ = builder.Use("before", async context =>
                {
                    _ = await before(context);
                    return(context.IgnoreResult());
                });
            }
            _ = builder.Use("main", async context =>
            {
                Parser parser = CommandLines.CreateDefaultParser(command, context);
                return(await parser.InvokeAsync(context.Origin, context.Services.GetConsole()));
            });
            if (after != null)
            {
                _ = builder.Use("after", async context =>
                {
                    _ = await after(context);
                    return(context.IgnoreResult());
                });
            }
            return(await ConsumePipelineBuilder(builder, new Logger(), origin));
        }
Example #5
0
        void Button02(object sender, EventArgs args)
        {
            //prolog.Reset();
            //Label label = new Label();
            //string code = "square(X,Y) :- Y is X * X. ";
            string query = "split(\"ab.cd.\", X).";

            //string codeTitle = "conde2";

            //label.Text =
            //    string.Format("{0} {1}\n", prolog.Prompt, query);

            //if (SetClause(prolog, code, false, codeTitle))
            //    StatusLabel.Text = "Set Clauses";

            CommandLines.Last().Command = query;
            CommandLines.Last().CommandLabel.Text = CommandLines.Last().Command;
            CommandLines.Last().CommandEntry.Focus();

            //List<Solution> solutions = GetSolutions(prolog, query);
            //label.Text += SolutionsString(solutions);
            //Console.Children.Add(label);

            //prolog.Reset();
            //AddPrompt(GetPromptText(prolog.Prompt));

            /*
             * Console.HeightRequest = Console.Height + 100.0;
             *
             * Label3.Text = string.Format("Console Size = ( {0}, {1} )",
             *                          Console.Width, Console.HeightRequest);
             * //Label2.Text = "Clicked " + Console.HeightRequest.ToString();
             * ConsoleBack.ScrollToAsync(0, Console.HeightRequest, false);
             */
        }
Example #6
0
        async void CancelEditor(object sender, EventArgs e)
        {
            if (FileEditor.Text != OriginalFile)
            {
                if (await DisplayAlert("Don't Save?", "", "Cancel", "OK"))
                {
                    return;
                }
            }

            FileEditorGrid.IsVisible = false;
            CommandLines.Last().CommandEntry.Focus();

            /*
             * if (FileEditor.Text == OriginalFile)
             * {
             *  FileEditorGrid.IsVisible = false;
             *  CommandLines.Last().CommandEntry.Focus();
             * }
             * else if(!await DisplayAlert("Don't Save?", "", "Cancel", "OK"))
             * {
             *  FileEditorGrid.IsVisible = false;
             *  CommandLines.Last().CommandEntry.Focus();
             * }
             */
        }
Example #7
0
        // Buttons of FileEditor Menu:
        //     save File & exit, save File, exit without saving file
        void SaveExitFile(object sender, EventArgs e)
        {
            // PCL Storage: Write content in IFile
            IWriteFile(CurrentFile.iFile, FileEditor.Text);

            FileEditorGrid.IsVisible = false;
            CommandLines.Last().CommandEntry.Focus();
        }
Example #8
0
        // Buttons of FileEditor Menu:
        //     save File & exit, save File, exit without saving file
        void SaveExitFile(object sender, EventArgs e)
        {
            string name = (FileEditorTitle.Text).Substring(11);

            File.WriteAllText(WorkingDir + name, FileEditor.Text);
            FileEditorGrid.IsVisible = false;
            CommandLines.Last().CommandEntry.Focus();
        }
 private void AddCommandLines(params string[] lines)
 {
     foreach (string line in lines)
     {
         var commandline = new PrimitiveViewModel <string>(line);
         commandline.RemoveRequested += HandleCommandLineRemoveRequested;
         CommandLines.Add(commandline);
     }
 }
Example #10
0
 public static Builder UseCliCommand(this Builder builder) => builder.Use(nameof(UseCliCommand),
                                                                          async context =>
 {
     Parser cliCommand = CommandLines.CreateDefaultParser(context.Services.GetCliCommand(), context);
     IConsole console  = context.Services.GetConsole();
     int exitCode      = await cliCommand.InvokeAsync(context.Origin, console);
     if (!context.Services.TryGet <string>(out _, ServicesExtensions.ArgWorkspaceNameId))    // No workspace id, cliCommand interrupt by --help or --version
     {
         context.IsStopped = true;
     }
     return(exitCode);
 });
Example #11
0
 public static Builder UseCliCommand(this Builder builder) => builder.Use(nameof(UseCliCommand),
                                                                          async context =>
 {
     Parser cliCommand = CommandLines.CreateDefaultParser(context.Services.GetCliCommand(), context);
     IConsole console  = context.Services.GetConsole();
     int exitCode      = await cliCommand.InvokeAsync(context.Origin, console);
     if (!context.Services.TryGet <IWorkspace>(out _))    // No workspace, cliCommand interrupt
     {
         context.IsStopped = true;
     }
     return(exitCode);
 });
Example #12
0
        public MainPage()
        {
            InitializeComponent();

            CreateRootFolder();

            AddPrompt(CurrentFolder.Path);

            // Just after launching the App, Entry.Focus() doesn't work like
            // ScrollToAsync() due to timing probelm(?), so maake it into Timer
            Device.StartTimer(TimeSpan.FromMilliseconds(1), () =>
            {
                CommandLines.Last().CommandEntry.Focus();
                return(false);   // Timer Cycle is only one time
            });
        }
        public MainPage()
        {
            InitializeComponent();

            // Add the 1st Prompt on the Console
#if SystemIO
            AddPrompt(GetPromptText());
#elif PCLStorage
            CreateRootFolder();
            AddPrompt(CurrentFolder.Path);
            //Label1.Text = LocalStorage.
#endif

            // Just after launching the App, Entry.Focus() doesn't work
            // due to timing probelm(?), so maake it into Timer
            Device.StartTimer(TimeSpan.FromMilliseconds(1), () =>
            {
                CommandLines.Last().CommandEntry.Focus();
                return(false);   // Timer Cycle is only one time
            });
        }
Example #14
0
        protected override async Task <int> Handle(CArgument argument, IConsole console, InvocationContext context, PipelineContext pipeline, CancellationToken cancellationToken)
        {
            Environment.CurrentDirectory = argument.Directory !.FullName;
            pipeline.Services.Add <IWorkspace>(new Managements.FSBased.Workspace(argument.Directory));
            ILogger logger = pipeline.Services.GetLogger();

            if (argument.Command != "")
            {
                Parser repl = CommandLines.CreateDefaultParser(pipeline.Services.GetReplCommand(), pipeline);
                pipeline.IsStopped = true;
                return(await repl.InvokeAsync(argument.Command, console));
            }

            if (argument.Verbose)
            {
            }
            else
            {
                _ = logger.UseLevelFilter(LogLevel.Information);
            }

            return(0);
        }
Example #15
0
        //string WorkingDir = @"C:\Users\0000010745011\AppData\Local\Packages\135baee3-8b33-4698-955b-a2060bcefdfe_zkjxvjmeh878e\LocalState\RootFolder";

        // Identify Input Command and Execute it
        void CommandExecute(string command)
        {
            string result = ""; // String of the command execute result

            // Get the three characters of the command to identify
            string com = command;

            if (command != null)
            {
                if (command.Length > 3)
                {
                    com = command.Substring(0, 3);
                }
            }

            // Identify the command from the extracted three characters
            switch (com)
            {
            case "":        // No command, only CR
            case null:
                AddPrompt(GetPromptText());
                return;

            case "pro":     // Run the Prolog Interpreter
                if (command == "prolog")
                {
                    RunProlog = true;
                    prolog.Reset();
                    result = "\n";
                }
                else
                {
                    result = "Command Invalid";
                }

                break;

            case "dir":     // Show the files and the directories
                result = dir();
                break;

            case "pwd":     // Print the current working directory
                result = ">" + CurrentDir + "\n";
                break;


            case "ed ":     // Run the file editor
                result = ed(command);
                break;

            default:        // Text other than the commands is entered, return the text
                result = command + "\n";
                break;
            }

            // Display the Command Execute Result following the Command Line
            Console.Children.Add(new Label()
            {
                Text = result
            });

            // Store the result
            CommandLines.Last().Results = result;

            // Add a new Command Line
            AddPrompt(GetPromptText());
        }
Example #16
0
 void Button02(object sender, EventArgs args)
 {
     IDleteAllObjects(LocalStorage);
     CommandLines.Last().CommandEntry.Focus();
 }
Example #17
0
 void CancelEditor(object sender, EventArgs e)
 {
     FileEditorGrid.IsVisible = false;
     CommandLines.Last().CommandEntry.Focus();
 }
Example #18
0
 // Focus Command Line, if Tap Console
 void OnTapConsole(object sender, EventArgs args)
 {
     CommandLines.Last().CommandEntry.Focus();
 }
Example #19
0
        // Identify Input Command and Execute it
        async void CommandExecute(string command)
        {
            string result = "";

            // Get the first three characters of command
            string com = command;

            if (command != null)
            {
                if (command.Length > 3)
                {
                    com = command.Substring(0, 3);
                }
            }


            // Identify the command from the first three characters
            switch (com)
            {
            case "":
            case null:
                AddPrompt(CurrentFolder.Path);
                return;

            case "pro":
                if (command == "prolog")
                {
                    RunProlog = true;
                    prolog.Reset();
                    result = "\n";
                }
                else
                {
                    result = "Command Invalid";
                }
                break;

            case "dir":
                result = dir();
                break;

            case "pwd":
                result = CurrentFolder.Path + "\n";
                break;

            case "mkd":
                result = await mkdir(command);

                break;

            case "cd ":
                result = await cd(command);

                break;

            case "del":
                result = await del(command);

                break;

            case "mor":
                result = await more(command);

                break;

            case "ed ":
                result = await ed(command);

                break;



            default:
                result = "No Command" + "\n";
                break;
            }

            // Display the Command Execute Result following the Command Line
            Console.Children.Add(new Label()
            {
                Text = result
            });

            // Store the result
            CommandLines.Last().Results = result;

            // Add a new Command Line
            //AddPrompt(CurrentFolder.Path);
            AddPrompt(GetPromptText());
        }
Example #20
0
        async void PrologInterpreter(string command)
#endif
        {
            string          result    = "";
            string          com       = "";
            List <Solution> solutions = new List <Solution>();

            // Get the first character of the command
// #if iOS
            if (command != null)
            {
// #else // else if UWP
//             if(command != "")
// #endif
                com = command.Substring(0, 1);
            }

            // Identify the command from the three characters
            switch (com)
            {
            case "":
            case null:
                AddPrompt(GetPromptText());
                return;

            case "l":       // List Segments of the current folder
                if (command == "ls.")
                {
                    result = ls();
                    break;
                }
                else
                {
                    goto default;
                }

            case "[":       // Load Program
#if SystemIO
                result = SetProgram(command);
#elif PCLStorage
                result = await SetProgram(command);
#endif
                break;


            case "h":       // Exit Prolog Interpreter
                if (command == "halt.")
                {
                    RunProlog = false;
                    prolog.Reset();
                    result = "\n";
                    //System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
                    break;
                }
                else
                {
                    goto default;
                }
            //{
            //    result = "Command Invalid";
            //}
            //break;

            case "r":       // Reset Prolog Engine
                if (command == "reset.")
                {
                    prolog.Reset();
                    result = "\n";
                    break;
                }
                else
                {
                    goto default;
                }
            //{
            //    result = "Command Invalid";
            //}
            //break;


            default:        // Query Input
                solutions = GetSolutions(prolog, command);
                result    = SolutionsString(solutions);
                break;
            }

            // Display the Command Execute Result following the Command Line
            Console.Children.Add(new Label()
            {
                Text = result
            });

            // Store the result
            CommandLines.Last().Results = result;

            // Add a new Command Line
            AddPrompt(GetPromptText());
        }