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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With