summaryrefslogtreecommitdiffstats
path: root/src/core/monojob.c
diff options
context:
space:
mode:
authorMichael Brown2011-03-08 00:55:57 +0100
committerMichael Brown2011-03-08 00:55:57 +0100
commit3936136e5e300ad793e0eb149eb13a4400b208f6 (patch)
tree00701395ec9d3ba5092638aade31fb34bf6b523b /src/core/monojob.c
parent[prefix] Allow iPXE's own command line to be executed as a script (diff)
downloadipxe-3936136e5e300ad793e0eb149eb13a4400b208f6.tar.gz
ipxe-3936136e5e300ad793e0eb149eb13a4400b208f6.tar.xz
ipxe-3936136e5e300ad793e0eb149eb13a4400b208f6.zip
[monojob] Display percentage progress, if available
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/monojob.c')
-rw-r--r--src/core/monojob.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/core/monojob.c b/src/core/monojob.c
index 994edeb1..682b1dfb 100644
--- a/src/core/monojob.c
+++ b/src/core/monojob.c
@@ -57,14 +57,17 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
* @ret rc Job final status code
*/
int monojob_wait ( const char *string ) {
+ struct job_progress progress;
int key;
int rc;
- unsigned long last_progress_dot;
+ unsigned long last_progress;
unsigned long elapsed;
+ unsigned int percentage;
+ int shown_percentage = 0;
- printf ( "%s.", string );
+ printf ( "%s...", string );
monojob_rc = -EINPROGRESS;
- last_progress_dot = currticks();
+ last_progress = currticks();
while ( monojob_rc == -EINPROGRESS ) {
step();
if ( iskey() ) {
@@ -77,14 +80,28 @@ int monojob_wait ( const char *string ) {
break;
}
}
- elapsed = ( currticks() - last_progress_dot );
+ elapsed = ( currticks() - last_progress );
if ( elapsed >= TICKS_PER_SEC ) {
- printf ( "." );
- last_progress_dot = currticks();
+ if ( shown_percentage )
+ printf ( "\b\b\b\b \b\b\b\b" );
+ job_progress ( &monojob, &progress );
+ if ( progress.total ) {
+ percentage = ( ( 100 * progress.completed ) /
+ progress.total );
+ printf ( "%3d%%", percentage );
+ shown_percentage = 1;
+ } else {
+ printf ( "." );
+ shown_percentage = 0;
+ }
+ last_progress = currticks();
}
}
rc = monojob_rc;
+ if ( shown_percentage )
+ printf ( "\b\b\b\b \b\b\b\b" );
+
if ( rc ) {
printf ( " %s\n", strerror ( rc ) );
} else {