Archived

This topic is now archived and is closed to further replies.

trub

Console Animation via Text Output

Recommended Posts

I sometimes see programs that operate via the console (I am talking about the win32 cmd.exe here) and they display things like progress bars or error/status flags, etc. Like, if the program was processing a file it would show... Pre-Caching File [#***********] then Pre-Caching File [##**********] then Pre-Caching File [###*********] you get the idea What I was wondering is how they are able to print and update the console without it flickering like crazy. I tried to do a progross bar in C/C++ and just used system("cls") to clear and then redraw but had the flicker problem. Is there a better way to do this? Thanks! [edited by - trub on March 28, 2004 5:27:15 PM]

Share this post


Link to post
Share on other sites
Not sure if it works with a DOS window, but I know that on Linux, you can cout backspace characters to move back one character. So, you''d just print your progress bar (but no newline -- you can''t backspace past the beginning of a line and into the one above it), then when you needed to update it, backspace the number of characters your progress bar is wide so you''ll be back where it started, and print it again (in the updated state).

Or you could just do a windowed app -- you''ll need to eventually anyway, right? I mean, unless you''re writing a game with ASCII graphics...

Share this post


Link to post
Share on other sites
IIRC DOS has functions for setting where the cursor is at on the console... I can remember using it with QBasic, but never tried looking for any c/c++ equivalent.

There are a couple of libraries, such as ncurses, that let you do just about whatever you want on a text console. Probably a bit overkill for a progress bar though.



Drakonite

Shoot Pixels Not People

Share this post


Link to post
Share on other sites
For a Win32 console, Microsoft provides an API. Look up WriteConsoleOutput in MSDN and that should get you started.

Share this post


Link to post
Share on other sites