Improve printf to handle minimum width

This commit is contained in:
Baptiste Wicht 2013-11-02 21:21:03 +01:00
parent 9f55ac3f53
commit aa71717c4c
2 changed files with 22 additions and 1 deletions

View File

@ -136,6 +136,14 @@ void k_printf(const char* fmt, ...){
} else {
ch = *(fmt++);
std::size_t min_width = 0;
while(ch >= '0' && ch <= '9'){
min_width = 10 * min_width + (ch - '0');
ch = *(fmt++);
}
auto prev = current_column;
if(ch == 'd'){
auto arg = va_arg(va, std::size_t);
k_print(arg);
@ -188,6 +196,19 @@ void k_printf(const char* fmt, ...){
auto arg = va_arg(va, const char*);
k_print(arg);
}
if(min_width > 0){
auto width = current_column - prev;
if(min_width > width){
min_width -= width;
while(min_width > 0){
k_print(' ');
--min_width;
}
}
}
}
}

View File

@ -278,7 +278,7 @@ void disks_command(const char*){
for(std::size_t i = 0; i < number_of_disks(); ++i){
auto& descriptor = drive(i);
k_printf("%h %h %s\n", descriptor.controller, descriptor.drive, descriptor.present ? "Yes" : "No");
k_printf("%12h %8h %s\n", descriptor.controller, descriptor.drive, descriptor.present ? "Yes" : "No");
}
}