Remove Microsoft.DotNet.Cli.Utils
This commit is contained in:
parent
7f7742577d
commit
49fd345192
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<packageSources>
|
|
||||||
<clear />
|
|
||||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
|
||||||
</packageSources>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Cli.Utils
|
||||||
|
{
|
||||||
|
public static class AnsiColorExtensions
|
||||||
|
{
|
||||||
|
public static string Red(this string text)
|
||||||
|
{
|
||||||
|
return "\x1B[31m" + text + "\x1B[39m";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Yellow(this string text)
|
||||||
|
{
|
||||||
|
return "\x1B[33m" + text + "\x1B[39m";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
// 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.IO;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Cli.Utils
|
||||||
|
{
|
||||||
|
public class AnsiConsole
|
||||||
|
{
|
||||||
|
private AnsiConsole(TextWriter writer)
|
||||||
|
{
|
||||||
|
Writer = writer;
|
||||||
|
|
||||||
|
OriginalForegroundColor = Console.ForegroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _boldRecursion;
|
||||||
|
|
||||||
|
public static AnsiConsole GetOutput()
|
||||||
|
{
|
||||||
|
return new AnsiConsole(Console.Out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AnsiConsole GetError()
|
||||||
|
{
|
||||||
|
return new AnsiConsole(Console.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextWriter Writer { get; }
|
||||||
|
|
||||||
|
public ConsoleColor OriginalForegroundColor { get; }
|
||||||
|
|
||||||
|
private void SetColor(ConsoleColor color)
|
||||||
|
{
|
||||||
|
const int Light = 0x08;
|
||||||
|
int c = (int)color;
|
||||||
|
|
||||||
|
Console.ForegroundColor =
|
||||||
|
c < 0 ? color : // unknown, just use it
|
||||||
|
_boldRecursion > 0 ? (ConsoleColor)(c | Light) : // ensure color is light
|
||||||
|
(ConsoleColor)(c & ~Light); // ensure color is dark
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetBold(bool bold)
|
||||||
|
{
|
||||||
|
_boldRecursion += bold ? 1 : -1;
|
||||||
|
if (_boldRecursion > 1 || (_boldRecursion == 1 && !bold))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// switches on _boldRecursion to handle boldness
|
||||||
|
SetColor(Console.ForegroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine(string message)
|
||||||
|
{
|
||||||
|
Write(message);
|
||||||
|
Writer.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Write(string message)
|
||||||
|
{
|
||||||
|
var escapeScan = 0;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
var escapeIndex = message.IndexOf("\x1b[", escapeScan, StringComparison.Ordinal);
|
||||||
|
if (escapeIndex == -1)
|
||||||
|
{
|
||||||
|
var text = message.Substring(escapeScan);
|
||||||
|
Writer.Write(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var startIndex = escapeIndex + 2;
|
||||||
|
var endIndex = startIndex;
|
||||||
|
while (endIndex != message.Length &&
|
||||||
|
message[endIndex] >= 0x20 &&
|
||||||
|
message[endIndex] <= 0x3f)
|
||||||
|
{
|
||||||
|
endIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = message.Substring(escapeScan, escapeIndex - escapeScan);
|
||||||
|
Writer.Write(text);
|
||||||
|
if (endIndex == message.Length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (message[endIndex])
|
||||||
|
{
|
||||||
|
case 'm':
|
||||||
|
int value;
|
||||||
|
if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value))
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
SetBold(true);
|
||||||
|
break;
|
||||||
|
case 22:
|
||||||
|
SetBold(false);
|
||||||
|
break;
|
||||||
|
case 30:
|
||||||
|
SetColor(ConsoleColor.Black);
|
||||||
|
break;
|
||||||
|
case 31:
|
||||||
|
SetColor(ConsoleColor.Red);
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
SetColor(ConsoleColor.Green);
|
||||||
|
break;
|
||||||
|
case 33:
|
||||||
|
SetColor(ConsoleColor.Yellow);
|
||||||
|
break;
|
||||||
|
case 34:
|
||||||
|
SetColor(ConsoleColor.Blue);
|
||||||
|
break;
|
||||||
|
case 35:
|
||||||
|
SetColor(ConsoleColor.Magenta);
|
||||||
|
break;
|
||||||
|
case 36:
|
||||||
|
SetColor(ConsoleColor.Cyan);
|
||||||
|
break;
|
||||||
|
case 37:
|
||||||
|
SetColor(ConsoleColor.Gray);
|
||||||
|
break;
|
||||||
|
case 39:
|
||||||
|
Console.ForegroundColor = OriginalForegroundColor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
escapeScan = endIndex + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Cli.Utils
|
||||||
|
{
|
||||||
|
// Stupid-simple console manager
|
||||||
|
public class Reporter
|
||||||
|
{
|
||||||
|
private static readonly Reporter NullReporter = new Reporter(console: null);
|
||||||
|
private static object _lock = new object();
|
||||||
|
|
||||||
|
private readonly AnsiConsole _console;
|
||||||
|
|
||||||
|
private Reporter(AnsiConsole console)
|
||||||
|
{
|
||||||
|
_console = console;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Reporter Output { get; } = new Reporter(AnsiConsole.GetOutput());
|
||||||
|
public static Reporter Error { get; } = new Reporter(AnsiConsole.GetError());
|
||||||
|
|
||||||
|
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?.Write(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.Extensions.Cli.Utils;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine(e.Message.Red());
|
Reporter.Error.WriteLine(e.Message.Red());
|
||||||
Reporter.Verbose.WriteLine(e.ToString().Yellow());
|
Reporter.Output.WriteLine(e.ToString().Yellow());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
using Microsoft.Extensions.Cli.Utils;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.Extensions.CommandLineUtils": "1.0.0-*",
|
"Microsoft.Extensions.CommandLineUtils": "1.0.0-*",
|
||||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||||
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
|
||||||
"System.Diagnostics.Process": "4.1.0-*"
|
"System.Diagnostics.Process": "4.1.0-*"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.Extensions.Cli.Utils;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine(e.Message.Red());
|
Reporter.Error.WriteLine(e.Message.Red());
|
||||||
Reporter.Verbose.WriteLine(e.ToString().Yellow());
|
Reporter.Output.WriteLine(e.ToString().Yellow());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
using Microsoft.Extensions.Cli.Utils;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,11 @@
|
||||||
"nowarn": [ "CS1591" ],
|
"nowarn": [ "CS1591" ],
|
||||||
"xmlDoc": true
|
"xmlDoc": true
|
||||||
},
|
},
|
||||||
|
"compile": "../Microsoft.AspNetCore.Server.IISIntegration.Tools/Internal/*.cs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.Extensions.CommandLineUtils": "1.0.0-*",
|
"Microsoft.Extensions.CommandLineUtils": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
||||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||||
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
|
||||||
"System.Diagnostics.Process": "4.1.0-*"
|
"System.Diagnostics.Process": "4.1.0-*"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue