Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Fancy Terminal Tricks

Fancy Terminal Tricks
Thread Tools
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Dec 5, 2002, 12:10 AM
 
I thought I saw how to do this somewhere before, but I can't remember where exactly. I want to be print out information to stdout the way thet wget and scp do with their progress bar. That is, I want to be able to write out characters to specifically locations in stdout (or do I just rewrite the whole line, I dunno).

Thanks,
Matt
     
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status: Offline
Reply With Quote
Dec 5, 2002, 02:22 AM
 
I'm not following you. You mean write characters to specific places on the terminal screen?

If you want to get fancy, doing stuff like they used to do before graphical windows became popular, check out curses.h. Here's a good reference manual.

http://jnagy.com/Ftp/download/public...C%20Curses.pdf

Here's a good introduction and overview.

http://www.wrkgrp.com/support/Curses.html

Probably both of those will seem a tad daunting. Especially since you'll only be doing a few simple things out of the library. The following is a pretty good tutorial that goes through some very simple code.

http://saathi.ncst.ernet.in/~pgdst/p...20Tutorial.htm

You should be able to pick out of that a few functions that will do what you are looking for.
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Dec 5, 2002, 04:00 AM
 
Curses is good for plenty of things, but it's overkill for a one-line "progress bar" animation.

You can "animate" a single line of text by printing over it multiple times -- print a line, then issue a carriage return instead of a newline. For example:
Code:
printf(" 10 %% #\r"); printf(" 20 %% ##\r"); printf(" 30 %% ###\r"); ... printf(" 90 %% #########\r"); printf("100 %% ##########\r");
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Dec 6, 2002, 01:39 AM
 
Originally posted by Rickster:
Curses is good for plenty of things, but it's overkill for a one-line "progress bar" animation.

You can "animate" a single line of text by printing over it multiple times -- print a line, then issue a carriage return instead of a newline. For example:
Code:
printf(" 10 %% #\r"); printf(" 20 %% ##\r"); printf(" 30 %% ###\r"); ... printf(" 90 %% #########\r"); printf("100 %% ##########\r");
Thanks Richster... but you forgot one thing. One will probably want to flush the printf buffer (aka stdout) in the case of a progress bar because the prtinf buffer doesn't get normally flushed to screen unless there's a newline character. Small modification, but it would be like this:

Code:
int i; for(i=0; i<10; i++) { printf("%d progress so far",10*i); fflush(stdout); }
Thanks,
Matt
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:26 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2