#include #include #include #include #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); }