/// <summary>
 /// Determine how many rows the prompt should take.
 /// </summary>
 /// <param name="cols">Current number of columns on the screen.</param>
 /// <param name="displayCells">String manipulation helper.</param>
 /// <returns></returns>
 internal int ComputePromptLines(DisplayCells displayCells, int cols)
 {
     // split the prompt string into lines
     _actualPrompt = StringManipulationHelper.GenerateLines(displayCells, _promptString, cols, cols);
     return(_actualPrompt.Count);
 }
示例#2
0
        /// <summary>
        /// Write to the output interface.
        /// </summary>
        private void WriteToScreen()
        {
            int leftIndentation      = _indentationManager.LeftIndentation;
            int rightIndentation     = _indentationManager.RightIndentation;
            int firstLineIndentation = _indentationManager.FirstLineIndentation;

            // VALIDITY CHECKS:

            // check the useful ("active") width
            int usefulWidth = _textColumns - rightIndentation - leftIndentation;

            if (usefulWidth <= 0)
            {
                // fatal error, there is nothing to write to the device
                // just clear the buffer and return
                _stringBuffer = new StringBuilder();
            }

            // check indentation or hanging is not larger than the active width
            int indentationAbsoluteValue = (firstLineIndentation > 0) ? firstLineIndentation : -firstLineIndentation;

            if (indentationAbsoluteValue >= usefulWidth)
            {
                // valu too big, we reset it to zero
                firstLineIndentation = 0;
            }

            // compute the first line indentation or hanging
            int firstLineWidth      = _textColumns - rightIndentation - leftIndentation;
            int followingLinesWidth = firstLineWidth;

            if (firstLineIndentation >= 0)
            {
                // the first line has an indentation
                firstLineWidth -= firstLineIndentation;
            }
            else
            {
                // the first line is hanging
                followingLinesWidth += firstLineIndentation;
            }

            // error checking on invalid values

            // generate the lines using the computed widths
            StringCollection sc = StringManipulationHelper.GenerateLines(_lo.DisplayCells, _stringBuffer.ToString(),
                                                                         firstLineWidth, followingLinesWidth);

            // compute padding
            int firstLinePadding      = leftIndentation;
            int followingLinesPadding = leftIndentation;

            if (firstLineIndentation >= 0)
            {
                // the first line has an indentation
                firstLinePadding += firstLineIndentation;
            }
            else
            {
                // the first line is hanging
                followingLinesPadding -= firstLineIndentation;
            }

            // now write the lines on the screen
            bool firstLine = true;

            foreach (string s in sc)
            {
                if (firstLine)
                {
                    firstLine = false;
                    _lo.WriteLine(StringManipulationHelper.PadLeft(s, firstLinePadding));
                }
                else
                {
                    _lo.WriteLine(StringManipulationHelper.PadLeft(s, followingLinesPadding));
                }
            }

            _stringBuffer = new StringBuilder();
        }
示例#3
0
 internal int ComputePromptLines(DisplayCells displayCells, int cols)
 {
     this.actualPrompt = StringManipulationHelper.GenerateLines(displayCells, this.promptString, cols, cols);
     return(this.actualPrompt.Count);
 }