From cc42d75209424bc6fcaecbf82b95d980863de7f1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 17 May 2020 13:02:48 +0200 Subject: [PATCH] ls: Make column alignment Unicode-aware :^) You can now have emojis in file names and they will line up correctly in "ls" output. --- Userland/ls.cpp | 7 +++++++ 1 file changed, 7 insertions(+) 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 #include #include +#include #include #include #include @@ -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]);