Command Line Programming

I've seen some fancy command line programs. Some of them almost look animated. For instance, I used a command line installer for something in Ubuntu one, and it have a "progress arrow" that looked like [==> and would add an equals sign (=) in between the last one and the greater than (>).

Now, I know the answers will be different depending on which operating system I'm using, but I would like to learn how to program command line programs like that. I need a Windows and a Linux version of the command line front end, so if anyone can direct me to some decent resources for either, that would be wonderful.

I know that some people will tell me to just google it, but if you good "windows command line programming," you get nothing of value, and "windows c++ command line programming" is not much better. I cannot think of an effective way to phrase is so google knows what to look for. Hence why I came to the forum.

Anyway, any help and/or advice would be very appreciated.
All the C and C++ standard libraries have for output are streams, and streams are not designed to do any of this. What you want to do is access the console as if it was an actual device, not through the stream abstraction. Now, on Windows you can do this using system calls, but it's somewhat complicated, limited, and the result will only work on Windows. The curses libraries are portable, easy to use, and widely available. There are two open source curses that I know of. The only difference between them is their licences. PDcurses is in the public domain, while ncurses is GPL'd or LGPL'd.

Finally, "command line" and "console", while related, are entirely different things. A command line is a line of text used to invoke a program. It includes the program's name and any parameters that will be passed to it. For example, wget http://www.google.com/
A console is the device for text output.
Alright, so console was the word I needed to use.

I've tried using libraries for many different things, but have never succeeded in using libraries. I usually cannot get my IDE to compile code that uses libraries, even if I think I've "installed" them properly.

Anyway, I'll give it another go with libraries. I'm downloading code::blocks, as that seems to be a commonly used IDE.
well, here's a silly program which does the arrow thing.
you simply print a backspace '\b' to overwrite the arrow head.
it's not big, it's not clever :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <unistd.h>

using namespace std;

int main(int argc, char ** argv) {

    int count = 30;
    cout <<  "=>" << flush;
    while(--count) {
        usleep(1e05);
        cout <<  "\b=>" << flush;
    }

    cout << endl;

    return 0;
}
Last edited on
oh, BTW, you said ubuntu.
console animation.
install the package bb

run bb on a black console screen for best result.
ascii animation.
it is quite amazing.

Topic archived. No new replies allowed.