diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-06-06 12:31:12 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-06-06 12:31:12 -0700 |
commit | 7b5b105d84103d4320de510f0fdab345b5d2f477 (patch) | |
tree | 79f2dc2b08f83e2fc52f3a9cd294e79b36951b86 /sys/cmd/term/util.c | |
parent | e02e1403b432f8cd6d07ebbdd235627f20f01cfb (diff) |
added fork of st
Diffstat (limited to 'sys/cmd/term/util.c')
-rw-r--r-- | sys/cmd/term/util.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/cmd/term/util.c b/sys/cmd/term/util.c new file mode 100644 index 0000000..3e7d81b --- /dev/null +++ b/sys/cmd/term/util.c @@ -0,0 +1,30 @@ +#include <u.h> + +static const uchar table[] = { +#include "nonspacing.h" +}; + +static const uchar wtable[] = { +#include "wide.h" +}; + +int +wcwidth(wchar_t wc) +{ + if (wc < 0xffU) + return (wc+1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0; + if ((wc & 0xfffeffffU) < 0xfffe) { + if ((table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) + return 0; + if ((wtable[wtable[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) + return 2; + return 1; + } + if ((wc & 0xfffe) == 0xfffe) + return -1; + if (wc-0x20000U < 0x20000) + return 2; + if (wc == 0xe0001 || wc-0xe0020U < 0x5f || wc-0xe0100U < 0xef) + return 0; + return 1; +} |