Skip to content

Commit e4703ab

Browse files
EvangelinkCopilot
andauthored
Recognize foot and WezTerm as ANSI terminals in MTP (#12587)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e28fba2 commit e4703ab

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎eng/vendored-files.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@
282282
{
283283
"id": "platform-terminal-ansi-detector",
284284
"local_path": "src/MTP/Microsoft.Testing.Platform/OutputDevice/Terminal/AnsiDetector.cs",
285-
"notes": "Ported from Spectre.Console's AnsiDetector (with additional regexes from supports-ansi).",
285+
"notes": "Ported from Spectre.Console's AnsiDetector (with additional matching rules from supports-ansi). Uses allocation-free ordinal string matching and retains the eterm-color exclusion. IsAnsiSupported already provides the testable terminal predicate extracted upstream as IsAnsiTerminal.",
286286
"sources": [
287287
{
288288
"repo": "spectreconsole/spectre.console",
289289
"ref": "main",
290290
"path": "src/Spectre.Console.Ansi/AnsiDetector.cs",
291-
"baseline_ref_sha": "bbf51e4c2841dae4d574193a7a5695499d453f60",
292-
"baseline_blob_sha": "a31831944cb05dac9b48942fe7cb14dac89444d8",
291+
"baseline_ref_sha": "04b5dac6398dce0838c48cc3a3b6d1cc8a7f1747",
292+
"baseline_blob_sha": "3cfb811c22434230f62b9ee11c4f25b7b49f449c",
293293
"scope": "terminal regex list and ANSI capability detection logic"
294294
}
295295
]

‎src/MTP/Microsoft.Testing.Platform/OutputDevice/Terminal/AnsiDetector.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
// Portions of the code in this file were ported from the spectre.console by Patrik Svensson, Phil Scott, Nils Andresen
5-
// https://github.com/spectreconsole/spectre.console/blob/main/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs
5+
// https://github.com/spectreconsole/spectre.console/blob/04b5dac6398dce0838c48cc3a3b6d1cc8a7f1747/src/Spectre.Console.Ansi/AnsiDetector.cs
66
// and from the supports-ansi project by Qingrong Ke
77
// https://github.com/keqingrong/supports-ansi/blob/master/index.js
88
using Microsoft.CodeAnalysis;
@@ -23,7 +23,7 @@ public static bool IsAnsiSupported(string? termType)
2323
}
2424

2525
// Each condition mirrors the original regex pattern but uses plain string operations,
26-
// eliminating the 17 Regex allocations and their compilation cost.
26+
// eliminating Regex allocations and their compilation cost.
2727
return termType.StartsWith("xterm", StringComparison.Ordinal) // ^xterm — xterm, PuTTY, Mintty
2828
|| termType.StartsWith("rxvt", StringComparison.Ordinal) // ^rxvt — RXVT
2929
|| (termType.IndexOf("eterm", StringComparison.Ordinal) >= 0 // ^(?!eterm-color).*eterm.* — eterm but not eterm-color (#9950)
@@ -41,6 +41,8 @@ public static bool IsAnsiSupported(string? termType)
4141
|| termType.IndexOf("konsole", StringComparison.Ordinal) >= 0 // konsole — Konsole
4242
|| termType.IndexOf("bvterm", StringComparison.Ordinal) >= 0 // bvterm — Bitvise SSH Client
4343
|| termType.StartsWith("st-256color", StringComparison.Ordinal) // ^st-256color — Suckless Simple Terminal, st
44-
|| termType.IndexOf("alacritty", StringComparison.Ordinal) >= 0; // alacritty — Alacritty
44+
|| termType.IndexOf("alacritty", StringComparison.Ordinal) >= 0 // alacritty — Alacritty
45+
|| termType.StartsWith("foot", StringComparison.Ordinal) // ^foot — foot
46+
|| termType.StartsWith("wezterm", StringComparison.Ordinal); // ^wezterm — WezTerm
4547
}
4648
}

‎test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/AnsiDetectorTests.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public sealed class AnsiDetectorTests
3434
[DataRow("custom-bvterm-terminal", true)]
3535
[DataRow("st-256color", true)]
3636
[DataRow("custom-alacritty-terminal", true)]
37+
[DataRow("foot", true)]
38+
[DataRow("foot-direct", true)]
39+
[DataRow("foot-256color", true)]
40+
[DataRow("wezterm", true)]
41+
[DataRow("wezterm-256color", true)]
3742
[DataRow("custom-xterm", false)]
3843
[DataRow("custom-rxvt", false)]
3944
[DataRow("custom-screen", false)]
@@ -42,7 +47,11 @@ public sealed class AnsiDetectorTests
4247
[DataRow("custom-vt220", false)]
4348
[DataRow("custom-vt320", false)]
4449
[DataRow("custom-st-256color", false)]
50+
[DataRow("custom-foot", false)]
51+
[DataRow("custom-wezterm", false)]
4552
[DataRow("XTERM", false)]
53+
[DataRow("FOOT", false)]
54+
[DataRow("WEZTERM", false)]
4655
[DataRow("custom-ANSI-terminal", false)]
4756
[DataRow("\0xterm", false, DisplayName = "Nul before an anchored prefix")]
4857
public void IsAnsiSupported_TerminalFamilyAndPosition_MatchesContract(string? terminal, bool expected)

0 commit comments

Comments
 (0)