Exemplo n.º 1
0
 internal void Initialize(string[] propertyNames, int screenColumnWidth, DisplayCells dc)
 {
     this.columnWidth = screenColumnWidth;
     if ((propertyNames == null) || (propertyNames.Length == 0))
     {
         this.disabled = true;
     }
     else
     {
         this.disabled = false;
         if ((((screenColumnWidth - " : ".Length) - 1) - 1) < 0)
         {
             this.disabled = true;
         }
         else
         {
             int num = (screenColumnWidth - " : ".Length) - 1;
             this.propertyLabelsDisplayLength = 0;
             int[] numArray = new int[propertyNames.Length];
             for (int i = 0; i < propertyNames.Length; i++)
             {
                 numArray[i] = dc.Length(propertyNames[i]);
                 if (numArray[i] > this.propertyLabelsDisplayLength)
                 {
                     this.propertyLabelsDisplayLength = numArray[i];
                 }
             }
             if (this.propertyLabelsDisplayLength > num)
             {
                 this.propertyLabelsDisplayLength = num;
             }
             this.propertyLabels = new string[propertyNames.Length];
             for (int j = 0; j < propertyNames.Length; j++)
             {
                 string[] strArray = null;
                 IntPtr   ptr;
                 if (numArray[j] < this.propertyLabelsDisplayLength)
                 {
                     this.propertyLabels[j] = propertyNames[j] + new string(' ', this.propertyLabelsDisplayLength - numArray[j]);
                 }
                 else if (numArray[j] > this.propertyLabelsDisplayLength)
                 {
                     this.propertyLabels[j] = propertyNames[j].Substring(0, dc.GetHeadSplitLength(propertyNames[j], this.propertyLabelsDisplayLength));
                 }
                 else
                 {
                     this.propertyLabels[j] = propertyNames[j];
                 }
                 strArray             = this.propertyLabels;
                 ptr                  = (IntPtr)j;
                 strArray[(int)(ptr)] = strArray[(int)ptr] + " : ";
             }
             this.propertyLabelsDisplayLength += " : ".Length;
         }
     }
 }
Exemplo n.º 2
0
        internal void Initialize(string[] propertyNames, int screenColumnWidth, DisplayCells dc)
        {
            this.columnWidth = screenColumnWidth;
            if ((propertyNames == null) || (propertyNames.Length == 0))
            {
                this.disabled = true;
            }
            else
            {
                this.disabled = false;
                if ((((screenColumnWidth - " : ".Length) - 1) - 1) < 0)
                {
                    this.disabled = true;
                }
                else
                {
                    int num = (screenColumnWidth - " : ".Length) - 1;
                    this.propertyLabelsDisplayLength = 0;
                    int[] numArray = new int[propertyNames.Length];
                    for (int i = 0; i < propertyNames.Length; i++)
                    {
                        numArray[i] = dc.Length(propertyNames[i]);
                        if (numArray[i] > this.propertyLabelsDisplayLength)
                        {
                            this.propertyLabelsDisplayLength = numArray[i];
                        }
                    }
                    if (this.propertyLabelsDisplayLength > num)
                    {
                        this.propertyLabelsDisplayLength = num;
                    }
                    this.propertyLabels = new string[propertyNames.Length];
                    for (int j = 0; j < propertyNames.Length; j++)
                    {
                        string[] strArray = null;
                        IntPtr ptr;
                        if (numArray[j] < this.propertyLabelsDisplayLength)
                        {
                            this.propertyLabels[j] = propertyNames[j] + new string(' ', this.propertyLabelsDisplayLength - numArray[j]);
                        }
                        else if (numArray[j] > this.propertyLabelsDisplayLength)
                        {
                            this.propertyLabels[j] = propertyNames[j].Substring(0, dc.GetHeadSplitLength(propertyNames[j], this.propertyLabelsDisplayLength));
                        }
                        else
                        {
                            this.propertyLabels[j] = propertyNames[j];
                        }
						strArray = this.propertyLabels;
						ptr = (IntPtr) j;
						strArray[(int) (ptr)] = strArray[(int) ptr] + " : ";
                    }
                    this.propertyLabelsDisplayLength += " : ".Length;
                }
            }
        }
