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
  * @ret rc		Job final status code
57
  * @ret rc		Job final status code
58
  */
58
  */
59
 int monojob_wait ( const char *string ) {
59
 int monojob_wait ( const char *string ) {
60
+	struct job_progress progress;
60
 	int key;
61
 	int key;
61
 	int rc;
62
 	int rc;
62
-	unsigned long last_progress_dot;
63
+	unsigned long last_progress;
63
 	unsigned long elapsed;
64
 	unsigned long elapsed;
65
+	unsigned int percentage;
66
+	int shown_percentage = 0;
64
 
67
 
65
-	printf ( "%s.", string );
68
+	printf ( "%s...", string );
66
 	monojob_rc = -EINPROGRESS;
69
 	monojob_rc = -EINPROGRESS;
67
-	last_progress_dot = currticks();
70
+	last_progress = currticks();
68
 	while ( monojob_rc == -EINPROGRESS ) {
71
 	while ( monojob_rc == -EINPROGRESS ) {
69
 		step();
72
 		step();
70
 		if ( iskey() ) {
73
 		if ( iskey() ) {
77
 				break;
80
 				break;
78
 			}
81
 			}
79
 		}
82
 		}
80
-		elapsed = ( currticks() - last_progress_dot );
83
+		elapsed = ( currticks() - last_progress );
81
 		if ( elapsed >= TICKS_PER_SEC ) {
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
 	rc = monojob_rc;
100
 	rc = monojob_rc;
87
 
101
 
102
+	if ( shown_percentage )
103
+		printf ( "\b\b\b\b    \b\b\b\b" );
104
+
88
 	if ( rc ) {
105
 	if ( rc ) {
89
 		printf ( " %s\n", strerror ( rc ) );
106
 		printf ( " %s\n", strerror ( rc ) );
90
 	} else {
107
 	} else {

Loading…
Cancel
Save