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); } }
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()); }
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); } }
public string ReadPassword(Action writePromtAction) { var readline = new Readline.Readline(History) { CtrlCInterrupts = CtrlCInterrupts, CtrlDIsEOF = CtrlDIsEOF, CtrlZIsEOF = CtrlZIsEOF }; readline.WritePrompt += (sender, args) => WritePrompt?.Invoke(this, EventArgs.Empty); readline.Interrupt += (sender, args) => ShellInterrupt?.Invoke(this, EventArgs.Empty); return readline.ReadPassword(); }