Fedora Linux Support Community & Resources Center
  #1  
Old 22nd February 2006, 11:07 PM
Firewing1's Avatar
Firewing1 Offline
Administrator
 
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224
Dynamic / Changing shell text?

Hello,
I've seen many programs -- eg Yum, Fsck, RPM, etc that will output progress bars during their run. Although, it's dynamic text -- It's not like
Code:
1% [program returns, waits a few seconds, and outputs the new value]
7.6% [same thing]
15%
It's one line that changes to the new value. Any tips on how to make these?

And, for a bonus, does anyone know how to take their values and use them for a GUI like YumEx does? I know how PyGTK works, I just need how to retrieve these values. I've tried looking at it's source, but couldn't find it.
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #2  
Old 22nd February 2006, 11:34 PM
RedFedora's Avatar
RedFedora Offline
Registered User
 
Join Date: May 2004
Posts: 503
For the progress bar, you can use logic like this:

while (! done)
{
printf("You are %d percent done.", my_percent);
// do some stuff
printf("\r");
}

The "\r" returns the cursor to the start of the line. I think
there is a better way to do this with ncurses, but this
is the really simply way.


I suppose if you were piping the output of your command to a GUI program,
you could just search the line for the number abd use that in your progress
bar. See "man popen".
__________________
Registered Linux User # 373325
Reply With Quote
  #3  
Old 22nd February 2006, 11:35 PM
brunson Offline
Registered User
 
Join Date: Jun 2005
Location: Westminster, Colorado
Posts: 2,305
For text, you can just print an ascii CarriageReturn character to put yourself at the beginning of the line and write the line again (you have to supress the newline each time you output).

In a GUI standard operating procedure would be to start the subprocess with a popen() call, then use select() to wait for output on the file descriptor, read any changes when the they occur, then update the GUI accordingly. Simple in concept, only a little hairy in implementation.
__________________
Registered Linux User #4837
411th in line to get sued by Micro$oft
Quote:
Basically, to learn Unix you learn to understand and apply a small set of key ideas and achieve expertise by expanding both the set of ideas and your ability to apply them - Paul Murphy
Reply With Quote
  #4  
Old 22nd February 2006, 11:53 PM
Firewing1's Avatar
Firewing1 Offline
Administrator
 
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224
Thanks!
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
Reply

Tags
changing, dynamic, shell, text

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla Flash plugin unicode dynamic text michaeleekk Using Fedora 0 3rd September 2006 03:52 PM
Shell Script (Formatting Text) pobman Programming & Packaging 4 26th April 2006 08:00 AM
text-shell resolution enlargement woosting Using Fedora 15 24th February 2005 02:05 AM
How do I access CD-ROM from text-based shell? TheProgrammer Using Fedora 8 4th November 2004 10:13 AM


Current GMT-time: 19:56 (Wednesday, 19-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat