【发布时间】:2020-06-03 04:22:48
【问题描述】:
我编写了这个简单的 C#/.NET Core 控制台应用程序代码,它输出一组 7x7x7 的颜色立方体,测试 24 位颜色而不是 256 色模式,以及我使用的自定义 TTF 字体,它源自“Ultimate Old School PC Font Pack”包含一些额外的 Unicode 块字符。
正如所见,它在 Windows 10 终端中运行良好,但在 Cygwin 中却很糟糕,尽管根据 Github (https://gist.github.com/XVilka/8346728) 应该支持它。
如果使用 [38m 或 [48m 代码的代码中的某些内容可能与使用 Cygwin.bat 或 Cygwin 的 mintty 的 Cygwin 不太兼容,那么关于可能出现什么问题的任何想法?
但是,正如您从第三张图片中看到的那样,它在 Mingw64/MSYS2 的 Mintty 中看起来还不错,但我更喜欢使用 Cygwin。如您所见,它以某种方式破坏了第三张图片中的三角形字符,即使我在 mintty 中将字符集设置为 UTF-8。
using System;
using System.Text;
namespace ConsoleColor
{
public class App
{
//int[] colorMeta1 = { 0, 85, 170, 255 };
int[] colorMeta2 = { 0, 43, 85, 127, 170, 213, 255 };
public App()
{
int length = colorMeta2.Length;
int index = 0;
Encoding defaultEncoder = Console.OutputEncoding;
Console.OutputEncoding = Encoding.UTF8;
for (int r=0;r<length;r++)
{
for(int g=0;g<length;g++)
{
for(int b=0;b<length;b++)
{
int r2 = colorMeta2[r];
int g2 = colorMeta2[g];
int b2 = colorMeta2[b];
int foregroundColor = (r2 == 255 || g2 == 255 || b2 == 255) ? 0 : 255;
Console.Write($"\u001b[38;2;{r2};{g2};{b2}m█");
Console.Write($"\u001b[38;2;{foregroundColor};{foregroundColor};{foregroundColor}m\u001b[48;2;{r2};{g2};{b2}m({r2.ToString().PadLeft(3, ' ')},{g2.ToString().PadLeft(3, ' ')},{b2.ToString().PadLeft(3, ' ')})");
Console.Write($"\u001b[38;2;{r2};{g2};{b2}m█");
Console.Write($"\u001b[38;2;{170};{170};{170}m");
Console.Write($"\u001b[48;2;{0};{0};{0}m");
index++;
}
Console.WriteLine();
}
}
Console.WriteLine($"{index} total colors.");
for (int a = 0x2580; a <= 0x259F; a++)
Console.Write($"{(char)a}");
for (int a = 0x25E2; a <= 0x25E5; a++)
Console.Write($"{(char)a}");
Console.WriteLine();
Console.OutputEncoding = defaultEncoder;
}
}
class Program
{
static void Main(string[] args)
{
App app = new App();
}
}
}
【问题讨论】:
-
将薄荷糖
terminal type更改为xterm-direct或mintty-direct -
@matzeri:在 Cygwin 安装中不起作用。查看有关 MSys2/MingW64 版本 mintty 的页面,它是 3.1.6(x86_64-pc-msys),而 Cygwin 版本是 mintty 3.1.6(x86_64-pc-cygwin)。如果我使用 Windows cmd.exe 命令提示符来“dotrun run >run1.txt”,然后在 Cygwin 终端上使用“cat run1.txt”,它可以工作,但“dotnet run”在 Cygwin 下无法使用相同的输出,事实上,输出有时会显示 msys2 版本的正确字符,有时不会在后续运行中显示,这似乎表明 dotnet 和 mintty 可能存在问题。
-
我指的是 Mintty 的配置,而不是另一个包。点击 Mintty 窗口左上角的图标而不是
Option-> Terminal -> Type -
我试过了,还是不行。