diff options
author | Paul Fertser <fercerpav@gmail.com> | 2022-04-11 13:43:22 +0300 |
---|---|---|
committer | Paul Fertser <fercerpav@gmail.com> | 2022-04-12 12:17:36 +0300 |
commit | 8e728fee157ea96bb6e96a485a11d5a638bd6c98 (patch) | |
tree | 903d43acb7a5578af571effe35c508203c27856a | |
parent | ccede06a658bf609ba5cf5b536740d4983b02603 (diff) | |
download | profani-tty-8e728fee157ea96bb6e96a485a11d5a638bd6c98.tar.gz |
Show return symbol for embedded newlines
When editing multi-line messages or comments everything past the first newline becomes invisible. This patch fixes it by substituting a Unicode symbol for "return" instead of printing the newline as is. On locales where it's not available single backslash is used instead.
-rw-r--r-- | src/ui/inputwin.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 60a0e36f..caab9ff1 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -328,7 +328,30 @@ _inp_write(char* line, int offset) getyx(inp_win, y, x); col += x; - waddstr(inp_win, line); + for (size_t i = 0; line[i] != '\0'; i++) { + char* c = &line[i]; + char retc[MB_CUR_MAX]; + + size_t ch_len = mbrlen(c, MB_CUR_MAX, NULL); + if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) { + waddch(inp_win, ' '); + continue; + } + + if (line[i] == '\n') { + c = retc; + ch_len = wctomb(retc, L'\u23ce'); /* return symbol */ + if (ch_len == -1) { /* not representable */ + retc[0] = '\\'; + ch_len = 1; + } + } else { + i += ch_len - 1; + } + + waddnstr(inp_win, c, ch_len); + } + wmove(inp_win, 0, col); _inp_win_handle_scroll(); |