diff --git a/CliFx/Extensions.cs b/CliFx/Extensions.cs deleted file mode 100644 index 2789af3..0000000 --- a/CliFx/Extensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -namespace CliFx -{ - /// - /// Extensions for - /// - public static class Extensions - { - /// - /// Sets console foreground color, executes specified action, and sets the color back to the original value. - /// - public static void WithForegroundColor(this IConsole console, ConsoleColor foregroundColor, Action action) - { - var lastColor = console.ForegroundColor; - console.ForegroundColor = foregroundColor; - - action(); - - console.ForegroundColor = lastColor; - } - - /// - /// Sets console background color, executes specified action, and sets the color back to the original value. - /// - public static void WithBackgroundColor(this IConsole console, ConsoleColor backgroundColor, Action action) - { - var lastColor = console.BackgroundColor; - console.BackgroundColor = backgroundColor; - - action(); - - console.BackgroundColor = lastColor; - } - - /// - /// Sets console foreground and background colors, executes specified action, and sets the colors back to the original values. - /// - public static void WithColors(this IConsole console, ConsoleColor foregroundColor, ConsoleColor backgroundColor, Action action) => - console.WithForegroundColor(foregroundColor, () => console.WithBackgroundColor(backgroundColor, action)); - } -} \ No newline at end of file diff --git a/CliFx/IConsole.cs b/CliFx/IConsole.cs index 42730ea..9f801a2 100644 --- a/CliFx/IConsole.cs +++ b/CliFx/IConsole.cs @@ -71,4 +71,42 @@ namespace CliFx /// CancellationToken GetCancellationToken(); } + + /// + /// Extensions for . + /// + public static class ConsoleExtensions + { + /// + /// Sets console foreground color, executes specified action, and sets the color back to the original value. + /// + public static void WithForegroundColor(this IConsole console, ConsoleColor foregroundColor, Action action) + { + var lastColor = console.ForegroundColor; + console.ForegroundColor = foregroundColor; + + action(); + + console.ForegroundColor = lastColor; + } + + /// + /// Sets console background color, executes specified action, and sets the color back to the original value. + /// + public static void WithBackgroundColor(this IConsole console, ConsoleColor backgroundColor, Action action) + { + var lastColor = console.BackgroundColor; + console.BackgroundColor = backgroundColor; + + action(); + + console.BackgroundColor = lastColor; + } + + /// + /// Sets console foreground and background colors, executes specified action, and sets the colors back to the original values. + /// + public static void WithColors(this IConsole console, ConsoleColor foregroundColor, ConsoleColor backgroundColor, Action action) => + console.WithForegroundColor(foregroundColor, () => console.WithBackgroundColor(backgroundColor, action)); + } } \ No newline at end of file diff --git a/CliFx/Utilities/Extensions.cs b/CliFx/Utilities/Extensions.cs deleted file mode 100644 index 69e21d5..0000000 --- a/CliFx/Utilities/Extensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CliFx.Utilities -{ - /// - /// Extensions for . - /// - public static class Extensions - { - /// - /// Creates a bound to this console. - /// - public static ProgressTicker CreateProgressTicker(this IConsole console) => new ProgressTicker(console); - } -} \ No newline at end of file diff --git a/CliFx/Utilities/ProgressTicker.cs b/CliFx/Utilities/ProgressTicker.cs index 92e9dd1..da944f0 100644 --- a/CliFx/Utilities/ProgressTicker.cs +++ b/CliFx/Utilities/ProgressTicker.cs @@ -48,4 +48,15 @@ namespace CliFx.Utilities } } } + + /// + /// Extensions for . + /// + public static class ProgressTickerExtensions + { + /// + /// Creates a bound to this console. + /// + public static ProgressTicker CreateProgressTicker(this IConsole console) => new ProgressTicker(console); + } } \ No newline at end of file