Browse Source

[monojob] Display job status message, if present

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
4674df25ef
1 changed files with 25 additions and 9 deletions
  1. 25
    9
      src/core/monojob.c

+ 25
- 9
src/core/monojob.c View File

55
 
55
 
56
 struct interface monojob = INTF_INIT ( monojob_intf_desc );
56
 struct interface monojob = INTF_INIT ( monojob_intf_desc );
57
 
57
 
58
+/**
59
+ * Clear previously displayed message
60
+ *
61
+ * @v len		Length of previously displayed message
62
+ */
63
+static void monojob_clear ( size_t len ) {
64
+	unsigned int i;
65
+
66
+	for ( i = 0 ; i < len ; i++ )
67
+		putchar ( '\b' );
68
+	for ( i = 0 ; i < len ; i++ )
69
+		putchar ( ' ' );
70
+	for ( i = 0 ; i < len ; i++ )
71
+		putchar ( '\b' );
72
+}
73
+
58
 /**
74
 /**
59
  * Wait for single foreground job to complete
75
  * Wait for single foreground job to complete
60
  *
76
  *
73
 	unsigned long scaled_completed;
89
 	unsigned long scaled_completed;
74
 	unsigned long scaled_total;
90
 	unsigned long scaled_total;
75
 	unsigned int percentage;
91
 	unsigned int percentage;
76
-	int shown_percentage = 0;
92
+	size_t clear_len = 0;
77
 	int ongoing_rc;
93
 	int ongoing_rc;
78
 	int key;
94
 	int key;
79
 	int rc;
95
 	int rc;
123
 		/* Display progress, if applicable */
139
 		/* Display progress, if applicable */
124
 		elapsed = ( now - last_display );
140
 		elapsed = ( now - last_display );
125
 		if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
141
 		if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
126
-			if ( shown_percentage )
127
-				printf ( "\b\b\b\b    \b\b\b\b" );
142
+			monojob_clear ( clear_len );
128
 			/* Normalise progress figures to avoid overflow */
143
 			/* Normalise progress figures to avoid overflow */
129
 			scaled_completed = ( progress.completed / 128 );
144
 			scaled_completed = ( progress.completed / 128 );
130
 			scaled_total = ( progress.total / 128 );
145
 			scaled_total = ( progress.total / 128 );
131
 			if ( scaled_total ) {
146
 			if ( scaled_total ) {
132
 				percentage = ( ( 100 * scaled_completed ) /
147
 				percentage = ( ( 100 * scaled_completed ) /
133
 					       scaled_total );
148
 					       scaled_total );
134
-				printf ( "%3d%%", percentage );
135
-				shown_percentage = 1;
149
+				clear_len = printf ( "%3d%%", percentage );
136
 			} else {
150
 			} else {
137
 				printf ( "." );
151
 				printf ( "." );
138
-				shown_percentage = 0;
152
+				clear_len = 0;
153
+			}
154
+			if ( progress.message[0] ) {
155
+				clear_len += printf ( " [%s]",
156
+						      progress.message );
139
 			}
157
 			}
140
 			last_display = now;
158
 			last_display = now;
141
 		}
159
 		}
143
 	rc = monojob_rc;
161
 	rc = monojob_rc;
144
 	monojob_close ( &monojob, rc );
162
 	monojob_close ( &monojob, rc );
145
 
163
 
146
-	if ( shown_percentage )
147
-		printf ( "\b\b\b\b    \b\b\b\b" );
148
-
164
+	monojob_clear ( clear_len );
149
 	if ( string ) {
165
 	if ( string ) {
150
 		if ( rc ) {
166
 		if ( rc ) {
151
 			printf ( " %s\n", strerror ( rc ) );
167
 			printf ( " %s\n", strerror ( rc ) );

Loading…
Cancel
Save