![]() |
|
Command Line Progress Bar (C/C++ and/or Java) |
bamccaig
Member #7,536
July 2006
![]() |
I am looking for an explanation/instructions on how some command-line applications show progress bars. For example, prompt>./dosomething
Doing something... Progress: [=========== ] 55% Does anybody know how this is done? I am looking for a solution that doesn't require clearing the screen with 'clear' or 'cls', etc. For example, the Linux update utility 'yum' shows similar progress bars on the command-line. You can still scroll up through previous output so clearly it is possible, at least in some cases, to achieve this without any crazy clearing of screens. I'm quite confident that it is possible with C/C++ in at least Windows and Linux (which I assume implies most Unix-like systems as well), although I don't know how or which libraries would achieve this. My instincts tell me it would be shell and operating system dependent, but I don't want excuses. I want results! As implied in the title of this thread, I am also interested in doing this with Java. Does anybody know of packages that can achieve this on the command-line? Your comments are appreciated. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Steve Terry
Member #1,989
March 2002
![]() |
I think you can use a special escape character, like /r to move the cursor to the beginning of the line. ___________________________________ |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
If you want complete control of the console window (changing colors, mouse support, cursor control) =-----===-----===-----= |
Steve Terry
Member #1,989
March 2002
![]() |
I was bored ___________________________________ |
bamccaig
Member #7,536
July 2006
![]() |
Thank you both! The \r is working and I also discovered that generating the string before printing it speeds up the line and makes the caret appear only at the end of the line flashing, as opposed to flashing inside of the progress bar ugly-ly. I also appreciate the article about controlling the command line. I will definitely look at that! Thanks again! -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Goalie Ca
Member #2,579
July 2002
![]() |
If you want more control over it i suggest looking into ncurses. ------------- |
|