Browse Source

[monojob] Display percentage progress, if available

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
3936136e5e
1 changed files with 23 additions and 6 deletions
  1. 23
    6
      src/core/monojob.c

+ 23
- 6
src/core/monojob.c View File

@@ -57,14 +57,17 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
57 57
  * @ret rc		Job final status code
58 58
  */
59 59
 int monojob_wait ( const char *string ) {
60
+	struct job_progress progress;
60 61
 	int key;
61 62
 	int rc;
62
-	unsigned long last_progress_dot;
63
+	unsigned long last_progress;
63 64
 	unsigned long elapsed;
65
+	unsigned int percentage;
66
+	int shown_percentage = 0;
64 67
 
65
-	printf ( "%s.", string );
68
+	printf ( "%s...", string );
66 69
 	monojob_rc = -EINPROGRESS;
67
-	last_progress_dot = currticks();
70
+	last_progress = currticks();
68 71
 	while ( monojob_rc == -EINPROGRESS ) {
69 72
 		step();
70 73
 		if ( iskey() ) {
@@ -77,14 +80,28 @@ int monojob_wait ( const char *string ) {
77 80
 				break;
78 81
 			}
79 82
 		}
80
-		elapsed = ( currticks() - last_progress_dot );
83
+		elapsed = ( currticks() - last_progress );
81 84
 		if ( elapsed >= TICKS_PER_SEC ) {
82
-			printf ( "." );
83
-			last_progress_dot = currticks();
85
+			if ( shown_percentage )
86
+				printf ( "\b\b\b\b    \b\b\b\b" );
87
+			job_progress ( &monojob, &progress );
88
+			if ( progress.total ) {
89
+				percentage = ( ( 100 * progress.completed ) /
90
+					       progress.total );
91
+				printf ( "%3d%%", percentage );
92
+				shown_percentage = 1;
93
+			} else {
94
+				printf ( "." );
95
+				shown_percentage = 0;
96
+			}
97
+			last_progress = currticks();
84 98
 		}
85 99
 	}
86 100
 	rc = monojob_rc;
87 101
 
102
+	if ( shown_percentage )
103
+		printf ( "\b\b\b\b    \b\b\b\b" );
104
+
88 105
 	if ( rc ) {
89 106
 		printf ( " %s\n", strerror ( rc ) );
90 107
 	} else {

Loading…
Cancel
Save