mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Userland: Improved the printing of the ls command. (#468)
The ls command takes into consideration the length of the largest filename when it prints a line. Fixes #432.
This commit is contained in:
parent
3792c91059
commit
91c79440a1
Notes:
sideshowbarker
2024-07-19 12:35:46 +09:00
Author: https://github.com/marprok Commit: https://github.com/SerenityOS/serenity/commit/91c79440a19 Pull-request: https://github.com/SerenityOS/serenity/pull/468
1 changed files with 8 additions and 6 deletions
|
@ -265,7 +265,6 @@ int do_file_system_object_short(const char* path)
|
|||
|
||||
int printed_on_row = 0;
|
||||
int nprinted;
|
||||
|
||||
for (int i = 0; i < names.size(); ++i) {
|
||||
auto& name = names[i];
|
||||
char pathbuf[256];
|
||||
|
@ -273,19 +272,22 @@ int do_file_system_object_short(const char* path)
|
|||
|
||||
if (!print_filesystem_object_short(pathbuf, name.characters(), &nprinted))
|
||||
return 2;
|
||||
int column_width = 14;
|
||||
int offset = columns % longest_name / (columns / longest_name);
|
||||
/* The offset must be at least 2 because:
|
||||
* - With each file an aditional char is printed e.g. '@','*'.
|
||||
* - Each filename must be separated by a space.
|
||||
*/
|
||||
int column_width = longest_name + (offset > 0 ? offset : 2);
|
||||
printed_on_row += column_width;
|
||||
|
||||
for (int i = nprinted; i < column_width; ++i)
|
||||
for (int j = nprinted; i != (names.size() - 1) && j < column_width; ++j)
|
||||
printf(" ");
|
||||
if ((printed_on_row + column_width) >= columns) {
|
||||
if (i != names.size() - 1)
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
printed_on_row = 0;
|
||||
}
|
||||
}
|
||||
if (printed_on_row)
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue