aboutsummaryrefslogtreecommitdiff
path: root/ui-terminal.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-03-16 21:53:42 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-03-16 22:51:55 +0100
commitc6557f5e8778dc7adf867c74b30c8cbe5951be66 (patch)
tree57e0c7a2e4da960f880feb8b874c68a62e73a319 /ui-terminal.c
parent1b68cf418d8a3b97a68b46faf09d3dd84e8dd3ed (diff)
downloadvis-c6557f5e8778dc7adf867c74b30c8cbe5951be66.tar.gz
vis-c6557f5e8778dc7adf867c74b30c8cbe5951be66.tar.xz
ui: further cleanup display code
Diffstat (limited to 'ui-terminal.c')
-rw-r--r--ui-terminal.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/ui-terminal.c b/ui-terminal.c
index fd8e126..0f341e5 100644
--- a/ui-terminal.c
+++ b/ui-terminal.c
@@ -98,7 +98,6 @@ static void ui_window_move(UiTermWin *win, int x, int y) {
win->y = y;
}
-/* Convert color from string. */
static bool color_fromstring(UiTerm *ui, CellColor *color, const char *s)
{
if (!s)
@@ -122,7 +121,7 @@ static bool color_fromstring(UiTerm *ui, CellColor *color, const char *s)
return true;
}
- struct {
+ static const struct {
const char *name;
CellColor color;
} color_names[] = {
@@ -345,11 +344,11 @@ static void ui_draw(Ui *ui) {
debug("ui-draw\n");
UiTerm *tui = (UiTerm*)ui;
ui_arrange(ui, tui->layout);
-
for (UiTermWin *win = tui->windows; win; win = win->next)
ui_window_draw((UiWin*)win);
if (tui->info[0])
ui_draw_string(tui, 0, tui->height-1, tui->info, NULL, UI_STYLE_INFO);
+ ui_term_backend_blit(tui);
}
static void ui_redraw(Ui *ui) {
@@ -359,44 +358,33 @@ static void ui_redraw(Ui *ui) {
view_dirty(win->win->view);
}
-static bool ui_resize_to(Ui *ui, int width, int height) {
+static void ui_resize(Ui *ui) {
UiTerm *tui = (UiTerm*)ui;
+ struct winsize ws;
+ int width = 80, height = 24;
+
+ if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) != -1) {
+ width = ws.ws_col;
+ height = ws.ws_row;
+ }
+
width = MAX(width, 1);
width = MIN(width, MAX_WIDTH);
height = MAX(height, 1);
height = MIN(height, MAX_HEIGHT);
- ui_term_backend_resize(tui, width, height);
+ if (!ui_term_backend_resize(tui, width, height))
+ return;
+
size_t size = width*height*sizeof(Cell);
if (size > tui->cells_size) {
Cell *cells = realloc(tui->cells, size);
if (!cells)
- return false;
+ return;
tui->cells_size = size;
tui->cells = cells;
}
tui->width = width;
tui->height = height;
- ui_draw(ui);
- return true;
-}
-
-static void ui_resize(Ui *ui) {
- struct winsize ws;
- int width = 80, height = 24;
-
- if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) != -1) {
- width = ws.ws_col;
- height = ws.ws_row;
- }
-
- ui_resize_to(ui, width, height);
-}
-
-static void ui_update(Ui *ui) {
- debug("ui-doupdate\n");
- UiTerm *tui = (UiTerm*)ui;
- ui_draw(ui);
- ui_term_backend_blit(tui);
}
static void ui_window_free(UiWin *w) {
@@ -448,7 +436,6 @@ static void ui_window_options_set(UiWin *w, enum UiOption options) {
win->next = NULL;
}
}
-
ui_draw((Ui*)win->ui);
}
@@ -566,15 +553,12 @@ static void ui_info(Ui *ui, const char *msg, va_list ap) {
UiTerm *tui = (UiTerm*)ui;
ui_draw_line(tui, 0, tui->height-1, ' ', UI_STYLE_INFO);
vsnprintf(tui->info, sizeof(tui->info), msg, ap);
- ui_draw(ui);
}
static void ui_info_hide(Ui *ui) {
UiTerm *tui = (UiTerm*)ui;
- if (tui->info[0]) {
+ if (tui->info[0])
tui->info[0] = '\0';
- ui_draw(ui);
- }
}
static TermKey *ui_termkey_new(int fd) {
@@ -700,7 +684,6 @@ Ui *ui_term_new(void) {
.suspend = ui_suspend,
.resume = ui_resume,
.resize = ui_resize,
- .update = ui_update,
.window_new = ui_window_new,
.window_free = ui_window_free,
.window_focus = ui_window_focus,