How to animate the command line? -


i have wondered how people update previous line in command line. great example of when using wget command in linux. creates ascii loading bar of sorts looks this:

[======>                    ] 37%

and of course loading bar moves , percent changes, doesn't make new line. cannot figure out how this. can point me in right direction?

there 2 ways know of this:

  • use backspace escape character ('\b') erase line
  • use curses package, if programming language of choice has bindings it.

and google revealed ansi escape codes, appear way. reference, here function in c++ this:

void drawprogressbar(int len, double percent) {   cout << "\x1b[2k"; // erase entire current line.   cout << "\x1b[0e"; // move beginning of current line.   string progress;   (int = 0; < len; ++i) {     if (i < static_cast<int>(len * percent)) {       progress += "=";     } else {       progress += " ";     }   }   cout << "[" << progress << "] " << (static_cast<int>(100 * percent)) << "%";   flush(cout); // required. } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -