完全有可能
彩色字体文本和大字体标题可以通过“彩色控制台”实现,我强烈推荐。
当我构建一个基于控制台的解决方案并且我想要漂亮的格式时,这就是我正在使用的。他们的网站很好,因为它演示了它可以做什么。但是,您可以在任何给定时间显示最大数量的不同颜色。这个限制是 16 种不同的颜色。
这个项目还允许你使用FIGlet字体,即红色'FourFort'的大标题。其中一些已经包含在内,但您可以在 Internet 上找到更多内容并可以创建自己的内容。
http://colorfulconsole.com/
许可证类型是 MIT,你可以在 Github 上找到它们
https://github.com/tomakita/Colorful.Console/blob/master/LICENSE.md
我在 Windows 和 Linux 的 net core 中编译没有任何问题
另一部分,如我所见,是覆盖一些控制台行为。
您可以使用 Console.Write 写入控制台并输出该字符,以便它预先添加所有内容。
或
您可以一次捕获输入的一个字符,循环中只有在输入特定序列(如“Enter”)时才会中断。如果您在捕获后删除输入,然后将其附加到您从上一次迭代中保留的内容中,您可能会产生该前缀 '>'
的错觉
更新
我写了一个概念证明来描述我提出的第二个想法。任何“静态”内容都必须添加到“historyInput”变量中。
代码如下:
using System;
namespace BeautifyConsoleSO
{
class Program
{
static void Main(string[] args)
{
char inputPrefix = '>';
bool flag = false;
string historyInput = string.Empty;
string currentInput = string.Empty;
historyInput += "Hello World!";
Console.WriteLine(historyInput);
Console.Write(inputPrefix);
while(flag != true)
{
ConsoleKeyInfo input = Console.ReadKey();
switch(input.Key)
{
case ConsoleKey.Spacebar:
currentInput += ' ';
break;
case ConsoleKey.Enter:
historyInput += Environment.NewLine;
historyInput += currentInput;
currentInput = string.Empty;
break;
case ConsoleKey.Backspace:
if(currentInput.Length > 0)
{
if (!currentInput[currentInput.Length - 1].Equals(' '))
{
currentInput = currentInput.Remove(currentInput.Length - 1);
}
else
{
currentInput = currentInput.Remove(currentInput.Length - 2);
}
}
break;
default:
currentInput += input.KeyChar;
break;
}
Console.Clear();
Console.WriteLine(historyInput);
Console.Write("{0}{1}", inputPrefix, currentInput);
}
Console.ReadLine();
}
}
}
但这并不完美;它有一些闪烁效果。如果我想到更好的东西,我会再次更新。
更新 2
这是一个变体; Console.Clear() 生成闪烁。这一项通过用新行归档相当于控制台高度的值来限制刷新。我还在游标前缀中添加了计数,以便更好地演示。
using System;
using System.Linq;
namespace BeautifyConsoleSO
{
class Program
{
static void Main(string[] args)
{
char inputPrefix = '>';
bool flag = false;
int clearConsoleRefreshSpeed = 100;
int clearConsoleTick = 0;
string historyInput = string.Empty;
string currentInput = string.Empty;
string fix = string.Concat(Enumerable.Repeat(Environment.NewLine, Console.WindowHeight));
Console.WriteLine(fix);
historyInput += "Hello World!";
Console.WriteLine(historyInput);
Console.Write(inputPrefix);
while(flag != true)
{
ConsoleKeyInfo input = Console.ReadKey();
switch(input.Key)
{
case ConsoleKey.Spacebar:
currentInput += ' ';
break;
case ConsoleKey.Enter:
historyInput += Environment.NewLine;
historyInput += currentInput;
currentInput = string.Empty;
break;
case ConsoleKey.Backspace:
if(currentInput.Length > 0)
{
if (!currentInput[currentInput.Length - 1].Equals(' '))
{
currentInput = currentInput.Remove(currentInput.Length - 1);
}
else
{
currentInput = currentInput.Remove(currentInput.Length - 2);
}
}
break;
default:
currentInput += input.KeyChar;
break;
}
// attempt to fix flickering associated with Console.Clear()
Console.WriteLine(fix);
Console.WriteLine(historyInput);
Console.Write("{0}{1}", clearConsoleTick + " " + inputPrefix, currentInput);
clearConsoleTick++;
if(clearConsoleTick % clearConsoleRefreshSpeed == 0)
{
Console.Clear();
Console.WriteLine(fix);
}
}
Console.ReadLine();
}
}
}
我不想向这个答案发送垃圾邮件,但是这个概念证明的第三种变体可以实现捕获每一行而不是一行中的每个字符。