Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I need to update text in terminal. Say update some 90% to 91%. Just like the command line downloaders do. How can I do it in C or bash ...
  1. #1
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51

    Updating text in terminal

    Hi, I need to update text in terminal. Say update some 90% to 91%. Just like the command line downloaders do. How can I do it in C or bash script (i mean inclusive or).

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The trick is to output the backspace character (represented symbolically as '\b'). So for instance, in Bash (though this translates directly into C):
    Code:
    alex@danu ~ $ echo -n 'ab'; echo -e '\bc'
    ac
    I print out 'ab' (the '-n' disables the trailing newline). I then print out the backspace character and 'c' (the '-e' enables backslash interpretation). The 'b' is erased, and replaced with the 'c'.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    Hah, that's clever as hell Cabhan! I like that. I was thinking use dialog or ncurses.

  4. #4
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51

    \b oh no!

    How can I update this?

    Task 1: 99%
    Task 2: 65%
    Task 3: 80%
    .......
    ......

    Where progress of different tasks is updated by different threads?
    \b simply isn't the solution.

  5. #5
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51

    yes curses

    Now I've got it. Curse that's all google needed to lead me toward what I wanted.
    Thanks.

  6. #6
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Aha. For that, you'll need separate labels, each of which is managed by its own thread. I've not used curses myself before, but I'm sure that it has the facilities you need.
    DISTRO=Arch
    Registered Linux User #388732

  7. #7
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    O I though you were sticking with bash, yea NCurses can do that pretty easily. Don't think you even really need to use threads for it. Just have a loop that does the math on the three counters then uses addstr() to put the information in the window and refresh() to draw it. If you're interested in NCurses, I recommend getting the only book on the topic (besides O Reilly's curses book from the 80s), "Programmer's Guide to NCurses". I have it, and it goes through Ncurses slowly and methodically with TONS of code examples.

  8. #8
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51

    Yeah. NCurses

    Thanks. NCurses. That's all I needed. There is rich documentation on the web.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...