|  | @@ -55,6 +55,22 @@ static struct interface_descriptor monojob_intf_desc =
 | 
		
	
		
			
			| 55 | 55 |  
 | 
		
	
		
			
			| 56 | 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 | 75 |   * Wait for single foreground job to complete
 | 
		
	
		
			
			| 60 | 76 |   *
 | 
		
	
	
		
			
			|  | @@ -73,7 +89,7 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
 | 
		
	
		
			
			| 73 | 89 |  	unsigned long scaled_completed;
 | 
		
	
		
			
			| 74 | 90 |  	unsigned long scaled_total;
 | 
		
	
		
			
			| 75 | 91 |  	unsigned int percentage;
 | 
		
	
		
			
			| 76 |  | -	int shown_percentage = 0;
 | 
		
	
		
			
			|  | 92 | +	size_t clear_len = 0;
 | 
		
	
		
			
			| 77 | 93 |  	int ongoing_rc;
 | 
		
	
		
			
			| 78 | 94 |  	int key;
 | 
		
	
		
			
			| 79 | 95 |  	int rc;
 | 
		
	
	
		
			
			|  | @@ -123,19 +139,21 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
 | 
		
	
		
			
			| 123 | 139 |  		/* Display progress, if applicable */
 | 
		
	
		
			
			| 124 | 140 |  		elapsed = ( now - last_display );
 | 
		
	
		
			
			| 125 | 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 | 143 |  			/* Normalise progress figures to avoid overflow */
 | 
		
	
		
			
			| 129 | 144 |  			scaled_completed = ( progress.completed / 128 );
 | 
		
	
		
			
			| 130 | 145 |  			scaled_total = ( progress.total / 128 );
 | 
		
	
		
			
			| 131 | 146 |  			if ( scaled_total ) {
 | 
		
	
		
			
			| 132 | 147 |  				percentage = ( ( 100 * scaled_completed ) /
 | 
		
	
		
			
			| 133 | 148 |  					       scaled_total );
 | 
		
	
		
			
			| 134 |  | -				printf ( "%3d%%", percentage );
 | 
		
	
		
			
			| 135 |  | -				shown_percentage = 1;
 | 
		
	
		
			
			|  | 149 | +				clear_len = printf ( "%3d%%", percentage );
 | 
		
	
		
			
			| 136 | 150 |  			} else {
 | 
		
	
		
			
			| 137 | 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 | 158 |  			last_display = now;
 | 
		
	
		
			
			| 141 | 159 |  		}
 | 
		
	
	
		
			
			|  | @@ -143,9 +161,7 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
 | 
		
	
		
			
			| 143 | 161 |  	rc = monojob_rc;
 | 
		
	
		
			
			| 144 | 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 | 165 |  	if ( string ) {
 | 
		
	
		
			
			| 150 | 166 |  		if ( rc ) {
 | 
		
	
		
			
			| 151 | 167 |  			printf ( " %s\n", strerror ( rc ) );
 |