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(
|
||||
this IConsole console,
|
||||
ConsoleColor foregroundColor,
|
||||
ConsoleColor backgroundColor)
|
||||
{
|
||||
var foregroundColorRegistration = console.WithForegroundColor(foregroundColor);
|
||||
var backgroundColorRegistration = console.WithBackgroundColor(backgroundColor);
|
||||
|
||||
return Disposable.Create(() =>
|
||||
{
|
||||
foregroundColorRegistration.Dispose();
|
||||
backgroundColorRegistration.Dispose();
|
||||
});
|
||||
}
|
||||
ConsoleColor backgroundColor) =>
|
||||
Disposable.Merge(
|
||||
console.WithForegroundColor(foregroundColor),
|
||||
console.WithBackgroundColor(backgroundColor)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CliFx.Utils
|
||||
{
|
||||
@@ -14,5 +15,14 @@ namespace CliFx.Utils
|
||||
internal partial class Disposable
|
||||
{
|
||||
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