src/System.Management.Automation/FormatAndOutput/common/ListWriter.cs
/// <summary>
/// Internal helper to split a line that is too long to fit and pad it to the left
/// with a given string.
/// </summary>
/// <param name="prependString">String to add to the left.</param>
/// <param name="line">Line to print.</param>
/// <param name="lo">LineOutput to write to.</param>
Internal helper to split a line that is too long to fit and pad it to the left
with a given string.
Internal helper to split a line that is too long to fit and pad it to the left with a given string .
private void WriteSingleLineHelper(string prependString, string line, LineOutput lo)
        {
            if (line is null)
            {
                line = string.Empty;
            }
            int fieldCellCount = _columnWidth - _propertyLabelsDisplayLength;
            StringCollection sc = StringManipulationHelper.GenerateLines(lo.DisplayCells, line, fieldCellCount, fieldCellCount);
            string headPadding = null;
            string style = PSStyle.Instance.Formatting.FormatAccent;
            string reset = PSStyle.Instance.Reset;
            for (int k = 0; k < sc.Count; k++)
            {
                string str = sc[k];
                _cachedBuilder.Clear();
                if (k == 0)
                {
                    if (string.IsNullOrWhiteSpace(prependString) || style == string.Empty)
                    {
                        _cachedBuilder.Append(prependString).Append(str);
                    }
                    else
                    {
                        _cachedBuilder
                            .Append(style)
                            .Append(prependString)
                            .Append(reset)
                            .Append(str);
                    }
                }
                else
                {
                    headPadding ??= StringUtil.Padding(_propertyLabelsDisplayLength);
                    _cachedBuilder.Append(headPadding).Append(str);
                }
                if (str.Contains(ValueStringDecorated.ESC) && !str.EndsWith(reset))
                {
                    _cachedBuilder.Append(reset);
                }
                lo.WriteLine(_cachedBuilder.ToString());
            }
        }
private void WriteSingleLineHelper ( string prependString , string line , LineOutput lo ) { if ( line is null ) { line = string . Empty ; } int fieldCellCount = _columnWidth - _propertyLabelsDisplayLength ; StringCollection sc = StringManipulationHelper . GenerateLines ( lo . DisplayCells , line , fieldCellCount , fieldCellCount ) ; string headPadding = null ; string style = PSStyle . Instance . Formatting . FormatAccent ; string reset = PSStyle . Instance . Reset ; for ( int k = 0 ; k < sc . Count ; k ++ ) { string str = sc [ k ] ; _cachedBuilder . Clear ( ) ; if ( k == 0 ) { if ( string . IsNullOrWhiteSpace ( prependString ) || style == string . Empty ) { _cachedBuilder . Append ( prependString ) . Append ( str ) ; } else { _cachedBuilder . Append ( style ) . Append ( prependString ) . Append ( reset ) . Append ( str ) ; } } else { headPadding ??= StringUtil . Padding ( _propertyLabelsDisplayLength ) ; _cachedBuilder . Append ( headPadding ) . Append ( str ) ; } if ( str . Contains ( ValueStringDecorated . ESC ) && ! str . EndsWith ( reset ) ) { _cachedBuilder . Append ( reset ) ; } lo . WriteLine ( _cachedBuilder . ToString ( ) ) ; } }
Internal helper to split a line that is too long to fit and pad it to the left
with a given string.
Internal helper to split a line that is too long to fit and pad it to the left with a given string .
// compute the width of the field for the value string (in screen cells) // split the lines // The padding to use in the lines after the first. // The VT style used for the list label. // display the string collection // - Sometimes 'prependString' is just padding white spaces, and we don't //   need to add formatting escape sequences in such a case. // - Otherwise, if the style is an empty string, then the user has chosen //   to not apply a style to the list label. // Apply the style to the list label. // Lazily calculate the padding to use for the subsequent lines as it's quite often that only the first line exists.
prependString
string
String to add to the left.
String to add to the left .
line
string
Line to print.
Line to print .
lo
LineOutput
LineOutput to write to.
LineOutput to write to .