mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-18 17:15:09 -04:00
Improve printf to handle minimum width
This commit is contained in:
parent
9f55ac3f53
commit
aa71717c4c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user