/// <summary> /// helper, writing a single property to the screen. /// It wraps the value of the property if it is tool long to fit /// </summary> /// <param name="k">index of property to write.</param> /// <param name="propertyValue">string value of the property to write.</param> /// <param name="lo">LineOutput interface to write to.</param> private void WriteProperty(int k, string propertyValue, LineOutput lo) { if (propertyValue == null) { propertyValue = string.Empty; } // make sure we honor embedded newlines string[] lines = StringManipulationHelper.SplitLines(propertyValue); // padding to use in the lines after the first string padding = null; for (int i = 0; i < lines.Length; i++) { string prependString = null; if (i == 0) { prependString = _propertyLabels[k]; } else { if (padding == null) { padding = StringUtil.Padding(_propertyLabelsDisplayLength); } prependString = padding; } WriteSingleLineHelper(prependString, lines[i], lo); } }
private void WriteProperty(int k, string propertyValue, LineOutput lo) { if (propertyValue == null) { propertyValue = ""; } string[] strArray = StringManipulationHelper.SplitLines(propertyValue); string str = null; for (int i = 0; i < strArray.Length; i++) { string prependString = null; if (i == 0) { prependString = this.propertyLabels[k]; } else { if (str == null) { str = prependString = new string(' ', this.propertyLabelsDisplayLength); } prependString = str; } this.WriteSingleLineHelper(prependString, strArray[i], lo); } }
/// <summary> /// Internal helper, needed because it might make recursive calls to itself. /// </summary> /// <param name="val">String to process.</param> /// <param name="cols">Width of the device.</param> private void WriteLineInternal(string val, int cols) { if (string.IsNullOrEmpty(val)) { _writeLineCall(val); return; } // If the output is being redirected, then we don't break val if (!_lineWrap) { _writeCall(val); return; } // check for line breaks List <string> lines = StringManipulationHelper.SplitLines(val); // process the substrings as separate lines for (int k = 0; k < lines.Count; k++) { // compute the display length of the string int displayLength = _displayCells.Length(lines[k]); if (displayLength < cols) { // NOTE: this is the case where where System.Console.WriteLine() would work just fine _writeLineCall(lines[k]); continue; } if (displayLength == cols) { // NOTE: this is the corner case where System.Console.WriteLine() cannot be called _writeCall(lines[k]); continue; } // the string does not fit, so we have to wrap around on multiple lines string s = lines[k]; while (true) { // the string is still too long to fit, write the first cols characters // and go back for more wraparound int headCount = _displayCells.TruncateTail(s, cols); WriteLineInternal(s.VtSubstring(0, headCount), cols); // chop off the first fieldWidth characters, already printed s = s.VtSubstring(headCount); if (_displayCells.Length(s) <= cols) { // if we fit, print the tail of the string and we are done WriteLineInternal(s, cols); break; } } } }
private void WriteLineInternal(string val, int cols) { if (string.IsNullOrEmpty(val)) { this.writeLineCall(val); } else if (!this.lineWrap) { this.writeCall(val); } else { string[] strArray = StringManipulationHelper.SplitLines(val); for (int i = 0; i < strArray.Length; i++) { int num2 = this._displayCells.Length(strArray[i]); if (num2 < cols) { this.writeLineCall(strArray[i]); } else if (num2 == cols) { this.writeCall(strArray[i]); } else { string str = strArray[i]; do { int headSplitLength = this._displayCells.GetHeadSplitLength(str, cols); this.WriteLineInternal(str.Substring(0, headSplitLength), cols); str = str.Substring(headSplitLength); }while (this._displayCells.Length(str) > cols); this.WriteLineInternal(str, cols); } } } }