简体   繁体   中英

Erase multiple console lines with console characters

So I'm aware that with console characters you can return the cursor to the beginning of the current line ( \\r ) or just a single character ( \\b ) for overwriting. What I would like to know is I overwrite multiple lines with control characters.

I have a grid of dots, printed to the console:

. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .

And then go back to the first character and redraw it

. . . . . . . .
. . . 0 . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .

Not sure which language this will be in, that's why I'd prefer the solution to use characters.

(All the below only applies if you do not render the output yourself in a Swing JPanel or similar)

Note that the emulation level you can expect from a console output unit is very limited. Typically you can expect Ctrl-H to backspace, and Ctrl-M to return the cursor to the beginning of the line. Anything more than that sets additional requirements.

Historically this has been done by sending ANSI escape sequences (a close relative of the physical VT100 terminal) which was then interpreted to move the cursor, clear parts of the monitor and switch colors. You will need something similar to do this in the output device. For CMD.EXE in Windows see How to make win32 console recognize ANSI/VT100 escape sequences? for suggestions. Linux and OS X terminal emulators support this.

You can then either generate the escape sequences yourself - which is relatively easy for simple needs - or delegate to a curses/ncurses library, to achieve what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM