msysgit:Unicode 字体警告

发布于 2024-11-04 17:32:49 字数 492 浏览 6 评论 0原文

最近,我在使用 msysgit 时遇到此错误,特别是当 git 输出生成一些非 ASCII 内容时:

警告:您的控制台字体可能不支持 Unicode。如果您在输出中遇到奇怪的字符,请考虑切换到 TrueType 字体,例如 Lucida Console!

有趣的是,虽然该消息告诉我我的字体不支持 Unicode,但它实际上支持 Unicode,并且相关文本显示正确(以正确的编码和显示所有字符)。

可悲的是我没有找到禁用此消息的方法。我尝试更改 Git Bash 中的字体(我通常使用 PowerShell),但是当我检查那里的字体时,我注意到它实际上已经设置为 Lucida Console,并且警告出现在同一个控制台中也。所以我有点不知道如何解决这个问题,或者至少阻止 msysgit 一直打印这个警告。

我尝试重新安装 msysgit,也选择了将字体设置为 Lucida Console 的选项,但没有帮助。我能做些什么?

Recently I am getting this error when using msysgit, in particular when there is some non-ASCII content generated by the git output:

warning: Your console font probably doesn't support Unicode. If you experience strange characters in the output, consider switching to a TrueType font such as Lucida Console!

The funny thing is that although that message is telling me that my font doesn't support Unicode, it actually does and the text in question is displayed correctly (in the correct encoding & with all characters displayed).

The sad thing is that I don't find a way to disable this message. I tried changing the font in the Git Bash (I usually use PowerShell) but when I checked the font there, I noticed that it was actually already set to Lucida Console, and the warning appears in that same console too. So I'm a bit clueless what to do to fix this, or at least stop msysgit from printing this warning all the time.

I tried reinstalling msysgit, also with the option selected that is supposed to set the font to Lucida Console, but it didn't help. What can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习ぎ惯性依靠 2024-11-11 17:32:49

实际上,它是在谈论更改命令提示符中的字体。

:]

Actually it is talking about changing the font in your Command Prompt.

:]

等你爱我 2024-11-11 17:32:49

该测试由 compat/winansi.c 中的函数 warn_if_raster_font 完成。这使用 Win32 API GetCurrentConsoleFontEx 来查找附加到当前输出流的控制台正在使用的字体。此测试在 Windows Vista 及更高版本上应该始终正确。在 Windows XP 上,它必须在注册表中查找当前默认的控制台字体。因此,您可能使用的是 XP,并且当您为正在使用的控制台配置了快捷方式时,默认设置仍配置为使用非 unicode 字体。

如果没有,您可以尝试编译以下使用大致相同代码的代码,然后查看它打印出来的内容。如果输出包含 tt: 4,我们希望相应的 git 代码能够正确检测您的控制台字体为 truetype。

#define STRICT
#define WINVER 0x0600
#define _WIN32_WINNT 0x600
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#ifdef __MINGW32__
typedef struct _CONSOLE_FONT_INFOEX {
        ULONG cbSize;
        DWORD nFont;
        COORD dwFontSize;
        UINT FontFamily;
        UINT FontWeight;
        WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
#endif

typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
                PCONSOLE_FONT_INFOEX);
int
_tmain(int argc, TCHAR *argv[])
{
    PGETCURRENTCONSOLEFONTEX pgccf;
    pgccf = (PGETCURRENTCONSOLEFONTEX)
        GetProcAddress(GetModuleHandleW(L"kernel32.dll"),
                   "GetCurrentConsoleFontEx");
    if (pgccf == NULL) {
        _tprintf(_T("error: failed to get function pointer\n"));
    } else {
        HANDLE console;
        CONSOLE_FONT_INFOEX cfi;
        cfi.cbSize = sizeof(cfi);

        console = GetStdHandle(STD_OUTPUT_HANDLE);
        if (!pgccf(console, 0, &cfi)) {
            _tprintf(_T("error: failed to get console info\n"));
        } else {
            _tprintf(_T("font %08x tt:%d"), cfi.FontFamily,
                 (cfi.FontFamily&TMPF_TRUETYPE));
            wprintf(L" %s", cfi.FaceName);
            _tprintf(_T("\n"));
        }
    }
    return 0;
}

This test is done by the function warn_if_raster_font in compat/winansi.c. This uses the Win32 API GetCurrentConsoleFontEx to find the font in use by the console attached to the current output stream. This test should always be correct on Windows Vista and above. On Windows XP it has to resort to looking in the registry for the current default console font. So possibly you are on XP and while you have configured the shortcut for the console you are using, the default setting remains configured to use a non-unicode font.

If not, you might try compiling the following which uses roughly the same code and see what it prints out. Provided the output contains tt: 4 we would expect the corresponding git code to properly detect your console font as truetype.

#define STRICT
#define WINVER 0x0600
#define _WIN32_WINNT 0x600
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#ifdef __MINGW32__
typedef struct _CONSOLE_FONT_INFOEX {
        ULONG cbSize;
        DWORD nFont;
        COORD dwFontSize;
        UINT FontFamily;
        UINT FontWeight;
        WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
#endif

typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
                PCONSOLE_FONT_INFOEX);
int
_tmain(int argc, TCHAR *argv[])
{
    PGETCURRENTCONSOLEFONTEX pgccf;
    pgccf = (PGETCURRENTCONSOLEFONTEX)
        GetProcAddress(GetModuleHandleW(L"kernel32.dll"),
                   "GetCurrentConsoleFontEx");
    if (pgccf == NULL) {
        _tprintf(_T("error: failed to get function pointer\n"));
    } else {
        HANDLE console;
        CONSOLE_FONT_INFOEX cfi;
        cfi.cbSize = sizeof(cfi);

        console = GetStdHandle(STD_OUTPUT_HANDLE);
        if (!pgccf(console, 0, &cfi)) {
            _tprintf(_T("error: failed to get console info\n"));
        } else {
            _tprintf(_T("font %08x tt:%d"), cfi.FontFamily,
                 (cfi.FontFamily&TMPF_TRUETYPE));
            wprintf(L" %s", cfi.FaceName);
            _tprintf(_T("\n"));
        }
    }
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文