【问题标题】:How to use vt100 code in Windows如何在 Windows 中使用 vt100 代码
【发布时间】:2013-04-11 11:46:07
【问题描述】:

我尝试在控制台中移动光标。

我发现 vt100 代码可以做到这一点。

#include<stdio.h>
int main()
{
    printf("123456789\n");
    printf("\033A");
    printf("abcdefghi\n");
    return 0;
}

它的输出和计划的不一样。这就是上面的代码在控制台中打印的内容。

第二行“A”前面有个小箭头,不能放到网页上

123456789
Aabcdefghi

在Windows下用Visual Studio编程时如何使用vt100代码?

【问题讨论】:

  • 在 DOS 下,ANSI.SYS 驱动程序负责解释终端控制序列。以下可能在 Windows 下有所帮助:github.com/adoxa/ansicon

标签: c windows visual-studio vt100


【解决方案1】:

VT100 代码在普通 Windows 控制台中不起作用。您需要terminal emulation program

This page 似乎声称它确实支持 vt100。但我个人无法证实这一点。而且我找不到任何参考。

可能有点矫枉过正,但Cygwin 包含一个 X 服务器,您可以使用它运行支持 vt100 代码的 Xterm

【讨论】:

  • 从 Windows 10 向上它确实可以工作(将 VT100 放入他们的终端)你只需要初始化它。
  • 这很有趣,如果您有参考或示例代码,那将是一个很好的答案。我当时找不到任何东西,也不是特别有动力去研究它 ATM。
【解决方案2】:

并非所有 Windows 平台都支持 VT100。只有那些 Windows 10 及更高版本(您可能会注意到 PowerShell 有颜色)。

如果您使用的是 Windows 10,则运行上面的代码但它不起作用;这意味着您尚未激活它(默认情况下它不会打开)。

有一种跨平台方法(您无需使用 Windows 特定功能即可开始使用)。

您只需要在控制代码之前调用system(" ")

#include<stdio.h>
#include <stdlib.h> // Library for system() function

int main()
{
    system(" "); // Start VT100 support

    printf("123456789\n");
    printf("\033A"); // And you are away :)

    printf("abcdefghi\n");
    return 0;
}

或者您可以使用SetConsoleTextAttribute() 激活VT100,如here 所述


您可以找到更多关于控制台虚拟终端序列的参考from the Microsoft Documentation

以下序列的行为基于 VT100 和衍生的终端仿真器技术,尤其是 xterm 终端仿真器。有关终端序列的更多信息,请访问 http://vt100.nethttp://invisible-island.net/xterm/ctlseqs/ctlseqs.html


This post also seems helpful as it describes different ways to start VT100

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-03
    • 2021-02-05
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多