private LineOutput InstantiateLineOutputInterface() { StreamingTextWriter.WriteLineCallback writeCall = new StreamingTextWriter.WriteLineCallback(this.OnWriteLine); this.writer = new StreamingTextWriter(writeCall, base.Host.CurrentCulture); int columns = 80; if (this.width.HasValue) { columns = this.width.Value; } else { try { columns = base.Host.UI.RawUI.BufferSize.Width - 1; } catch (HostException) { } } return new TextWriterLineOutput(this.writer, columns); }
/// <summary> /// one time initialization: acquire a screen host interface /// by creating one on top of a stream /// </summary> private LineOutput InstantiateLineOutputInterface() { // set up the streaming text writer StreamingTextWriter.WriteLineCallback callback = new StreamingTextWriter.WriteLineCallback(this.OnWriteLine); _writer = new StreamingTextWriter(callback, Host.CurrentCulture); // compute the # of columns available int computedWidth = 120; if (_width != null) { // use the value from the command line computedWidth = _width.Value; } else { // use the value we get from the console try { // NOTE: we subtract 1 because we want to properly handle // the following scenario: // MSH>get-foo|format-table|out-string // in this case, if the computed width is (say) 80, get-content // would cause a wrapping of the 80 column long raw strings. // Hence we set the width to 79. computedWidth = this.Host.UI.RawUI.BufferSize.Width - 1; } catch (HostException) { // non interactive host } } // use it to create and initialize the Line Output writer TextWriterLineOutput twlo = new TextWriterLineOutput(_writer, computedWidth); // finally have the LineOutput interface extracted return (LineOutput)twlo; }