diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-02-23 00:37:47 -0500 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-02-23 00:37:47 -0500 |
| commit | 3add5ed8899a8f4a442c249913602de6b7d60732 (patch) | |
| tree | e4f864b1f4d41aa258c8b678b00a7d9ed69640f7 /src/Draw.c | |
| download | insel-3add5ed8899a8f4a442c249913602de6b7d60732.tar.gz | |
billions must commit
Diffstat (limited to 'src/Draw.c')
| -rw-r--r-- | src/Draw.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Draw.c b/src/Draw.c new file mode 100644 index 0000000..1132f10 --- /dev/null +++ b/src/Draw.c @@ -0,0 +1,49 @@ +#include <string.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdio.h> + +#include "Globals.h" +#include "Terminal.h" +#include "Draw.h" + +void draw(void) { + int rows, cols; + struct winsize w; + ioctl(tty_out_fd, TIOCGWINSZ, &w); + rows = w.ws_row; + cols = w.ws_col; + + if (rows < 1) rows = 24; + if (cols < 1) cols = 80; + + int prompt_len = strlen(opts.prompt); + int input_pos = prompt_len + 2; + int filter_line = rows; + int item_end = rows - 1; + + dprintf(tty_out_fd, "\033[H\033[J"); + + dprintf(tty_out_fd, "\033[%d;1H", filter_line); + dprintf(tty_out_fd, "\033[7m"); + dprintf(tty_out_fd, "%-*s", cols, ""); + dprintf(tty_out_fd, "\033[%d;1H", filter_line); + dprintf(tty_out_fd, "%s", opts.prompt); + if (input_len > 0) { + dprintf(tty_out_fd, " %s", input); + } + dprintf(tty_out_fd, "\033[0m"); + + for (int i = 1; i < item_end; i++) { + int idx = i - 1 + scroll; + dprintf(tty_out_fd, "\033[%d;1H", i); + if (idx < (int)filtered.count) { + if (idx == cursor) { + dprintf(tty_out_fd, "\033[7m"); + } + dprintf(tty_out_fd, "%s\033[0m", filtered.items[idx]); + } + } + dprintf(tty_out_fd, "\033[%d;%dH", filter_line, input_pos); + fsync(tty_out_fd); +} |
