public void WrapEditableCharacters_DoubleWidthCharacters_UsesStringWidth() { var text = "每个人都有他的作战策略,直到脸上中了一拳。"; var wrapped = WordWrapping.WrapEditableCharacters(new StringBuilder(text), caret: 13, width: 20); Assert.Equal( new[] { new WrappedLine(0, "每个人都有他的作战策"), new WrappedLine(10, "略,直到脸上中了一拳"), new WrappedLine(20, "。"), }, wrapped.WrappedLines ); Assert.Equal(new ConsoleCoordinate(1, 3), wrapped.Cursor); }
public void WrapEditableCharacters_DoubleWidthCharactersWithWrappingInMiddleOfCharacter_WrapsCharacter() { var text = "每个人都有他的作战策略, 直到脸上中了一拳。"; var wrapped = WordWrapping.WrapEditableCharacters(new StringBuilder(text), caret: 19, width: 19); Assert.Equal( new[] { new WrappedLine(0, "每个人都有他的作战"), // case 1: we should wrap early, because the next character is a full-width (2-wide) character. new WrappedLine(9, "策略, 直到脸上中了"), // case 2: single width space ("normal" space) sets us to align to width 19 exactly. new WrappedLine(19, "一拳。") }, wrapped.WrappedLines ); Assert.Equal(new ConsoleCoordinate(2, 0), wrapped.Cursor); }
public void WrapEditableCharacters_GivenLongText_WrapsCharacters() { var text = "Here is some text that should be wrapped character by character"; var wrapped = WordWrapping.WrapEditableCharacters(new StringBuilder(text), text.Length - 5, 20); Assert.Equal( new[] { new WrappedLine(0, "Here is some text th"), new WrappedLine(20, "at should be wrapped"), new WrappedLine(40, " character by charac"), new WrappedLine(60, "ter"), }, wrapped.WrappedLines ); Assert.Equal(new ConsoleCoordinate(2, 18), wrapped.Cursor); }
/// <summary> /// This is just an extra function used by <see cref="Prompt.RenderAnsiOutput"/> that highlights arbitrary text. It's /// not used for drawing input during normal functioning of the prompt. /// </summary> public static Row[] ApplyColorToCharacters(IReadOnlyCollection <FormatSpan> highlights, string text, int textWidth) { var wrapped = WordWrapping.WrapEditableCharacters(new StringBuilder(text), 0, textWidth); return(ApplyColorToCharacters(highlights, wrapped.WrappedLines, selection: null, selectedTextBackground: null)); }