示例#1
0
        private List <ConsoleString> FormatAsWrappedSegments(SmartWrapOverflowBehavior smartWrap, ConsoleString value)
        {
            List <ConsoleString> ret = new List <ConsoleString>();

            while (value.Length > smartWrap.MaxWidthBeforeWrapping)
            {
                var segment = value.Substring(0, smartWrap.MaxWidthBeforeWrapping);

                int lookBehindLimit = smartWrap.WordBreakLookBehind;
                for (int i = segment.Length - 1; i >= 0 && lookBehindLimit > 0; i--)
                {
                    if (char.IsWhiteSpace(segment[i].Value))
                    {
                        if (i != 0)
                        {
                            segment = value.Substring(0, i);
                        }
                        else
                        {
                            segment = value.Substring(0, smartWrap.MaxWidthBeforeWrapping + 1);
                        }
                        break;
                    }
                    lookBehindLimit--;
                }

                ret.Add(segment);
                value = value.Substring(segment.Length);
            }

            if (value.Length > 0 || ret.Count == 0)
            {
                ret.Add(value);
            }

            for (int i = 0; i < ret.Count; i++)
            {
                if (ret[i].ToString().Length > 0 && char.IsWhiteSpace(ret[i].ToString()[0]))
                {
                    ret[i] = ret[i].Substring(1);
                }
            }

            return(ret);
        }
示例#2
0
        private ConsoleString TruncateIfNeeded(TruncateOverflowBehavior truncateBehavior, ConsoleString value)
        {
            if (value.Length > truncateBehavior.MaxWidthBeforeShowingTruncationText)
            {
                value = value.Substring(0, truncateBehavior.MaxWidthBeforeShowingTruncationText) + truncateBehavior.TruncationText;
            }

            return(value);
        }
示例#3
0
        /// <summary>
        /// Asks the user if they are sure about performing some operation and returns true if they indicate yes and
        /// false if they indicate no.
        /// </summary>
        /// <param name="about">The message to display.  'Are you sure?' will be apended.</param>
        /// <returns>true if they indicate yes and false if they indicate no.</returns>
        public bool IsUserSure(ConsoleString about)
        {
            if (about.EndsWith("."))
            {
                about = about.Substring(0, about.Length - 1);
            }

            var response = Prompt(about + ".  Are you sure?", "y", "n");

            if (response.Equals("y", StringComparison.InvariantCultureIgnoreCase) == true)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public void Wipe()
        {
            using (Console.TakeSnapshot())
            {
                Console.CursorLeft = Left;
                Console.CursorTop  = Top;
                int linesToClear = (Bottom - Top) + 1;

                for (int i = 0; i < linesToClear; i++)
                {
                    if (i == 0 && Left > 0)
                    {
                        var partialLine = clearedLine.Substring(0, clearedLine.Length - Left);
                        Console.Write(partialLine);
                    }
                    else
                    {
                        Console.Write(clearedLine);
                    }
                }
            }
        }
        private void RedrawSearchResults()
        {
            using (var snapshot = this.console.TakeSnapshot())
            {
                resultsWiper.Wipe();
                resultsWiper.SetBottomToTop();
                menuWiper.Bottom = resultsWiper.Bottom;

                this.console.CursorTop  = resultsWiper.Top;
                this.console.CursorLeft = 0;


                for (int i = 0; i < latestResults.Count; i++)
                {
                    ConsoleString searchResult = latestResults[i].RichDisplayText;

                    if (i == selectedIndex)
                    {
                        searchResult = searchResult.HighlightSubstring(0, searchResult.Length, ConsoleColor.Yellow, null);
                    }

                    if (searchResult.Length > this.console.BufferWidth - 1)
                    {
                        searchResult = searchResult.Substring(0, this.console.BufferWidth - 4) + "...";
                    }

                    if (latestResultsSearchString.Length > 0)
                    {
                        searchResult = searchResult.Highlight(latestResultsSearchString, ConsoleColor.Black, ConsoleColor.Yellow, StringComparison.InvariantCultureIgnoreCase);
                    }

                    this.console.WriteLine(searchResult);
                    resultsWiper.IncrementBottom();
                    menuWiper.IncrementBottom();
                }
            }
        }