Single line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */
| 2065 | * Rewrite the currently edited line accordingly to the buffer content, |
| 2066 | * cursor position, and number of columns of the terminal. */ |
| 2067 | static void refreshSingleLine(struct linenoiseState* l) { |
| 2068 | if (!l->render) { |
| 2069 | return; |
| 2070 | } |
| 2071 | |
| 2072 | char seq[64]; |
| 2073 | uint32_t plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt)); |
| 2074 | int fd = l->ofd; |
| 2075 | char buf[LINENOISE_MAX_LINE]; |
| 2076 | size_t len = l->len; |
| 2077 | size_t pos = l->pos; |
| 2078 | size_t chars = l->totalUTF8Chars; |
| 2079 | AppendBuffer append_buffer; |
| 2080 | size_t renderPos = 0; |
| 2081 | |
| 2082 | truncateText(l->buf, len, pos, l->cols, plen, highlightEnabled, renderPos, buf); |
| 2083 | |
| 2084 | /* Cursor to left edge */ |
| 2085 | snprintf(seq, 64, "\r"); |
| 2086 | append_buffer.abAppend(seq); |
| 2087 | |
| 2088 | append_buffer.abAppend("\033[0m"); // reset all attributes |
| 2089 | |
| 2090 | /* Write the prompt and the current buffer content */ |
| 2091 | append_buffer.abAppend(l->prompt); |
| 2092 | if (maskmode == 1) { |
| 2093 | while (chars--) |
| 2094 | append_buffer.abAppend("*"); |
| 2095 | } else { |
| 2096 | append_buffer.abAppend(buf, len); |
| 2097 | } |
| 2098 | /* Show hits if any. */ |
| 2099 | refreshShowHints(append_buffer, l, plen); |
| 2100 | /* Erase to right */ |
| 2101 | snprintf(seq, 64, "\x1b[0K"); |
| 2102 | append_buffer.abAppend(seq); |
| 2103 | /* Move cursor to original position. */ |
| 2104 | snprintf(seq, 64, "\r\x1b[%dC", (int)(renderPos + plen)); |
| 2105 | append_buffer.abAppend(seq); |
| 2106 | |
| 2107 | append_buffer.abWrite(fd); |
| 2108 | } |
| 2109 | |
| 2110 | bool isNewline(char c) { |
| 2111 | return c == '\n' || c == '\r'; |
no test coverage detected