Exemplo n.º 3
0
        private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen)
        {
            StringCollection retVal = new StringCollection();

            if (string.IsNullOrEmpty(val))
            {
                retVal.Add(val);
                return(retVal);
            }
            string[] strArray = SplitLines(val);
            for (int i = 0; i < strArray.Length; i++)
            {
                if ((strArray[i] == null) || (displayCells.Length(strArray[i]) <= firstLineLen))
                {
                    retVal.Add(strArray[i]);
                    continue;
                }
                SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen);
                int offset = 0;
                while (true)
                {
                    int activeLen = accumulator.ActiveLen;
                    int num5      = displayCells.Length(strArray[i], offset) - activeLen;
                    if (num5 <= 0)
                    {
                        break;
                    }
                    int length = displayCells.GetHeadSplitLength(strArray[i], offset, activeLen);
                    if (length <= 0)
                    {
                        length = 1;
                        accumulator.AddLine("?");
                    }
                    else
                    {
                        accumulator.AddLine(strArray[i].Substring(offset, length));
                    }
                    offset += length;
                }
                accumulator.AddLine(strArray[i].Substring(offset));
            }
            return(retVal);
        }
Exemplo n.º 4
0
 private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen)
 {
     StringCollection retVal = new StringCollection();
     if (string.IsNullOrEmpty(val))
     {
         retVal.Add(val);
         return retVal;
     }
     string[] strArray = SplitLines(val);
     for (int i = 0; i < strArray.Length; i++)
     {
         if ((strArray[i] == null) || (displayCells.Length(strArray[i]) <= firstLineLen))
         {
             retVal.Add(strArray[i]);
             continue;
         }
         SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen);
         int offset = 0;
         while (true)
         {
             int activeLen = accumulator.ActiveLen;
             int num5 = displayCells.Length(strArray[i], offset) - activeLen;
             if (num5 <= 0)
             {
                 break;
             }
             int length = displayCells.GetHeadSplitLength(strArray[i], offset, activeLen);
             if (length <= 0)
             {
                 length = 1;
                 accumulator.AddLine("?");
             }
             else
             {
                 accumulator.AddLine(strArray[i].Substring(offset, length));
             }
             offset += length;
         }
         accumulator.AddLine(strArray[i].Substring(offset));
     }
     return retVal;
 }
Exemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="propertyNames">names of the properties to display.</param>
        /// <param name="screenColumnWidth">column width of the screen.</param>
        /// <param name="dc">instance of the DisplayCells helper object.</param>
        internal void Initialize(string[] propertyNames, int screenColumnWidth, DisplayCells dc)
        {
            _columnWidth = screenColumnWidth;
            if (propertyNames == null || propertyNames.Length == 0)
            {
                // there is nothing to show
                _disabled = true;
                return;
            }

            _disabled = false;

            Debug.Assert(propertyNames != null, "propertyNames is null");
            Debug.Assert(propertyNames.Length > 0, "propertyNames has zero length");

            // assess the useful widths
            if ((screenColumnWidth - Separator.Length - MinFieldWidth - MinLabelWidth) < 0)
            {
                // we do not have enough space for any meaningful display
                _disabled = true;
                return;
            }

            // check if we have to truncate the labels
            int maxAllowableLabelLength = screenColumnWidth - Separator.Length - MinFieldWidth;

            // find out the max display length (cell count) of the property names
            _propertyLabelsDisplayLength = 0; // reset max

            // cache the cell lengths for each property
            Span <int> propertyNameCellCounts = propertyNames.Length <= OutCommandInner.StackAllocThreshold ? stackalloc int[propertyNames.Length] : new int[propertyNames.Length];;

            for (int k = 0; k < propertyNames.Length; k++)
            {
                Debug.Assert(propertyNames[k] != null, "propertyNames[k] is null");
                propertyNameCellCounts[k] = dc.Length(propertyNames[k]);
                if (propertyNameCellCounts[k] > _propertyLabelsDisplayLength)
                {
                    _propertyLabelsDisplayLength = propertyNameCellCounts[k];
                }
            }

            if (_propertyLabelsDisplayLength > maxAllowableLabelLength)
            {
                // need to truncate
                _propertyLabelsDisplayLength = maxAllowableLabelLength;
            }

            _propertyLabels = new string[propertyNames.Length];

            for (int k = 0; k < propertyNames.Length; k++)
            {
                if (propertyNameCellCounts[k] < _propertyLabelsDisplayLength)
                {
                    // shorter than the max, add padding
                    _propertyLabels[k] = propertyNames[k] + StringUtil.Padding(_propertyLabelsDisplayLength - propertyNameCellCounts[k]);
                }
                else if (propertyNameCellCounts[k] > _propertyLabelsDisplayLength)
                {
                    // longer than the max, clip
                    _propertyLabels[k] = propertyNames[k].Substring(0, dc.GetHeadSplitLength(propertyNames[k], _propertyLabelsDisplayLength));
                }
                else
                {
                    _propertyLabels[k] = propertyNames[k];
                }

                _propertyLabels[k] += Separator;
            }

            _propertyLabelsDisplayLength += Separator.Length;
        }
