dotnet-installer/build_projects/Microsoft.DotNet.Cli.Build.Framework/Reporter.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2016-02-02 18:04:50 +00:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build.Framework
{
// Stupid-simple console manager
internal class Reporter
{
private static readonly Reporter Null = new Reporter(console: null);
private static object _lock = new object();
private readonly AnsiConsole _console;
private Reporter(AnsiConsole console)
{
_console = console;
}
2016-02-23 20:10:50 +00:00
public static Reporter Output { get; } = new Reporter(AnsiConsole.GetOutput());
public static Reporter Error { get; } = new Reporter(AnsiConsole.GetOutput());
public static Reporter Verbose { get; } = new Reporter(AnsiConsole.GetOutput());
2016-02-02 18:04:50 +00:00
public void WriteLine(string message)
{
lock (_lock)
{
_console?.WriteLine(message);
}
}
public void WriteLine()
{
lock (_lock)
{
_console?.Writer?.WriteLine();
}
}
public void Write(string message)
{
lock (_lock)
{
_console?.Writer?.Write(message);
}
}
public void WriteBanner(string content)
{
string border = new string('*', content.Length + 6);
WriteLine($@"{border}
* {content} *
{border}".Green());
}
}
}