很难找到适合该问题的标题,我会尽力描述我的问题。
在我的命令行程序中,我使用了库ColorfulConsole(主要是因为使用了StyleSheets)。一切正常,我的所有颜色均正确显示。
当我在同一控制台会话中运行另一个命令时,会出现问题,颜色可以正确显示,但先前输出的颜色也将被覆盖。这将导致错误消息的颜色与调试输出的颜色相同。
让我们说我运行program.exe init -p <unknown directory>
。我得到以下(正确)输出:
执行时间与其他时间不同,这是我的错,但与问题无关
program.exe init -p <known directory>
问题A :是否有可能保留先前命令的颜色而不覆盖它们?
问题B :我错过了一些基本知识吗?
我已经尝试过:
Colorful.Console.ReplaceAllColorsWithDefaults();
Console.ResetColor();
Console.Clear();
(虽然可以运行,但是在每个命令之后清除控制台并不是很好)我知道Windows控制台有颜色限制,但是我没有超出颜色限制,因此我认为它与此无关。任何帮助表示赞赏。
编辑(使用Colorful.Console @ 1.2.10的最小可复制示例)
using System;
using System.Drawing;
using Console = Colorful.Console;
namespace MinimalReproducibleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Compiled with Color.Firebrick", Color.Firebrick);
}
}
}
当我运行此程序时,文本将显示为彩色火砖:
如果我用另一种颜色重新编译程序并执行它: