mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Refactor IConsole.WithColors(...)
This commit is contained in:
@@ -116,16 +116,10 @@ namespace CliFx.Infrastructure
|
|||||||
public static IDisposable WithColors(
|
public static IDisposable WithColors(
|
||||||
this IConsole console,
|
this IConsole console,
|
||||||
ConsoleColor foregroundColor,
|
ConsoleColor foregroundColor,
|
||||||
ConsoleColor backgroundColor)
|
ConsoleColor backgroundColor) =>
|
||||||
{
|
Disposable.Merge(
|
||||||
var foregroundColorRegistration = console.WithForegroundColor(foregroundColor);
|
console.WithForegroundColor(foregroundColor),
|
||||||
var backgroundColorRegistration = console.WithBackgroundColor(backgroundColor);
|
console.WithBackgroundColor(backgroundColor)
|
||||||
|
);
|
||||||
return Disposable.Create(() =>
|
|
||||||
{
|
|
||||||
foregroundColorRegistration.Dispose();
|
|
||||||
backgroundColorRegistration.Dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace CliFx.Utils
|
namespace CliFx.Utils
|
||||||
{
|
{
|
||||||
@@ -14,5 +15,14 @@ namespace CliFx.Utils
|
|||||||
internal partial class Disposable
|
internal partial class Disposable
|
||||||
{
|
{
|
||||||
public static IDisposable Create(Action dispose) => new Disposable(dispose);
|
public static IDisposable Create(Action dispose) => new Disposable(dispose);
|
||||||
|
|
||||||
|
public static IDisposable Merge(IEnumerable<IDisposable> disposables) => Create(() =>
|
||||||
|
{
|
||||||
|
foreach (var disposable in disposables)
|
||||||
|
disposable.Dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
public static IDisposable Merge(params IDisposable[] disposables) =>
|
||||||
|
Merge((IEnumerable<IDisposable>) disposables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user