aboutsummaryrefslogtreecommitdiff
path: root/src/wcwidth.h
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-06 11:44:47 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-20 12:43:55 +0200
commitdcd5d62501e61e0f6901d4d4687ab56430a4b8a7 (patch)
tree4501938052c0f62279eaae66c34811d4b5232fa2 /src/wcwidth.h
parent1d64b5790f26760cb830336ccca9d51474b73ae8 (diff)
downloadluasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.tar.gz
luasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.tar.bz2
luasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.zip
add example for reading a line from the terminal, non-blocking
Handles utf8, and character width
Diffstat (limited to 'src/wcwidth.h')
-rw-r--r--src/wcwidth.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wcwidth.h b/src/wcwidth.h
new file mode 100644
index 0000000..f2fee11
--- /dev/null
+++ b/src/wcwidth.h
@@ -0,0 +1,21 @@
1// wcwidth.h
2
3// Windows does not have a wcwidth function, so we use compatibilty code from
4// http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c by Markus Kuhn
5
6#ifndef MK_WCWIDTH_H
7#define MK_WCWIDTH_H
8
9
10#ifdef _WIN32
11#include <stdint.h>
12typedef uint32_t mk_wchar_t; // Windows wchar_t can be 16-bit, we need 32-bit
13#else
14#include <wchar.h>
15typedef wchar_t mk_wchar_t; // Posix wchar_t is 32-bit so just use that
16#endif
17
18int mk_wcwidth(mk_wchar_t ucs);
19int mk_wcswidth(const mk_wchar_t *pwcs, size_t n);
20
21#endif // MK_WCWIDTH_H