Skip to content

Commit 0832bab

Browse files
authored
Merge branch 'v2_develop' into v2_3836_setupfakefriver-after-fix
2 parents 99866c8 + dbfe521 commit 0832bab

File tree

7 files changed

+122
-26
lines changed

7 files changed

+122
-26
lines changed

Terminal.Gui/Text/TextFormatter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ public static string ClipAndJustify (
14111411

14121412
if (textFormatter is { Alignment: Alignment.Center })
14131413
{
1414-
return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
1414+
return GetRangeThatFits (runes, Math.Max ((runes.Count - width - zeroLength) / 2, 0), text, width, tabWidth, textDirection);
14151415
}
14161416

14171417
return GetRangeThatFits (runes, 0, text, width, tabWidth, textDirection);
@@ -1426,7 +1426,7 @@ public static string ClipAndJustify (
14261426

14271427
if (textFormatter is { VerticalAlignment: Alignment.Center })
14281428
{
1429-
return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
1429+
return GetRangeThatFits (runes, Math.Max ((runes.Count - width - zeroLength) / 2, 0), text, width, tabWidth, textDirection);
14301430
}
14311431

14321432
return GetRangeThatFits (runes, 0, text, width, tabWidth, textDirection);
@@ -1451,7 +1451,7 @@ public static string ClipAndJustify (
14511451
}
14521452
else if (textFormatter is { Alignment: Alignment.Center })
14531453
{
1454-
return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
1454+
return GetRangeThatFits (runes, Math.Max ((runes.Count - width - zeroLength) / 2, 0), text, width, tabWidth, textDirection);
14551455
}
14561456
else if (GetRuneWidth (text, tabWidth, textDirection) > width)
14571457
{
@@ -1470,7 +1470,7 @@ public static string ClipAndJustify (
14701470
}
14711471
else if (textFormatter is { VerticalAlignment: Alignment.Center })
14721472
{
1473-
return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
1473+
return GetRangeThatFits (runes, Math.Max ((runes.Count - width - zeroLength) / 2, 0), text, width, tabWidth, textDirection);
14741474
}
14751475
else if (runes.Count - zeroLength > width)
14761476
{
@@ -1526,7 +1526,7 @@ public static string Justify (
15261526
}
15271527
else
15281528
{
1529-
textCount = words.Sum (arg => arg.GetRuneCount ());
1529+
textCount = words.Sum (arg => arg.GetRuneCount ()) - text.EnumerateRunes ().Sum (r => r.GetColumns () == 0 ? 1 : 0);
15301530
}
15311531

15321532
int spaces = words.Length > 1 ? (width - textCount) / (words.Length - 1) : 0;
@@ -1936,7 +1936,7 @@ private static int GetRuneWidth (List<Rune> runes, int tabWidth, TextDirection t
19361936

19371937
private static int GetRuneWidth (Rune rune, int tabWidth, TextDirection textDirection = TextDirection.LeftRight_TopBottom)
19381938
{
1939-
int runeWidth = IsHorizontalDirection (textDirection) ? rune.GetColumns () : 1;
1939+
int runeWidth = IsHorizontalDirection (textDirection) ? rune.GetColumns () : rune.GetColumns () == 0 ? 0 : 1;
19401940

19411941
if (rune.Value == '\t')
19421942
{

Terminal.Gui/View/View.Keyboard.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,11 @@ public bool IsHotKeyBound (Key key, out View? boundView)
690690

691691
#if DEBUG
692692

693-
if (Application.KeyBindings.TryGet (key, out KeyBinding b))
694-
{
695-
Debug.WriteLine (
696-
$"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
697-
}
693+
//if (Application.KeyBindings.TryGet (key, out KeyBinding b))
694+
//{
695+
// Debug.WriteLine (
696+
// $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
697+
//}
698698

699699
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
700700
// Scour the bindings up our View hierarchy

Terminal.Gui/View/View.Layout.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ public bool SetRelativeLayout (Size superviewContentSize)
561561
{
562562
SuperView?.SetNeedsDraw ();
563563
}
564-
else
564+
else if (Application.TopLevels.Count == 1)
565565
{
566+
// If this is the only TopLevel, we need to redraw the screen
566567
Application.ClearScreenNextIteration = true;
567568
}
568569
}
@@ -801,7 +802,7 @@ public void SetNeedsLayout ()
801802
{
802803
foreach (Toplevel tl in Application.TopLevels)
803804
{
804-
// tl.SetNeedsDraw ();
805+
// tl.SetNeedsDraw ();
805806
}
806807
}
807808

UICatalog/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"All Views Tester": {
4444
"commandName": "Project",
45-
"commandLineArgs": "\"All Views Tester\" -b"
45+
"commandLineArgs": "\"All Views Tester\" -b -t 5000"
4646
},
4747
"Charmap": {
4848
"commandName": "Project",

UICatalog/Scenario.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ public static ObservableCollection<Scenario> GetScenarios ()
148148
/// </summary>
149149
public virtual void Main () { }
150150

151-
private const uint MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
152-
private const uint ABORT_TIMEOUT_MS = 2500;
153-
private const int DEMO_KEY_PACING_MS = 1; // Must be non-zero
151+
private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
152+
private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero
153+
154+
public static uint BenchmarkTimeout { get; set; } = 2500;
154155

155156
private readonly object _timeoutLock = new ();
156157
private object? _timeout;
157158
private Stopwatch? _stopwatch;
158-
private readonly BenchmarkResults _benchmarkResults = new BenchmarkResults ();
159+
private readonly BenchmarkResults _benchmarkResults = new ();
159160

160161
public void StartBenchmark ()
161162
{
@@ -178,7 +179,7 @@ public BenchmarkResults EndBenchmark ()
178179
return _benchmarkResults;
179180
}
180181

181-
private List<Key> _demoKeys;
182+
private List<Key>? _demoKeys;
182183
private int _currentDemoKey = 0;
183184

184185
private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
@@ -187,7 +188,7 @@ private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
187188
{
188189
lock (_timeoutLock!)
189190
{
190-
_timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (ABORT_TIMEOUT_MS), ForceCloseCallback);
191+
_timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (BenchmarkTimeout), ForceCloseCallback);
191192
}
192193

193194
Application.Iteration += OnApplicationOnIteration;
@@ -218,7 +219,7 @@ private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
218219
private void OnApplicationOnIteration (object? s, IterationEventArgs a)
219220
{
220221
BenchmarkResults.IterationCount++;
221-
if (BenchmarkResults.IterationCount > MAX_NATURAL_ITERATIONS + (_demoKeys.Count* DEMO_KEY_PACING_MS))
222+
if (BenchmarkResults.IterationCount > BENCHMARK_MAX_NATURAL_ITERATIONS + (_demoKeys.Count * BENCHMARK_KEY_PACING))
222223
{
223224
Application.RequestStop ();
224225
}
@@ -232,7 +233,7 @@ private void OnApplicationNotifyNewRunState (object? sender, RunStateEventArgs e
232233
_demoKeys = GetDemoKeyStrokes ();
233234

234235
Application.AddTimeout (
235-
new TimeSpan (0, 0, 0, 0, DEMO_KEY_PACING_MS),
236+
new TimeSpan (0, 0, 0, 0, BENCHMARK_KEY_PACING),
236237
() =>
237238
{
238239
if (_currentDemoKey >= _demoKeys.Count)
@@ -271,7 +272,7 @@ private bool ForceCloseCallback ()
271272
}
272273
}
273274

274-
Debug.WriteLine ($@" Failed to Quit with {Application.QuitKey} after {ABORT_TIMEOUT_MS}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
275+
Debug.WriteLine ($@" Failed to Quit with {Application.QuitKey} after {BenchmarkTimeout}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
275276

276277
Application.RequestStop ();
277278

UICatalog/UICatalog.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ private static int Main (string [] args)
148148
benchmarkFlag.AddAlias ("-b");
149149
benchmarkFlag.AddAlias ("--b");
150150

151+
Option<uint> benchmarkTimeout = new Option<uint> ("--timeout", getDefaultValue: () => Scenario.BenchmarkTimeout, $"The maximum time in milliseconds to run a benchmark for. Default is {Scenario.BenchmarkTimeout}ms.");
152+
benchmarkTimeout.AddAlias ("-t");
153+
benchmarkTimeout.AddAlias ("--t");
154+
151155
Option<string> resultsFile = new Option<string> ("--file", "The file to save benchmark results to. If not specified, the results will be displayed in a TableView.");
152156
resultsFile.AddAlias ("-f");
153157
resultsFile.AddAlias ("--f");
@@ -165,7 +169,7 @@ private static int Main (string [] args)
165169

166170
var rootCommand = new RootCommand ("A comprehensive sample library for Terminal.Gui")
167171
{
168-
scenarioArgument, benchmarkFlag, resultsFile, driverOption,
172+
scenarioArgument, benchmarkFlag, benchmarkTimeout, resultsFile, driverOption,
169173
};
170174

171175
rootCommand.SetHandler (
@@ -176,6 +180,7 @@ private static int Main (string [] args)
176180
Scenario = context.ParseResult.GetValueForArgument (scenarioArgument),
177181
Driver = context.ParseResult.GetValueForOption (driverOption) ?? string.Empty,
178182
Benchmark = context.ParseResult.GetValueForOption (benchmarkFlag),
183+
BenchmarkTimeout = context.ParseResult.GetValueForOption (benchmarkTimeout),
179184
ResultsFile = context.ParseResult.GetValueForOption (resultsFile) ?? string.Empty,
180185
/* etc. */
181186
};
@@ -197,6 +202,8 @@ private static int Main (string [] args)
197202
return 0;
198203
}
199204

205+
Scenario.BenchmarkTimeout = _options.BenchmarkTimeout;
206+
200207
UICatalogMain (_options);
201208

202209
return 0;
@@ -332,6 +339,7 @@ private static void UICatalogMain (Options options)
332339
// regardless of what's in a config file.
333340
Application.ForceDriver = _forceDriver = options.Driver;
334341

342+
335343
// If a Scenario name has been provided on the commandline
336344
// run it and exit when done.
337345
if (options.Scenario != "none")
@@ -788,7 +796,7 @@ public UICatalogTopLevel ()
788796
{
789797
if (_statusBar.NeedsLayout)
790798
{
791-
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
799+
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
792800
}
793801
return _statusBar.Frame.Height;
794802
})),
@@ -817,7 +825,7 @@ public UICatalogTopLevel ()
817825
{
818826
if (_statusBar.NeedsLayout)
819827
{
820-
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
828+
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
821829
}
822830
return _statusBar.Frame.Height;
823831
})),
@@ -1378,6 +1386,8 @@ private struct Options
13781386

13791387
public string Scenario;
13801388

1389+
public uint BenchmarkTimeout;
1390+
13811391
public bool Benchmark;
13821392

13831393
public string ResultsFile;

UnitTests/Text/TextFormatterTests.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,90 @@ string expectedWrappedText
46294629
Assert.Equal (expectedWrappedText, wrappedText);
46304630
}
46314631

4632+
[Theory]
4633+
[InlineData (
4634+
"Les Mise\u0301rables",
4635+
14,
4636+
-1,
4637+
false,
4638+
new [] { "Les Misérables" },
4639+
"Les Misérables"
4640+
)]
4641+
[InlineData (
4642+
"Les Mise\u0328\u0301rables",
4643+
14,
4644+
-2,
4645+
false,
4646+
new [] { "Les Misę́rables" },
4647+
"Les Misę́rables"
4648+
)]
4649+
public void Format_Combining_Marks_Alignments (
4650+
string text,
4651+
int maxWidth,
4652+
int widthOffset,
4653+
bool wrap,
4654+
IEnumerable<string> resultLines,
4655+
string expectedText
4656+
)
4657+
{
4658+
Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
4659+
4660+
// Horizontal text direction
4661+
foreach (Alignment alignment in Enum.GetValues (typeof (Alignment)))
4662+
{
4663+
TextFormatter tf = new () { Text = text, ConstrainToSize = new (maxWidth, 1), WordWrap = wrap, Alignment = alignment };
4664+
4665+
List<string> list = TextFormatter.Format (
4666+
text,
4667+
maxWidth,
4668+
alignment,
4669+
wrap,
4670+
tf.PreserveTrailingSpaces,
4671+
tf.TabWidth,
4672+
tf.Direction,
4673+
tf.MultiLine,
4674+
tf);
4675+
Assert.Equal (list.Count, resultLines.Count ());
4676+
Assert.Equal (resultLines, list);
4677+
var formattedText = string.Empty;
4678+
4679+
foreach (string txt in list)
4680+
{
4681+
formattedText += txt;
4682+
}
4683+
4684+
Assert.Equal (expectedText, formattedText);
4685+
}
4686+
4687+
// Vertical text direction
4688+
foreach (Alignment alignment in Enum.GetValues (typeof (Alignment)))
4689+
{
4690+
TextFormatter tf = new ()
4691+
{ Text = text, ConstrainToSize = new (1, maxWidth), WordWrap = wrap, VerticalAlignment = alignment, Direction = TextDirection.TopBottom_LeftRight };
4692+
4693+
List<string> list = TextFormatter.Format (
4694+
text,
4695+
maxWidth,
4696+
alignment,
4697+
wrap,
4698+
tf.PreserveTrailingSpaces,
4699+
tf.TabWidth,
4700+
tf.Direction,
4701+
tf.MultiLine,
4702+
tf);
4703+
Assert.Equal (list.Count, resultLines.Count ());
4704+
Assert.Equal (resultLines, list);
4705+
var formattedText = string.Empty;
4706+
4707+
foreach (string txt in list)
4708+
{
4709+
formattedText += txt;
4710+
}
4711+
4712+
Assert.Equal (expectedText, formattedText);
4713+
}
4714+
}
4715+
46324716
public static IEnumerable<object []> FormatEnvironmentNewLine =>
46334717
new List<object []>
46344718
{

0 commit comments

Comments
 (0)