diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-17 13:02:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-17 13:05:39 +0200 |
commit | cc42d75209424bc6fcaecbf82b95d980863de7f1 (patch) | |
tree | d3c860041c108fd2b2c1c6a414d6977b584f04c5 /Userland/ls.cpp | |
parent | 6cde7e4d20be4f244da16ab9f354628588964d1c (diff) | |
download | serenity-cc42d75209424bc6fcaecbf82b95d980863de7f1.zip |
ls: Make column alignment Unicode-aware :^)
You can now have emojis in file names and they will line up correctly
in "ls" output.
Diffstat (limited to 'Userland/ls.cpp')
-rw-r--r-- | Userland/ls.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Userland/ls.cpp b/Userland/ls.cpp index d1207203b8..665715ca49 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -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]); |