private async Task StartReplLoopAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { string commandString = null; int originalCursorTop = 0; try { await this.WritePromptStringToHostAsync(cancellationToken); } catch (OperationCanceledException) { break; } try { originalCursorTop = await ConsoleProxy.GetCursorTopAsync(cancellationToken); commandString = await this.ReadCommandLineAsync(cancellationToken); } catch (PipelineStoppedException) { this.WriteOutput( "^C", true, OutputType.Normal, foregroundColor: ConsoleColor.Red); } // Do nothing here, the while loop condition will exit. catch (TaskCanceledException) { } catch (OperationCanceledException) { } catch (Exception e) // Narrow this if possible { this.WriteOutput( $"\n\nAn error occurred while reading input:\n\n{e.ToString()}\n", true, OutputType.Error); Logger.WriteException("Caught exception while reading command line", e); } finally { if (!cancellationToken.IsCancellationRequested && originalCursorTop == await ConsoleProxy.GetCursorTopAsync(cancellationToken)) { this.WriteLine(); } } if (!string.IsNullOrWhiteSpace(commandString)) { var unusedTask = this.powerShellContext .ExecuteScriptStringAsync( commandString, writeInputToHost: false, writeOutputToHost: true, addToHistory: true) .ConfigureAwait(continueOnCapturedContext: false); break; } } }
public override void OnRegister() { _proxy = (ConsoleProxy) Facade.RetrieveProxy(ConsoleProxy.NAME); }
void CreateConsole(Jint.Engine engine) { var console = new ConsoleProxy(engine, context); engine.SetValue("console", console); }
/// <summary> /// Initializes a new instance of the Controller class. /// </summary> /// <param name="model">The model.</param> /// <param name="setup"> /// The setup. Optional overwrite of the extensions added to the /// console. Is not specified the Default setup is applied. /// </param> public Controller(object model, Action <Controller> setup = null) : this(model, ConsoleProxy.Instance(), setup) { }
/// <summary> /// Waits for a short period. /// </summary> /// <param name="op">The operation data.</param> /// <param name="done">The completion callback.</param> public void HandleOp(OperationData op, Action done) { ConsoleProxy.log("Waiting..."); window.setTimeout(done, 1500); }