diff options
| author | 2024-09-07 12:35:15 -0400 | |
|---|---|---|
| committer | 2024-09-07 12:35:15 -0400 | |
| commit | 29c052c9470cfde967c5a3965cd079c5ee8dbb66 (patch) | |
| tree | 1a42daf635def6a1ad6e568db29963ba1b3a1eea /src/lush.c | |
| parent | added API guide to readme (diff) | |
fixed bug with cursor alignment when adding text within the buffer
Diffstat (limited to '')
| -rw-r--r-- | src/lush.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -210,6 +210,10 @@ static void reprint_buffer(char *buffer, int *last_lines, int *pos, // move cursor down if it is up a number of lines first if (num_lines - cursor_line > 0) { printf("\033[%dB", num_lines - cursor_line); + // compensate for if the we have just filled a line + if ((strlen(buffer) + strlen(prompt) + 1) % width == 0) { + printf("\033[A"); + } } for (int i = 0; i < *last_lines; i++) { printf("\r\033[K"); @@ -327,7 +331,13 @@ char *lush_read_line() { strlen(&buffer[pos]) + 1); buffer[pos] = c; pos++; - + // handle edge case where cursor should be moved down + int width = get_terminal_width(); + char *prompt = get_prompt(); + if ((strlen(prompt) + pos) % width == width - 1 && + pos < strlen(buffer)) { + printf("\033[B"); + } // if modifying text reset history history_pos = -1; reprint_buffer(buffer, &last_lines, &pos, history_pos); |
