ls: Make column alignment Unicode-aware :^)

You can now have emojis in file names and they will line up correctly
in "ls" output.
This commit is contained in:
Andreas Kling 2020-05-17 13:02:48 +02:00
parent 6cde7e4d20
commit cc42d75209
Notes: sideshowbarker 2024-07-19 06:33:54 +09:00

View file

@ -28,6 +28,7 @@
#include <AK/QuickSort.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
@ -134,6 +135,12 @@ int print_escaped(const char* name)
{
int printed = 0;
Utf8View utf8_name(name);
if (utf8_name.validate()) {
printf("%s", name);
return utf8_name.length_in_codepoints();
}
for (int i = 0; name[i] != '\0'; i++) {
if (isprint(name[i])) {
putchar(name[i]);