Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vt100 code in Windows

I try to move the cursor in console.

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.

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

123456789
Aabcdefghi

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

like image 526
yck Avatar asked Apr 18 '13 11:04

yck


2 Answers

Not all Windows platforms support VT100. Only those Windows 10 and above (you may notice that PowerShell has colours).

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).

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

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;
}

Or you can use SetConsoleTextAttribute() to activate VT100 as described here


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

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.


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

like image 80
Xantium Avatar answered Sep 28 '22 12:09

Xantium


VT100 codes will not work in the normal Windows console. You'll need a terminal emulation program.

This page seems to claim that it does support vt100. But I can't personally confirm this. And I can't find any reference.

Probably overkill, but Cygwin includes an X-server with which you can run Xterm which supports vt100 codes.

like image 45
luser droog Avatar answered Sep 28 '22 12:09

luser droog