summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-11-02 17:35:30 +0100
committerMichal Schmidt <mschmidt@redhat.com>2012-11-02 17:39:52 +0100
commitc339d9775d1df19fdbbafc57486f7cd51af6b7fb (patch)
treee0689a930c57e861641308340165d9f7431ab24e /src/shared/util.c
parent0901758558506273c0b7553dc3cae587f2b94290 (diff)
util : fallback to plain ASCII drawing if locale is not UTF-8
When printing cgroup and sysfs hierarchies, avoid using UTF-8 box drawing characters if the locale is not UTF-8. https://bugzilla.redhat.com/show_bug.cgi?id=871153
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 3ac67505f0..2a8afae0ec 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6140,3 +6140,22 @@ bool is_locale_utf8(void) {
out:
return (bool)cached_answer;
}
+
+const char *draw_special_char(DrawSpecialChar ch) {
+ static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = {
+ /* UTF-8 */ {
+ [DRAW_BOX_VERT] = "\342\224\202", /* │ */
+ [DRAW_BOX_VERT_AND_RIGHT] = "\342\224\234", /* ├ */
+ [DRAW_BOX_UP_AND_RIGHT] = "\342\224\224", /* └ */
+ [DRAW_TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */
+ },
+ /* ASCII fallback */ {
+ [DRAW_BOX_VERT] = "|",
+ [DRAW_BOX_VERT_AND_RIGHT] = "+",
+ [DRAW_BOX_UP_AND_RIGHT] = "\\",
+ [DRAW_TRIANGULAR_BULLET] = ">",
+ }
+ };
+
+ return draw_table[!is_locale_utf8()][ch];
+}