开发者

How do I output to the console, and overwrite text without clearing the screen and re-writing everything?

开发者 https://www.devze.com 2023-03-06 18:10 出处:网络
Like when using aircrack-n开发者_Python百科g, or any program that has tables of data that constantly update.

Like when using aircrack-n开发者_Python百科g, or any program that has tables of data that constantly update.

=\


It depends somewhat on the system, and above all, how much you want to overwrite. For a lot of simply programs, outputting '\r' will do the trick: it will return the cursor to the start of the line (on almost all consoles), and you can overwrite the line. (I've used this in the past for continuously updated progress reports: n records processed, for example. Just be sure to not output a '\n' until you're ready.

For anything more complex, the usual solution is the curses library. It should be present on most Unix (sometimes under the name ncurses), and there's a port of ncurses to Windows as well. (The generic name of the library, and its name under traditional Unix, is curses; ncurses is a GPL implementation the library.)

0

精彩评论

暂无评论...
验证码 换一张
取 消