7

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?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
yck
  • 165
  • 1
  • 6
  • 1
    Under DOS, the ANSI.SYS driver was responsible for interpreting terminal control sequences. The following might help under Windows: https://github.com/adoxa/ansicon – Axel Kemper Apr 18 '13 at 11:41

2 Answers2

5

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

Xantium
  • 11,201
  • 10
  • 62
  • 89
1

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.

luser droog
  • 18,988
  • 3
  • 53
  • 105
  • From Windows 10 upwards it does work (the put the VT100 into their terminals) you just need to initailise it. – Xantium Jul 01 '18 at 16:20
  • 1
    That's interesting, if you have a reference or example code, that'd make a good answer. I couldn't find any at the time, and am not particularly motivated to research it ATM. – luser droog Jul 01 '18 at 16:32