mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using CliFx.Utils;
|
|
|
|
namespace CliFx.Infrastructure
|
|
{
|
|
/// <summary>
|
|
/// Implements a <see cref="TextWriter"/> for writing characters to a console stream.
|
|
/// </summary>
|
|
public partial class ConsoleWriter : StreamWriter
|
|
{
|
|
/// <summary>
|
|
/// Console that owns this stream.
|
|
/// </summary>
|
|
public IConsole Console { get; }
|
|
|
|
/// <summary>
|
|
/// Initializes an instance of <see cref="ConsoleWriter"/>.
|
|
/// </summary>
|
|
public ConsoleWriter(IConsole console, Stream stream, Encoding encoding)
|
|
: base(stream, encoding.WithoutPreamble(), 256)
|
|
{
|
|
Console = console;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes an instance of <see cref="ConsoleWriter"/>.
|
|
/// </summary>
|
|
public ConsoleWriter(IConsole console, Stream stream)
|
|
: this(console, stream, System.Console.OutputEncoding)
|
|
{
|
|
}
|
|
}
|
|
|
|
public partial class ConsoleWriter
|
|
{
|
|
internal static ConsoleWriter Create(IConsole console, Stream? stream) => new(
|
|
console,
|
|
stream is not null
|
|
? Stream.Synchronized(stream)
|
|
: Stream.Null
|
|
) {AutoFlush = true};
|
|
}
|
|
} |