vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 1dafe4ac773e8cc376ba2f3fb71067fcf9cd6d81
parent 869ec48ee5f9946d4188ae0b91c7135c87bb8aba
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 21 May 2016 13:01:22 +0200

vis: add functions to query window size

Diffstat:
Mui-curses.c | 10++++++++++
Mui.h | 2++
Mvis.c | 8++++++++
Mvis.h | 3+++
4 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/ui-curses.c b/ui-curses.c @@ -938,6 +938,14 @@ static enum UiOption ui_window_options_get(UiWin *w) { return win->options; } +static int ui_window_width(UiWin *win) { + return ((UiCursesWin*)win)->width; +} + +static int ui_window_height(UiWin *win) { + return ((UiCursesWin*)win)->height; +} + static void ui_window_swap(UiWin *aw, UiWin *bw) { UiCursesWin *a = (UiCursesWin*)aw; UiCursesWin *b = (UiCursesWin*)bw; @@ -981,6 +989,8 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file, enum UiOption option .options_get = ui_window_options_get, .reload = ui_window_reload, .syntax_style = ui_window_syntax_style, + .window_width = ui_window_width, + .window_height = ui_window_height, }; if (!(win->win = newwin(0, 0, 0, 0))) { diff --git a/ui.h b/ui.h @@ -80,6 +80,8 @@ struct UiWin { void (*options_set)(UiWin*, enum UiOption); enum UiOption (*options_get)(UiWin*); bool (*syntax_style)(UiWin*, int id, const char *style); + int (*window_width)(UiWin*); + int (*window_height)(UiWin*); }; #endif diff --git a/vis.c b/vis.c @@ -268,6 +268,14 @@ bool vis_window_syntax_set(Win *win, const char *syntax) { return !syntax || win->lexer_name; } +int vis_window_width_get(const Win *win) { + return win->ui->window_width(win->ui); +} + +int vis_window_height_get(const Win *win) { + return win->ui->window_height(win->ui); +} + void vis_draw(Vis *vis) { vis->ui->draw(vis->ui); } diff --git a/vis.h b/vis.h @@ -104,6 +104,9 @@ void vis_window_swap(Win*, Win*); const char *vis_window_syntax_get(Win*); bool vis_window_syntax_set(Win*, const char *name); +int vis_window_width_get(const Win*); +int vis_window_height_get(const Win*); + /* display a user prompt with a certain title and default text */ void vis_prompt_show(Vis*, const char *title);