supercrabtree / k

k is the new l, yo
1.78k stars 123 forks source link

Workaround zsh/stat bug causing garbage display with utf characters #87

Closed kepi closed 5 years ago

kepi commented 5 years ago

zstat isn't probably able to render UTF characters returned from strftime. There is abbreviated month name respecting locales setting used in format string.

It would be great to fix this somehow in ZSH, but for now using English locales seams to be reasonable workaround. English abbr. month looks better in output then month number.

You can problem in attached picture. First rectangle shows wrong encoding/display issue, second is how it should be displayed (and is also confirming that my terminal is utf capable ;) )

k_zstat_locale_problem

ratijas commented 5 years ago

+1

Getting something similar to your screenshot on russian locale.

ratijas commented 5 years ago

Figured out, it's zsh bug in zstat built-in command (Src/Modules/stat.c:200). I haven't located exact line of code yet, but it''s fun to explore anyway. For example, from link above:

    char *oend = outbuf + strlen(outbuf);
    /* Where the heck does "40" come from? */
    int len = ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
               localtime(&tim), nsecs);

My verdict: this issue should be closed as unrelated.

ratijas commented 5 years ago

Update: I've successfully located and fixed double-escape error where zsh special meta chars were replaces twice in a row. Submitting a patch right away...

diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c
index 50a6a9bb2..ed75ea691 100644
--- a/Src/Modules/stat.c
+++ b/Src/Modules/stat.c
@@ -200,8 +200,6 @@ stattimeprint(time_t tim, long nsecs, char *outbuf, int flags)
        /* Where the heck does "40" come from? */
        int len = ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
                           localtime(&tim), nsecs);
- if (len > 0)
- metafy(oend, len, META_NOALLOC);
        if (flags & STF_RAW)
            strcat(oend, ")");
     }
ratijas commented 5 years ago

Fixed in https://github.com/zsh-users/zsh/commit/e258e7d251b7403a6d77b23e6927b659bf9c2c37. Please, close this issue. @kepi @supercrabtree