Skip to content

Commit 15b0c0f

Browse files
committed
Update test foreground color to White
1 parent 9c1f75d commit 15b0c0f

4 files changed

Lines changed: 86 additions & 7 deletions

File tree

appveyor.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ cache:
1111

1212
install:
1313
- pwsh: |
14+
dotnet nuget remove source PowerShell_PublicPackages
15+
dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
1416
Write-Host "PS Version: $($PSVersionTable.PSVersion)"
1517
./build.ps1 -Bootstrap
1618
@@ -19,7 +21,7 @@ build_script:
1921
./build.ps1 -Configuration Release
2022
2123
test_script:
22-
- pwsh: ./build.ps1 -Test -Configuration Release -Framework net472
24+
- pwsh: ./build.ps1 -Test -Configuration Release
2325

2426
artifacts:
2527
- path: .\bin\Release\PSReadLine.zip

test/InlinePredictionTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public void Inline_HistoryAndPluginSource_Acceptance()
638638
Assert.Equal(Guid.Empty, _mockedMethods.acceptedPredictorId);
639639
Assert.Null(_mockedMethods.acceptedSuggestion);
640640
Assert.NotNull(_mockedMethods.commandHistory);
641-
Assert.Equal(1, _mockedMethods.commandHistory.Count);
641+
Assert.Single(_mockedMethods.commandHistory);
642642
Assert.Equal("netsh show me", _mockedMethods.commandHistory[0]);
643643

644644
_mockedMethods.ClearPredictionFields();
@@ -839,5 +839,15 @@ public void Inline_TruncateVeryLongSuggestion()
839839
TokenClassification.Command, "vv"))
840840
));
841841
}
842+
843+
// Example: How to validate 256-color emission for predictions
844+
// When PSReadLine emits ANSI escape codes like \x1b[38;5;238m (256-color),
845+
// the test console now tracks them in Emitted256Colors list.
846+
//
847+
// Usage in tests:
848+
// CheckThat(() => {
849+
// // Verify PSReadLine emitted color 238 for prediction text
850+
// Assert.Contains(_console.Emitted256Colors, c => c.ColorIndex == 238);
851+
// })
842852
}
843853
}

test/MockConsole.cs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ public virtual int WindowHeight
178178

179179
public virtual int WindowTop { get; set; }
180180

181+
// Track 256-color/RGB escape sequences emitted by PSReadLine
182+
public List<(int Position, bool IsForeground, int ColorIndex)> Emitted256Colors { get; } = new();
183+
181184
public virtual ConsoleColor BackgroundColor
182185
{
183186
get => _backgroundColor;
@@ -233,16 +236,48 @@ public virtual void Write(string s)
233236
var endSequence = s.IndexOfAny(endEscapeChars, i);
234237
var len = endSequence - i - (s[endSequence] != 'm' ? 1 : 2);
235238
var escapeSequence = s.Substring(i + 2, len);
236-
foreach (var subsequence in escapeSequence.Split(';'))
239+
var parts = escapeSequence.Split(';');
240+
241+
for (int j = 0; j < parts.Length; j++)
237242
{
243+
var subsequence = parts[j];
244+
238245
if (subsequence is "1" or "2" or "3")
239246
{
240247
// Ignore the font effect sequence: 1 - bold; 2 - dimmed color; 3 - italics
241248
// They are used in the metadata line of the list view.
242249
continue;
243250
}
244251

245-
EscapeSequenceActions[subsequence](this);
252+
// Handle 256-color/RGB sequences: 38 (FG) or 48 (BG)
253+
// PSReadLine uses \x1b[38;5;238m and \x1b[48;5;238m for predictions
254+
// Track these sequences without changing color state
255+
if (subsequence is "38" or "48")
256+
{
257+
bool isForeground = subsequence == "38";
258+
if (j + 2 < parts.Length)
259+
{
260+
var mode = parts[j + 1];
261+
if (mode == "5")
262+
{
263+
if (int.TryParse(parts[j + 2], out var colorIndex))
264+
{
265+
Emitted256Colors.Add((writePos, isForeground, colorIndex));
266+
}
267+
j += 2; // Skip mode and color index
268+
}
269+
else if (mode == "2" && j + 4 < parts.Length)
270+
{
271+
j += 4; // Skip mode and RGB values (r, g, b)
272+
}
273+
}
274+
continue;
275+
}
276+
277+
if (EscapeSequenceActions.ContainsKey(subsequence))
278+
{
279+
EscapeSequenceActions[subsequence](this);
280+
}
246281
}
247282
i = endSequence;
248283
continue;
@@ -462,16 +497,48 @@ public override void Write(string s)
462497
var endSequence = s.IndexOfAny(endEscapeChars, i);
463498
var len = endSequence - i - (s[endSequence] != 'm' ? 1 : 2);
464499
var escapeSequence = s.Substring(i + 2, len);
465-
foreach (var subsequence in escapeSequence.Split(';'))
500+
var parts = escapeSequence.Split(';');
501+
502+
for (int j = 0; j < parts.Length; j++)
466503
{
504+
var subsequence = parts[j];
505+
467506
if (subsequence is "1" or "2" or "3")
468507
{
469508
// Ignore the font effect sequence: 1 - bold; 2 - dimmed color; 3 - italics
470509
// They are used in the metadata line of the list view.
471510
continue;
472511
}
473512

474-
EscapeSequenceActions[subsequence](this);
513+
// Handle 256-color/RGB sequences: 38 (FG) or 48 (BG)
514+
// PSReadLine uses \x1b[38;5;238m and \x1b[48;5;238m for predictions
515+
// Track these sequences without changing color state
516+
if (subsequence is "38" or "48")
517+
{
518+
bool isForeground = subsequence == "38";
519+
if (j + 2 < parts.Length)
520+
{
521+
var mode = parts[j + 1];
522+
if (mode == "5")
523+
{
524+
if (int.TryParse(parts[j + 2], out var colorIndex))
525+
{
526+
Emitted256Colors.Add((writePos, isForeground, colorIndex));
527+
}
528+
j += 2; // Skip mode and color index
529+
}
530+
else if (mode == "2" && j + 4 < parts.Length)
531+
{
532+
j += 4; // Skip mode and RGB values (r, g, b)
533+
}
534+
}
535+
continue;
536+
}
537+
538+
if (EscapeSequenceActions.ContainsKey(subsequence))
539+
{
540+
EscapeSequenceActions[subsequence](this);
541+
}
475542
}
476543
i = endSequence;
477544
continue;

test/UnitTestReadLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private enum KeyMode
153153
// so the tests aren't sensitive to tweaks to the default colors.
154154
internal static readonly ConsoleColor[] Colors = new []
155155
{
156-
/*None*/ ConsoleColor.DarkRed,
156+
/*None*/ ConsoleColor.White,
157157
/*Comment*/ ConsoleColor.Blue,
158158
/*Keyword*/ ConsoleColor.Cyan,
159159
/*String*/ ConsoleColor.Gray,

0 commit comments

Comments
 (0)