Move extensions closer to the actual classes

This commit is contained in:
Alexey Golub
2020-05-11 16:51:36 +03:00
parent 802bbfccc6
commit 65628b145a
4 changed files with 49 additions and 55 deletions

View File

@@ -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));
}
}

View File

@@ -71,4 +71,42 @@ namespace CliFx
/// </summary>
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));
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}