Esempio n. 1
0
        public void RunShell()
        {
            _readline = new Readline.Readline(History)
            {
                CtrlCInterrupts = CtrlCInterrupts,
                CtrlDIsEOF      = CtrlDIsEOF,
                CtrlZIsEOF      = CtrlZIsEOF
            };

            _readline.WritePrompt       += ReadlineOnWritePrompt;
            _readline.Interrupt         += (sender, args) => ShellInterrupt?.Invoke(this, EventArgs.Empty);
            _readline.TabComplete       += ReadlineOnTabComplete;
            _readline.PrintAlternatives += (sender, args) => OnPrintAlternatives(args);

            while (true)
            {
                var input = _readline.ReadLine();

                if (string.IsNullOrWhiteSpace(input))
                {
                    continue;
                }

                input = input.Trim();


                var allTokens = ShellCommandTokenizer.Tokenize(input);

                foreach (var cmdTokens in allTokens)
                {
                    try
                    {
                        var tokenArr = cmdTokens.ToArray();

                        IShellCommand command = null;
                        lock (_lock)
                        {
                            command = _container.FindCommand(this, tokenArr);
                        }

                        BeforeCommandExecute?.Invoke(this, new CommandExecuteEventArgs(input, null, command));
                        ExecuteCommand(tokenArr);
                        AfterCommandExecute?.Invoke(this, new CommandExecuteEventArgs(input, CommandResult, command));
                    }
                    catch (ShellCommandNotFoundException)
                    {
                        OnShellCommandNotFound(input);
                    }
                }

                History.AddUnique(input);
            }
        }
Esempio n. 2
0
        public virtual string ReadPassword(Action writePromtAction)
        {
            var readline = new Readline.Readline(new ShellHistory())
            {
                CtrlCInterrupts = CtrlCInterrupts,
                CtrlDIsEOF      = CtrlDIsEOF,
                CtrlZIsEOF      = CtrlZIsEOF
            };

            readline.WritePrompt += (sender, args) => writePromtAction?.Invoke();
            readline.Interrupt   += (sender, args) => ShellInterrupt?.Invoke(this, EventArgs.Empty);

            return(readline.ReadPassword());
        }
Esempio n. 3
0
        public void RunShell()
        {
            var readline = new Readline.Readline(History)
            {
                CtrlCInterrupts = CtrlCInterrupts,
                CtrlDIsEOF      = CtrlDIsEOF,
                CtrlZIsEOF      = CtrlZIsEOF
            };

            readline.WritePrompt       += ReadlineOnWritePrompt;
            readline.Interrupt         += (sender, args) => ShellInterrupt?.Invoke(this, EventArgs.Empty);
            readline.TabComplete       += ReadlineOnTabComplete;
            readline.PrintAlternatives += (sender, args) => OnPrintAlternatives(args);

            while (true)
            {
                var input = readline.ReadLine();

                if (string.IsNullOrWhiteSpace(input))
                {
                    continue;
                }

                input = input.Trim();

                try
                {
                    ExecuteCommand(input);
                }
                catch (ShellCommandNotFoundException)
                {
                    OnShellCommandNotFound(input);
                }

                History.AddUnique(input);
            }
        }