Skip to content

Add ConsoleExtensions: WithForegroundColor, WithBackgroundColor, WithColors#15

Merged
Tyrrrz merged 2 commits intoprimefrom
copilot/add-console-extensions-methods
Apr 12, 2026
Merged

Add ConsoleExtensions: WithForegroundColor, WithBackgroundColor, WithColors#15
Tyrrrz merged 2 commits intoprimefrom
copilot/add-console-extensions-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Ports the WithForegroundColor pattern from DotnetRuntimeBootstrapper and extends it with background and compound variants. Each method temporarily changes the console color(s) and returns an IDisposable that restores the previous value(s) on dispose.

  • WithForegroundColor(ConsoleColor) — scoped foreground color change
  • WithBackgroundColor(ConsoleColor) — scoped background color change
  • WithColors(ConsoleColor, ConsoleColor) — compound; merges both disposables so a single using restores both colors
using (Console.WithColors(ConsoleColor.White, ConsoleColor.Red))
{
    Console.WriteLine("Error: something went wrong");
}
// foreground and background both restored here

…and WithColors

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/e9fb58c9-3f63-4c99-a8ed-90ef4639d82c

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 12, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 12, 2026 19:40
Copilot AI review requested due to automatic review settings April 12, 2026 19:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds scoped console color helpers to PowerKit’s extensions set, enabling temporary foreground/background color changes via IDisposable handles that restore prior console state on disposal.

Changes:

  • Introduces Console.WithForegroundColor(ConsoleColor) for scoped foreground color changes.
  • Introduces Console.WithBackgroundColor(ConsoleColor) for scoped background color changes.
  • Introduces Console.WithColors(ConsoleColor, ConsoleColor) to apply both colors under a single scope.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/Extensions/ConsoleExtensions.cs
Comment thread PowerKit/Extensions/ConsoleExtensions.cs
Comment thread PowerKit/Extensions/ConsoleExtensions.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants