|
@@ -2,14 +2,14 @@
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
-using Terminal.Gui.Views;
|
|
|
|
|
|
+using Terminal.Gui;
|
|
using Xunit;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
// Alias Console to MockConsole so we don't accidentally use Console
|
|
// Alias Console to MockConsole so we don't accidentally use Console
|
|
using Console = Terminal.Gui.FakeConsole;
|
|
using Console = Terminal.Gui.FakeConsole;
|
|
|
|
|
|
-namespace Terminal.Gui.Core {
|
|
|
|
|
|
+namespace Terminal.Gui.TextTests {
|
|
public class TextFormatterTests {
|
|
public class TextFormatterTests {
|
|
readonly ITestOutputHelper output;
|
|
readonly ITestOutputHelper output;
|
|
|
|
|
|
@@ -394,7 +394,7 @@ namespace Terminal.Gui.Core {
|
|
bool supportFirstUpperCase = true;
|
|
bool supportFirstUpperCase = true;
|
|
|
|
|
|
var text = ustring.Empty;
|
|
var text = ustring.Empty;
|
|
- Rune hotKeySpecifier = (Rune)0;
|
|
|
|
|
|
+ var hotKeySpecifier = (Rune)0;
|
|
int hotPos = 0;
|
|
int hotPos = 0;
|
|
Key hotKey = Key.Unknown;
|
|
Key hotKey = Key.Unknown;
|
|
bool result = false;
|
|
bool result = false;
|
|
@@ -437,7 +437,7 @@ namespace Terminal.Gui.Core {
|
|
bool supportFirstUpperCase = true;
|
|
bool supportFirstUpperCase = true;
|
|
|
|
|
|
var text = ustring.Empty;
|
|
var text = ustring.Empty;
|
|
- Rune hotKeySpecifier = (Rune)0;
|
|
|
|
|
|
+ var hotKeySpecifier = (Rune)0;
|
|
int hotPos = 0;
|
|
int hotPos = 0;
|
|
Key hotKey = Key.Unknown;
|
|
Key hotKey = Key.Unknown;
|
|
bool result = false;
|
|
bool result = false;
|
|
@@ -2162,9 +2162,7 @@ namespace Terminal.Gui.Core {
|
|
var height = 8;
|
|
var height = 8;
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var breakLines = "";
|
|
var breakLines = "";
|
|
- foreach (var line in wrappedLines) {
|
|
|
|
- breakLines += $"{line}{Environment.NewLine}";
|
|
|
|
- }
|
|
|
|
|
|
+ foreach (var line in wrappedLines) breakLines += $"{line}{Environment.NewLine}";
|
|
var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
|
|
|
|
@@ -2202,9 +2200,7 @@ namespace Terminal.Gui.Core {
|
|
var height = 3;
|
|
var height = 3;
|
|
var wrappedLines = TextFormatter.WordWrap (text, height, true);
|
|
var wrappedLines = TextFormatter.WordWrap (text, height, true);
|
|
var breakLines = "";
|
|
var breakLines = "";
|
|
- for (int i = 0; i < wrappedLines.Count; i++) {
|
|
|
|
- breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < wrappedLines.Count; i++) breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
|
|
var label = new Label (breakLines) {
|
|
var label = new Label (breakLines) {
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
Width = Dim.Fill (),
|
|
Width = Dim.Fill (),
|
|
@@ -2241,9 +2237,7 @@ namespace Terminal.Gui.Core {
|
|
var height = 8;
|
|
var height = 8;
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var breakLines = "";
|
|
var breakLines = "";
|
|
- foreach (var line in wrappedLines) {
|
|
|
|
- breakLines += $"{line}{Environment.NewLine}";
|
|
|
|
- }
|
|
|
|
|
|
+ foreach (var line in wrappedLines) breakLines += $"{line}{Environment.NewLine}";
|
|
var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
|
|
|
|
@@ -2282,9 +2276,7 @@ namespace Terminal.Gui.Core {
|
|
var height = 4;
|
|
var height = 4;
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var wrappedLines = TextFormatter.WordWrap (text, width, true);
|
|
var breakLines = "";
|
|
var breakLines = "";
|
|
- for (int i = 0; i < wrappedLines.Count; i++) {
|
|
|
|
- breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < wrappedLines.Count; i++) breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
|
|
var label = new Label (breakLines) {
|
|
var label = new Label (breakLines) {
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
Width = Dim.Fill (),
|
|
Width = Dim.Fill (),
|
|
@@ -2433,13 +2425,13 @@ namespace Terminal.Gui.Core {
|
|
Assert.Equal (ustring.Make (new Rune [] { 't', tag, 's', 't' }), tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
Assert.Equal (ustring.Make (new Rune [] { 't', tag, 's', 't' }), tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
|
|
|
|
var result = tf.ReplaceHotKeyWithTag (text, hotPos);
|
|
var result = tf.ReplaceHotKeyWithTag (text, hotPos);
|
|
- Assert.Equal ('e', (uint)(result.ToRunes () [1]));
|
|
|
|
|
|
+ Assert.Equal ('e', result.ToRunes () [1]);
|
|
|
|
|
|
text = "Ok";
|
|
text = "Ok";
|
|
tag = 'O';
|
|
tag = 'O';
|
|
hotPos = 0;
|
|
hotPos = 0;
|
|
Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
- Assert.Equal ('O', (uint)(result.ToRunes () [0]));
|
|
|
|
|
|
+ Assert.Equal ('O', result.ToRunes () [0]);
|
|
|
|
|
|
text = "[◦ Ok ◦]";
|
|
text = "[◦ Ok ◦]";
|
|
text = ustring.Make (new Rune [] { '[', '◦', ' ', 'O', 'k', ' ', '◦', ']' });
|
|
text = ustring.Make (new Rune [] { '[', '◦', ' ', 'O', 'k', ' ', '◦', ']' });
|
|
@@ -2449,13 +2441,13 @@ namespace Terminal.Gui.Core {
|
|
tag = 'O';
|
|
tag = 'O';
|
|
hotPos = 3;
|
|
hotPos = 3;
|
|
Assert.Equal (ustring.Make (new Rune [] { '[', '◦', ' ', tag, 'k', ' ', '◦', ']' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
Assert.Equal (ustring.Make (new Rune [] { '[', '◦', ' ', tag, 'k', ' ', '◦', ']' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
- Assert.Equal ('O', (uint)(result.ToRunes () [3]));
|
|
|
|
|
|
+ Assert.Equal ('O', result.ToRunes () [3]);
|
|
|
|
|
|
text = "^k";
|
|
text = "^k";
|
|
tag = '^';
|
|
tag = '^';
|
|
hotPos = 0;
|
|
hotPos = 0;
|
|
Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
|
|
- Assert.Equal ('^', (uint)(result.ToRunes () [0]));
|
|
|
|
|
|
+ Assert.Equal ('^', result.ToRunes () [0]);
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -2814,37 +2806,37 @@ namespace Terminal.Gui.Core {
|
|
[Fact]
|
|
[Fact]
|
|
public void System_Rune_ColumnWidth ()
|
|
public void System_Rune_ColumnWidth ()
|
|
{
|
|
{
|
|
- var c = new System.Rune ('a');
|
|
|
|
|
|
+ var c = new Rune ('a');
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune ('b');
|
|
|
|
|
|
+ c = new Rune ('b');
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune (123);
|
|
|
|
|
|
+ c = new Rune (123);
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, Rune.ColumnWidth (c));
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune ('\u1150');
|
|
|
|
|
|
+ c = new Rune ('\u1150');
|
|
Assert.Equal (2, Rune.ColumnWidth (c)); // 0x1150 ᅐ Unicode Technical Report #11
|
|
Assert.Equal (2, Rune.ColumnWidth (c)); // 0x1150 ᅐ Unicode Technical Report #11
|
|
Assert.Equal (2, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (2, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (3, ustring.Make (c).Length);
|
|
Assert.Equal (3, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune ('\u1161');
|
|
|
|
|
|
+ c = new Rune ('\u1161');
|
|
Assert.Equal (0, Rune.ColumnWidth (c)); // 0x1161 ᅡ column width of 0
|
|
Assert.Equal (0, Rune.ColumnWidth (c)); // 0x1161 ᅡ column width of 0
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (3, ustring.Make (c).Length);
|
|
Assert.Equal (3, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune (31);
|
|
|
|
|
|
+ c = new Rune (31);
|
|
Assert.Equal (-1, Rune.ColumnWidth (c)); // non printable character
|
|
Assert.Equal (-1, Rune.ColumnWidth (c)); // non printable character
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);// ConsoleWidth only returns zero or greater than zero
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);// ConsoleWidth only returns zero or greater than zero
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
|
|
|
|
- c = new System.Rune (127);
|
|
|
|
|
|
+ c = new Rune (127);
|
|
Assert.Equal (-1, Rune.ColumnWidth (c)); // non printable character
|
|
Assert.Equal (-1, Rune.ColumnWidth (c)); // non printable character
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
Assert.Equal (1, ustring.Make (c).Length);
|
|
@@ -2896,9 +2888,7 @@ namespace Terminal.Gui.Core {
|
|
Assert.Equal ("nd", list1 [10].ToString ());
|
|
Assert.Equal ("nd", list1 [10].ToString ());
|
|
Assert.Equal ("Line", list1 [11].ToString ());
|
|
Assert.Equal ("Line", list1 [11].ToString ());
|
|
Assert.Equal ("- 2.", list1 [^1].ToString ());
|
|
Assert.Equal ("- 2.", list1 [^1].ToString ());
|
|
- foreach (var txt in list1) {
|
|
|
|
- wrappedText1 += txt;
|
|
|
|
- }
|
|
|
|
|
|
+ foreach (var txt in list1) wrappedText1 += txt;
|
|
Assert.Equal (" Asentencehaswords. This isthesecondLine- 2.", wrappedText1);
|
|
Assert.Equal (" Asentencehaswords. This isthesecondLine- 2.", wrappedText1);
|
|
|
|
|
|
// With preserveTrailingSpaces = true.
|
|
// With preserveTrailingSpaces = true.
|
|
@@ -2920,9 +2910,7 @@ namespace Terminal.Gui.Core {
|
|
Assert.Equal ("Line", list2 [13].ToString ());
|
|
Assert.Equal ("Line", list2 [13].ToString ());
|
|
Assert.Equal (" - ", list2 [14].ToString ());
|
|
Assert.Equal (" - ", list2 [14].ToString ());
|
|
Assert.Equal ("2. ", list2 [^1].ToString ());
|
|
Assert.Equal ("2. ", list2 [^1].ToString ());
|
|
- foreach (var txt in list2) {
|
|
|
|
- wrappedText2 += txt;
|
|
|
|
- }
|
|
|
|
|
|
+ foreach (var txt in list2) wrappedText2 += txt;
|
|
Assert.Equal (" A sentence has words. This is the second Line - 2. ", wrappedText2);
|
|
Assert.Equal (" A sentence has words. This is the second Line - 2. ", wrappedText2);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -3430,7 +3418,7 @@ This TextFormatter (tf2) is rewritten.
|
|
[Fact]
|
|
[Fact]
|
|
public void GetSumMaxCharWidth_List_Simple_And_Wide_Runes ()
|
|
public void GetSumMaxCharWidth_List_Simple_And_Wide_Runes ()
|
|
{
|
|
{
|
|
- List<ustring> text = new List<ustring> () { "Hello", "World" };
|
|
|
|
|
|
+ var text = new List<ustring> () { "Hello", "World" };
|
|
Assert.Equal (2, TextFormatter.GetSumMaxCharWidth (text));
|
|
Assert.Equal (2, TextFormatter.GetSumMaxCharWidth (text));
|
|
Assert.Equal (1, TextFormatter.GetSumMaxCharWidth (text, 1, 1));
|
|
Assert.Equal (1, TextFormatter.GetSumMaxCharWidth (text, 1, 1));
|
|
text = new List<ustring> () { "こんにちは", "世界" };
|
|
text = new List<ustring> () { "こんにちは", "世界" };
|
|
@@ -4259,5 +4247,46 @@ This TextFormatter (tf2) is rewritten.
|
|
0111000000
|
|
0111000000
|
|
0000000000", expectedColors);
|
|
0000000000", expectedColors);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
|
+ public void Colors_On_TextAlignment_Right_And_Bottom ()
|
|
|
|
+ {
|
|
|
|
+ var labelRight = new Label ("Test") {
|
|
|
|
+ Width = 6,
|
|
|
|
+ Height = 1,
|
|
|
|
+ TextAlignment = TextAlignment.Right,
|
|
|
|
+ ColorScheme = Colors.Base
|
|
|
|
+ };
|
|
|
|
+ var labelBottom = new Label ("Test", TextDirection.TopBottom_LeftRight) {
|
|
|
|
+ Y = 1,
|
|
|
|
+ Width = 1,
|
|
|
|
+ Height = 6,
|
|
|
|
+ VerticalTextAlignment = VerticalTextAlignment.Bottom,
|
|
|
|
+ ColorScheme = Colors.Base
|
|
|
|
+ };
|
|
|
|
+ var top = Application.Top;
|
|
|
|
+ top.Add (labelRight, labelBottom);
|
|
|
|
+
|
|
|
|
+ Application.Begin (top);
|
|
|
|
+ ((FakeDriver)Application.Driver).SetBufferSize (7, 7);
|
|
|
|
+
|
|
|
|
+ TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
|
|
+ Test
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+T
|
|
|
|
+e
|
|
|
|
+s
|
|
|
|
+t ", output);
|
|
|
|
+
|
|
|
|
+ TestHelpers.AssertDriverColorsAre (@"
|
|
|
|
+000000
|
|
|
|
+0
|
|
|
|
+0
|
|
|
|
+0
|
|
|
|
+0
|
|
|
|
+0
|
|
|
|
+0", new Attribute [] { Colors.Base.Normal });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|