0

I'm trying to use the escape sequence \033[999D as a brute-force way of moving the cursor to the top row in the console. When I run my program, rather than doing what I intend, it returns a left-pointing arrow and a [999D, on the same line that I was last on.

How should I properly use this escape code? Are there any (better) substitutions?

My (test) code:

printf("This is a line\n");
printf("This is another line\n");
printf("\033[999D Overwrite");

My output:

This is a line
This is another line
←[999D Overwrite
2xedo
  • 147
  • 1
  • 2
  • 8
  • What system are you using? Ansi escape sequence processing is not enabled by default in the dumb Windows terminal. The scape sequence to move to home position is different too. – chqrlie Mar 07 '15 at 01:52
  • @chqrlie I'm on Windows 8.1, using a MinGW compiler, if that helps. – 2xedo Mar 07 '15 at 02:42
  • possible duplicate of [Setting the Cursor Position in a Win32 Console Application](http://stackoverflow.com/questions/2732292/setting-the-cursor-position-in-a-win32-console-application) – Jonathon Reinhart Mar 07 '15 at 05:43

2 Answers2

2

Check out the Win32 Console API.

Particularly of interest to you:

Of interest to people looking to set console colors:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
0

There are two problems (most likely): The first is that the D VT100 cursor control sequence is to go back a number of columns, which means it will go back a number of columns on the current row. It will not change line.

The second and the likely problem the code is printed is because you probably are using the Windows console program (the "DOS prompt") which is very bad at handling VT100 sequences by default.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • I believe I am using the DOS prompt. What should I use, in this case, to go back a specific row and column in the console? – 2xedo Mar 07 '15 at 02:44
  • 1
    @tuxedoandex The native Windows console program doesn't really support VT100/ANSI sequences at all, there are ways around it [as detailed in e.g. this old answer](http://stackoverflow.com/a/16799175/440558). As for the list of possible cursor control sequences, please follow the link in my answer. – Some programmer dude Mar 07 '15 at 02:53
  • Is there any way other than ANSI escape sequences to move the cursor? :\ – 2xedo Mar 07 '15 at 05:10