commit 7e453498215cc620402a449e6e34c0838b6320ad
parent 8b3dc609fa41e9625aab36f45de8c1c07c047aa7
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 19 Feb 2022 11:43:24 +0000
backspace
Diffstat:
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/richterm.c b/richterm.c
@@ -243,15 +243,22 @@ threadmain(int argc, char **argv)
&rich);
break;
}
- if (kv == 0x08) { /* backspace */
- break;
- }
if (elems->count > 0) {
char *str;
-
- if (kv == '\n') {
- Elem *e;
-
+ int ul;
+ Rune *R;
+ Elem *e;
+
+ if (kv == 0x08) { /* backspace */
+ if ((euser->count == 0) || (euser->str == nil)) break;
+ ul = utfnlen(euser->str, euser->count);
+ R = mallocz(sizeof(Rune) * ul, 1);
+ runesnprint(R, ul, "%s", euser->str);
+ free(euser->str);
+ euser->str = smprint("%S", R);
+ euser->count = strlen(euser->str);
+ free(R);
+ } else if (kv == '\n') {
str = smprint("%c%s\n" "n\n", euser->type, euser->str);
arraygrow(richdata, strlen(str), str);