diff options
author | Audun-Marius Gangstø <audun@gangsto.org> | 2020-11-21 12:26:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-21 17:34:42 +0100 |
commit | 9bf4499dd7c72db7636555ec386804540a3266fe (patch) | |
tree | 824c61d73006a355f0669434cc02ec2028ce79f5 | |
parent | 4323ac861ee5bb46051fada403971576356c928c (diff) | |
download | busybox-w32-9bf4499dd7c72db7636555ec386804540a3266fe.tar.gz busybox-w32-9bf4499dd7c72db7636555ec386804540a3266fe.tar.bz2 busybox-w32-9bf4499dd7c72db7636555ec386804540a3266fe.zip |
lineedit: fix unicode characters in prompt
function old new delta
parse_and_put_prompt 779 823 +44
Signed-off-by: Audun-Marius Gangstø <audun@gangsto.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/lineedit.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e40a72064..a3b798e3f 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2029,10 +2029,17 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
2029 | if (c == '\n') | 2029 | if (c == '\n') |
2030 | cmdedit_prmt_len = 0; | 2030 | cmdedit_prmt_len = 0; |
2031 | else if (flg_not_length != ']') { | 2031 | else if (flg_not_length != ']') { |
2032 | #if 0 /*ENABLE_UNICODE_SUPPORT*/ | 2032 | #if ENABLE_UNICODE_SUPPORT |
2033 | /* Won't work, pbuf is one BYTE string here instead of an one Unicode char string. */ | 2033 | if (n == 1) { |
2034 | /* FIXME */ | 2034 | /* Only count single-byte characters and the first of multi-byte characters */ |
2035 | cmdedit_prmt_len += unicode_strwidth(pbuf); | 2035 | if ((unsigned char)*pbuf < 0x80 /* single byte character */ |
2036 | || (unsigned char)*pbuf >= 0xc0 /* first of multi-byte characters */ | ||
2037 | ) { | ||
2038 | cmdedit_prmt_len += n; | ||
2039 | } | ||
2040 | } else { | ||
2041 | cmdedit_prmt_len += unicode_strwidth(pbuf); | ||
2042 | } | ||
2036 | #else | 2043 | #else |
2037 | cmdedit_prmt_len += n; | 2044 | cmdedit_prmt_len += n; |
2038 | #endif | 2045 | #endif |