Exemplo n.º 6
0
        private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen)
        {
            StringCollection retVal = new StringCollection();

            if (string.IsNullOrEmpty(val))
            {
                // if null or empty, just add and we are done
                retVal.Add(val);
                return(retVal);
            }

            // break string on newlines and process each line separately
            string[] lines = SplitLines(val);

            for (int k = 0; k < lines.Length; k++)
            {
                if (lines[k] == null || displayCells.Length(lines[k]) <= firstLineLen)
                {
                    // we do not need to split further, just add
                    retVal.Add(lines[k]);
                    continue;
                }

                // the string does not fit, so we have to wrap around on multiple lines
                // for each of these lines in the string, the first line will have
                // a (potentially) different length (indentation or hanging)

                // for each line, start a new state
                SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen);

                int offset = 0; // offset into the line we are splitting

                while (true)
                {
                    // acquire the current active display line length (it can very from call to call)
                    int currentDisplayLen = accumulator.ActiveLen;

                    // determine if the current tail would fit or not

                    // for the remaining part of the string, determine its display cell count
                    int currentCellsToFit = displayCells.Length(lines[k], offset);

                    // determine if we fit into the line
                    int excessCells = currentCellsToFit - currentDisplayLen;

                    if (excessCells > 0)
                    {
                        // we are not at the end of the string, select a sub string
                        // that would fit in the remaining display length
                        int charactersToAdd = displayCells.GetHeadSplitLength(lines[k], offset, currentDisplayLen);

                        if (charactersToAdd <= 0)
                        {
                            // corner case: we have a two cell character and the current
                            // display length is one.
                            // add a single cell arbitrary character instead of the original
                            // one and keep going
                            charactersToAdd = 1;
                            accumulator.AddLine("?");
                        }
                        else
                        {
                            // of the given length, add it to the accumulator
                            accumulator.AddLine(lines[k].Substring(offset, charactersToAdd));
                        }

                        // increase the offset by the # of characters added
                        offset += charactersToAdd;
                    }
                    else
                    {
                        // we reached the last (partial) line, we add it all
                        accumulator.AddLine(lines[k].Substring(offset));
                        break;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 7
0
        private static string GenerateRowField(string val, int width, int alignment, DisplayCells dc, bool addPadding)
        {
            // make sure the string does not have any embedded <CR> in it
            string s = StringManipulationHelper.TruncateAtNewLine(val);

            string currentValue = s;
            int    currentValueDisplayLength = dc.Length(currentValue);

            if (currentValueDisplayLength < width)
            {
                // the string is shorter than the width of the column
                // need to pad with with blanks to reach the desired width
                int padCount = width - currentValueDisplayLength;
                switch (alignment)
                {
                case TextAlignment.Right:
                {
                    s = StringUtil.Padding(padCount) + s;
                }

                break;

                case TextAlignment.Center:
                {
                    // add a bit at both ends of the string
                    int padLeft  = padCount / 2;
                    int padRight = padCount - padLeft;

                    s = StringUtil.Padding(padLeft) + s;
                    if (addPadding)
                    {
                        s += StringUtil.Padding(padRight);
                    }
                }

                break;

                default:
                {
                    if (addPadding)
                    {
                        // left align is the default
                        s += StringUtil.Padding(padCount);
                    }
                }

                break;
                }
            }
            else if (currentValueDisplayLength > width)
            {
                // the string is longer than the width of the column
                // truncate and add ellipsis if it's too long
                int truncationDisplayLength = width - EllipsisSize;

                if (truncationDisplayLength > 0)
                {
                    // we have space for the ellipsis, add it
                    switch (alignment)
                    {
                    case TextAlignment.Right:
                    {
                        // get from "abcdef" to "...f"
                        int tailCount = dc.GetTailSplitLength(s, truncationDisplayLength);
                        s = s.Substring(s.Length - tailCount);
                        s = PSObjectHelper.Ellipsis + s;
                    }

                    break;

                    case TextAlignment.Center:
                    {
                        // get from "abcdef" to "a..."
                        s  = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
                        s += PSObjectHelper.Ellipsis;
                    }

                    break;

                    default:
                    {
                        // left align is the default
                        // get from "abcdef" to "a..."
                        s  = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
                        s += PSObjectHelper.Ellipsis;
                    }

                    break;
                    }
                }
                else
                {
                    // not enough space for the ellipsis, just truncate at the width
                    int len = width;

                    switch (alignment)
                    {
                    case TextAlignment.Right:
                    {
                        // get from "abcdef" to "f"
                        int tailCount = dc.GetTailSplitLength(s, len);
                        s = s.Substring(s.Length - tailCount, tailCount);
                    }

                    break;

                    case TextAlignment.Center:
                    {
                        // get from "abcdef" to "a"
                        s = s.Substring(0, dc.GetHeadSplitLength(s, len));
                    }

                    break;

                    default:
                    {
                        // left align is the default
                        // get from "abcdef" to "a"
                        s = s.Substring(0, dc.GetHeadSplitLength(s, len));
                    }

                    break;
                    }
                }
            }

            // we need to take into consideration that truncation left the string one
            // display cell short if a double cell character got truncated
            // in this case, we need to pad with a blank
            int finalValueDisplayLength = dc.Length(s);

            if (finalValueDisplayLength == width)
            {
                return(s);
            }

            switch (alignment)
            {
            case TextAlignment.Right:
            {
                s = " " + s;
            }

            break;

            case TextAlignment.Center:
            {
                if (addPadding)
                {
                    s += " ";
                }
            }

            break;

            default:
            {
                // left align is the default
                if (addPadding)
                {
                    s += " ";
                }
            }

            break;
            }

            return(s);
        }
Exemplo n.º 8
0
        private static string GenerateRowField(string val, int width, int alignment, DisplayCells dc)
        {
            // make sure the string does not have any embedded <CR> in it
            string s = StringManipulationHelper.TruncateAtNewLine(val) ?? "";

            string currentValue = s;
            int currentValueDisplayLength = dc.Length(currentValue);

            if (currentValueDisplayLength < width)
            {
                // the string is shorter than the width of the column
                // need to pad with with blanks to reach the desired width
                int padCount = width - currentValueDisplayLength;
                switch (alignment)
                {
                    case TextAlignment.Right:
                        {
                            s = new string(' ', padCount) + s;
                        }
                        break;

                    case TextAlignment.Center:
                        {
                            // add a bit at both ends of the string
                            int padLeft = padCount / 2;
                            int padRight = padCount - padLeft;

                            s = new string(' ', padLeft) + s + new string(' ', padRight);
                        }
                        break;

                    default:
                        {
                            // left align is the default
                            s += new string(' ', padCount);
                        }
                        break;
                }
            }
            else if (currentValueDisplayLength > width)
            {
                // the string is longer than the width of the column
                // truncate and add ellipsis if it's too long
                int truncationDisplayLength = width - ellipsis.Length;

                if (truncationDisplayLength > 0)
                {
                    // we have space for the ellipsis, add it
                    switch (alignment)
                    {
                        case TextAlignment.Right:
                            {
                                // get from "abcdef" to "...f"    
                                int tailCount = dc.GetTailSplitLength(s, truncationDisplayLength);
                                s = s.Substring(s.Length - tailCount);
                                s = ellipsis + s;
                            }
                            break;

                        case TextAlignment.Center:
                            {
                                // get from "abcdef" to "a..."
                                s = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
                                s += ellipsis;
                            }
                            break;

                        default:
                            {
                                // left align is the default
                                // get from "abcdef" to "a..."
                                s = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
                                s += ellipsis;
                            }
                            break;
                    }
                }
                else
                {
                    // not enough space for the ellipsis, just truncate at the width
                    int len = width;

                    switch (alignment)
                    {
                        case TextAlignment.Right:
                            {
                                // get from "abcdef" to "f"
                                int tailCount = dc.GetTailSplitLength(s, len);
                                s = s.Substring(s.Length - tailCount, tailCount);
                            }
                            break;

                        case TextAlignment.Center:
                            {
                                // get from "abcdef" to "a"
                                s = s.Substring(0, dc.GetHeadSplitLength(s, len));
                            }
                            break;

                        default:
                            {
                                // left align is the default
                                // get from "abcdef" to "a"
                                s = s.Substring(0, dc.GetHeadSplitLength(s, len));
                            }
                            break;
                    }
                }
            }

            // we need to take into consideration that truncation left the string one
            // display cell short if a double cell character got truncated
            // in this case, we need to pad with a blank
            int finalValueDisplayLength = dc.Length(s);
            if (finalValueDisplayLength == width)
            {
                return s;
            }
            // we have to pad
            System.Diagnostics.Debug.Assert(finalValueDisplayLength == width - 1, "padding is not correct");
            switch (alignment)
            {
                case TextAlignment.Right:
                    {
                        s = " " + s;
                    }
                    break;

                case TextAlignment.Center:
                    {
                        s += " ";
                    }
                    break;

                default:
                    {
                        // left align is the default
                        s += " ";
                    }
                    break;
            }

            return s;
        }
Exemplo n.º 9
0
        private static string GenerateRowField(string val, int width, int alignment, DisplayCells dc)
        {
            string str = StringManipulationHelper.TruncateAtNewLine(val);

            if (str == null)
            {
                str = "";
            }
            string str2 = str;
            int    num  = dc.Length(str2);

            if (num < width)
            {
                int count = width - num;
                switch (alignment)
                {
                case 2:
                {
                    int num3 = count / 2;
                    int num4 = count - num3;
                    str = new string(' ', num3) + str + new string(' ', num4);
                    goto Label_0182;
                }

                case 3:
                    str = new string(' ', count) + str;
                    goto Label_0182;
                }
                str = str + new string(' ', count);
            }
            else if (num > width)
            {
                int displayCells = width - "...".Length;
                if (displayCells > 0)
                {
                    switch (alignment)
                    {
                    case 2:
                        str = str.Substring(0, dc.GetHeadSplitLength(str, displayCells)) + "...";
                        goto Label_0182;

                    case 3:
                    {
                        int tailSplitLength = dc.GetTailSplitLength(str, displayCells);
                        str = str.Substring(str.Length - tailSplitLength);
                        str = "..." + str;
                        goto Label_0182;
                    }
                    }
                    str = str.Substring(0, dc.GetHeadSplitLength(str, displayCells)) + "...";
                }
                else
                {
                    int num7 = width;
                    switch (alignment)
                    {
                    case 2:
                        str = str.Substring(0, dc.GetHeadSplitLength(str, num7));
                        goto Label_0182;

                    case 3:
                    {
                        int length = dc.GetTailSplitLength(str, num7);
                        str = str.Substring(str.Length - length, length);
                        goto Label_0182;
                    }
                    }
                    str = str.Substring(0, dc.GetHeadSplitLength(str, num7));
                }
            }
Label_0182:
            if (dc.Length(str) == width)
            {
                return(str);
            }
            switch (alignment)
            {
            case 2:
                return(str + " ");

            case 3:
                return(" " + str);
            }
            return(str + " ");
        }
Exemplo n.º 10
0
        private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen)
        {
            StringCollection retVal = new StringCollection();

            if (string.IsNullOrEmpty(val))
            {
                // if null or empty, just add and we are done
                retVal.Add(val);
                return retVal;
            }

            // break string on newlines and process each line separately
            string[] lines = SplitLines(val);

            for (int k = 0; k < lines.Length; k++)
            {
                if (lines[k] == null || displayCells.Length(lines[k]) <= firstLineLen)
                {
                    // we do not need to split further, just add
                    retVal.Add(lines[k]);
                    continue;
                }

                // the string does not fit, so we have to wrap around on multiple lines
                // for each of these lines in the string, the first line will have
                // a (potentially) different length (indentation or hanging)

                // for each line, start a new state
                SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen);

                int offset = 0; // offset into the line we are splitting

                while (true)
                {
                    // acquire the current active display line length (it can very from call to call)
                    int currentDisplayLen = accumulator.ActiveLen;

                    // determine if the current tail would fit or not

                    // for the remaining part of the string, determine its display cell count
                    int currentCellsToFit = displayCells.Length(lines[k], offset);

                    // determine if we fit into the line
                    int excessCells = currentCellsToFit - currentDisplayLen;

                    if (excessCells > 0)
                    {
                        // we are not at the end of the string, select a sub string
                        // that would fit in the remaining display length
                        int charactersToAdd = displayCells.GetHeadSplitLength(lines[k], offset, currentDisplayLen);

                        if (charactersToAdd <= 0)
                        {
                            // corner case: we have a two cell character and the current
                            // display length is one.
                            // add a single cell arbitrary character instead of the original
                            // one and keep going
                            charactersToAdd = 1;
                            accumulator.AddLine("?");
                        }
                        else
                        {
                            // of the given length, add it to the accumulator
                            accumulator.AddLine(lines[k].Substring(offset, charactersToAdd));
                        }

                        // increase the offset by the # of characters added
                        offset += charactersToAdd;
                    }
                    else
                    {
                        // we reached the last (partial) line, we add it all
                        accumulator.AddLine(lines[k].Substring(offset));
                        break;
                    }
                }
            }

            return retVal;
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="propertyNames">names of the properties to display</param>
        /// <param name="screenColumnWidth">column width of the screen</param>
        /// <param name="dc">instance of the DisplayCells helper object</param>
        internal void Initialize(string[] propertyNames, int screenColumnWidth, DisplayCells dc)
        {
            _columnWidth = screenColumnWidth;
            if (propertyNames == null || propertyNames.Length == 0)
            {
                // there is nothing to show
                _disabled = true;
                return;
            }

            _disabled = false;

            Debug.Assert(propertyNames != null, "propertyNames is null");
            Debug.Assert(propertyNames.Length > 0, "propertyNames has zero length");

            // assess the useful widths
            if ((screenColumnWidth - Separator.Length - MinFieldWidth - MinLabelWidth) < 0)
            {
                // we do not have enough space for any meaningful display
                _disabled = true;
                return;
            }

            // check if we have to truncate the labels
            int maxAllowableLabelLength = screenColumnWidth - Separator.Length - MinFieldWidth;

            // find out the max display length (cell count) of the property names
            _propertyLabelsDisplayLength = 0; // reset max

            // cache the cell lengths for each property
            int[] propertyNameCellCounts = new int[propertyNames.Length];
            for (int k = 0; k < propertyNames.Length; k++)
            {
                Debug.Assert(propertyNames[k] != null, "propertyNames[k] is null");
                propertyNameCellCounts[k] = dc.Length(propertyNames[k]);
                if (propertyNameCellCounts[k] > _propertyLabelsDisplayLength)
                    _propertyLabelsDisplayLength = propertyNameCellCounts[k];
            }

            if (_propertyLabelsDisplayLength > maxAllowableLabelLength)
            {
                // need to truncate
                _propertyLabelsDisplayLength = maxAllowableLabelLength;
            }

            _propertyLabels = new string[propertyNames.Length];

            for (int k = 0; k < propertyNames.Length; k++)
            {
                if (propertyNameCellCounts[k] < _propertyLabelsDisplayLength)
                {
                    // shorter than the max, add padding
                    _propertyLabels[k] = propertyNames[k] + new string(' ', _propertyLabelsDisplayLength - propertyNameCellCounts[k]);
                }
                else if (propertyNameCellCounts[k] > _propertyLabelsDisplayLength)
                {
                    // longer than the max, clip
                    _propertyLabels[k] = propertyNames[k].Substring(0, dc.GetHeadSplitLength(propertyNames[k], _propertyLabelsDisplayLength));
                }
                else
                {
                    _propertyLabels[k] = propertyNames[k];
                }

                _propertyLabels[k] += Separator;
            }
            _propertyLabelsDisplayLength += Separator.Length;
        }
Exemplo n.º 12
0
        private static string GenerateRowField(string val, int width, int alignment, DisplayCells dc)
        {
            string str = StringManipulationHelper.TruncateAtNewLine(val);
            if (str == null)
            {
                str = "";
            }
            string str2 = str;
            int num = dc.Length(str2);
            if (num < width)
            {
                int count = width - num;
                switch (alignment)
                {
                    case 2:
                    {
                        int num3 = count / 2;
                        int num4 = count - num3;
                        str = new string(' ', num3) + str + new string(' ', num4);
                        goto Label_0182;
                    }
                    case 3:
                        str = new string(' ', count) + str;
                        goto Label_0182;
                }
                str = str + new string(' ', count);
            }
            else if (num > width)
            {
                int displayCells = width - "...".Length;
                if (displayCells > 0)
                {
                    switch (alignment)
                    {
                        case 2:
                            str = str.Substring(0, dc.GetHeadSplitLength(str, displayCells)) + "...";
                            goto Label_0182;

                        case 3:
                        {
                            int tailSplitLength = dc.GetTailSplitLength(str, displayCells);
                            str = str.Substring(str.Length - tailSplitLength);
                            str = "..." + str;
                            goto Label_0182;
                        }
                    }
                    str = str.Substring(0, dc.GetHeadSplitLength(str, displayCells)) + "...";
                }
                else
                {
                    int num7 = width;
                    switch (alignment)
                    {
                        case 2:
                            str = str.Substring(0, dc.GetHeadSplitLength(str, num7));
                            goto Label_0182;

                        case 3:
                        {
                            int length = dc.GetTailSplitLength(str, num7);
                            str = str.Substring(str.Length - length, length);
                            goto Label_0182;
                        }
                    }
                    str = str.Substring(0, dc.GetHeadSplitLength(str, num7));
                }
            }
        Label_0182:
            if (dc.Length(str) == width)
            {
                return str;
            }
            switch (alignment)
            {
                case 2:
                    return (str + " ");

                case 3:
                    return (" " + str);
            }
            return (str + " ");
        }