如何在 Windows 中使用 vt100 代码 [英] How to use vt100 code in Windows

查看:41
本文介绍了如何在 Windows 中使用 vt100 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to move the cursor in console.

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

And I find out that vt100 code could do this.

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

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

Its output is not the same as planned. this is what the code above print in console.

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

In the second line there's a small arrow before "A", it cant put on the web

123456789
Aabcdefghi

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

How to use the vt100 code when programming in Visual Studio in Windows?

推荐答案

并非所有 Windows 平台都支持 VT100.仅适用于 Windows 10 及更高版本(您可能会注意到 PowerShell 具有颜色).

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

If you are on Windows 10, you run your code above and it does not work; it means you have not activated it (it does not turn on by default).

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

There is a cross platform method (where you do not need to use Windows specific functions to get it started).

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

You just need to call system(" ") before your control codes:

#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()这里

您可以找到有关控制台虚拟终端序列的更多参考来自 Microsoft 文档:

You can find further reference for Console Virtual Terminal Sequences from the Microsoft Documentation:

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

The behavior of the following sequences is based on the VT100 and derived terminal emulator technologies, most specifically the xterm terminal emulator. More information about terminal sequences can be found at http://vt100.net and at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html.

<小时>

这篇文章似乎也很有帮助描述启动 VT100 的不同方式

这篇关于如何在 Windows 中使用 vt100 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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