mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Move extensions closer to the actual classes
This commit is contained in:
@@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace CliFx
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extensions for <see cref="CliFx"/>
|
|
||||||
/// </summary>
|
|
||||||
public static class Extensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Sets console foreground color, executes specified action, and sets the color back to the original value.
|
|
||||||
/// </summary>
|
|
||||||
public static void WithForegroundColor(this IConsole console, ConsoleColor foregroundColor, Action action)
|
|
||||||
{
|
|
||||||
var lastColor = console.ForegroundColor;
|
|
||||||
console.ForegroundColor = foregroundColor;
|
|
||||||
|
|
||||||
action();
|
|
||||||
|
|
||||||
console.ForegroundColor = lastColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets console background color, executes specified action, and sets the color back to the original value.
|
|
||||||
/// </summary>
|
|
||||||
public static void WithBackgroundColor(this IConsole console, ConsoleColor backgroundColor, Action action)
|
|
||||||
{
|
|
||||||
var lastColor = console.BackgroundColor;
|
|
||||||
console.BackgroundColor = backgroundColor;
|
|
||||||
|
|
||||||
action();
|
|
||||||
|
|
||||||
console.BackgroundColor = lastColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets console foreground and background colors, executes specified action, and sets the colors back to the original values.
|
|
||||||
/// </summary>
|
|
||||||
public static void WithColors(this IConsole console, ConsoleColor foregroundColor, ConsoleColor backgroundColor, Action action) =>
|
|
||||||
console.WithForegroundColor(foregroundColor, () => console.WithBackgroundColor(backgroundColor, action));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -71,4 +71,42 @@ namespace CliFx
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
CancellationToken GetCancellationToken();
|
CancellationToken GetCancellationToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extensions for <see cref="IConsole"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ConsoleExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets console foreground color, executes specified action, and sets the color back to the original value.
|
||||||
|
/// </summary>
|
||||||
|
public static void WithForegroundColor(this IConsole console, ConsoleColor foregroundColor, Action action)
|
||||||
|
{
|
||||||
|
var lastColor = console.ForegroundColor;
|
||||||
|
console.ForegroundColor = foregroundColor;
|
||||||
|
|
||||||
|
action();
|
||||||
|
|
||||||
|
console.ForegroundColor = lastColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets console background color, executes specified action, and sets the color back to the original value.
|
||||||
|
/// </summary>
|
||||||
|
public static void WithBackgroundColor(this IConsole console, ConsoleColor backgroundColor, Action action)
|
||||||
|
{
|
||||||
|
var lastColor = console.BackgroundColor;
|
||||||
|
console.BackgroundColor = backgroundColor;
|
||||||
|
|
||||||
|
action();
|
||||||
|
|
||||||
|
console.BackgroundColor = lastColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets console foreground and background colors, executes specified action, and sets the colors back to the original values.
|
||||||
|
/// </summary>
|
||||||
|
public static void WithColors(this IConsole console, ConsoleColor foregroundColor, ConsoleColor backgroundColor, Action action) =>
|
||||||
|
console.WithForegroundColor(foregroundColor, () => console.WithBackgroundColor(backgroundColor, action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace CliFx.Utilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extensions for <see cref="Utilities"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class Extensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="ProgressTicker"/> bound to this console.
|
|
||||||
/// </summary>
|
|
||||||
public static ProgressTicker CreateProgressTicker(this IConsole console) => new ProgressTicker(console);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -48,4 +48,15 @@ namespace CliFx.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extensions for <see cref="ProgressTicker"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ProgressTickerExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="ProgressTicker"/> bound to this console.
|
||||||
|
/// </summary>
|
||||||
|
public static ProgressTicker CreateProgressTicker(this IConsole console) => new ProgressTicker(console);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user