如何让 win32 控制台识别 ANSI/VT100 转义序列? [英] How to make win32 console recognize ANSI/VT100 escape sequences?

查看:31
本文介绍了如何让 win32 控制台识别 ANSI/VT100 转义序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建 ncurses 库的轻量级版本.到目前为止,它在兼容 VT100 的终端上运行良好,但 win32 控制台无法将 33 代码识别为转义序列的开头:

I'm building a lightweight version of the ncurses library. So far, it works pretty well with VT100-compatible terminals, but win32 console fails to recognise the 33 code as the beginning of an escape sequence:

# include <stdio.h>
# include "term.h"

int main(void) {
  puts(BOLD COLOR(FG, RED) "Bold text" NOT_BOLD " is cool!" CLEAR);
  return 0;
}

需要在 C 代码级别做什么才能加载 ANSI.SYS 驱动程序并识别 ANSI/VT100 转义序列?

What needs to be done on the C code level, in order that the ANSI.SYS driver is loaded and the ANSI/VT100 escape sequences recognized?

推荐答案

[更新] 对于最新的 Windows 10,请阅读@brainslugs83 的有用贡献,就在此答案的评论下方.

[UPDATE] For latest Windows 10 please read useful contribution by @brainslugs83, just below in the comments to this answer.

对于Windows 10 周年更新之前的版本:

ANSI.SYS 有一个限制,它只能在 Windows 95-Vista 下的 MS-DOS 子系统上下文中运行.

ANSI.SYS has a restriction that it can run only in the context of the MS-DOS sub-system under Windows 95-Vista.

Microsoft KB101875 解释了如何在命令窗口中启用 ANSI.SYS,但它不适用于 Windows NT.根据文章:我们都喜欢颜色,现代版本的 Windows 没有这种良好的 ANSI 支持.

Microsoft KB101875 explains how to enable ANSI.SYS in a command window, but it does not apply to Windows NT. According to the article: we all love colors, modern versions of Windows do not have this nice ANSI support.

相反,微软创建了很多函数,但这远非你操作ANSI/VT100转义序列的需要.

Instead, Microsoft created a lot of functions, but this is far from your need to operate ANSI/VT100 escape sequence.

有关更详细的解释,请参阅维基百科文章:

For a more detailed explanation, see the Wikipedia article:

ANSI.SYS 也适用于 NT 派生系统,用于在 NTVDM 下执行的 16 位遗留程序.

ANSI.SYS also works in NT-derived systems for 16-bit legacy programs executing under the NTVDM.

Win32 控制台本身根本不支持 ANSI 转义序列.但是,诸如 Ansicon 之类的软件可以充当标准 Win32 控制台的包装器,并添加对 ANSI 转义序列的支持.

The Win32 console does not natively support ANSI escape sequences at all. Software such as Ansicon can however act as a wrapper around the standard Win32 console and add support for ANSI escape sequences.

所以我认为 Jason Hood 的 ANSICON 是您的解决方案.它是用 C 编写的,支持 32 位和 64 位版本的 Windows,并且 源码可用.

So I think ANSICON by Jason Hood is your solution. It is written in C, supports 32-bit and 64-bit versions of Windows, and the source is available.

我还发现了一些其他类似的问题或帖子,这些问题或帖子最终已被回答使用 ANSICON:

Also I found some other similar question or post which ultimately have been answered to use ANSICON:

这篇关于如何让 win32 控制台识别 ANSI/VT100 转义序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