Skip to content

Commit

Permalink
ui: make statusbar configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jan 13, 2016
1 parent bd51cd0 commit 8ca992e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 13 additions & 9 deletions ui-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,14 @@ static void ui_window_options_set(UiWin *w, enum UiOption options) {
win->sidebar_width = 0;
}
}
if (options & UI_OPTION_STATUSBAR) {
if (!win->winstatus)
win->winstatus = newwin(1, 0, 0, 0);
} else {
if (win->winstatus)
delwin(win->winstatus);
win->winstatus = NULL;
}
ui_window_draw(w);
}

Expand All @@ -879,7 +887,7 @@ static enum UiOption ui_window_options_get(UiWin *w) {
return win->options;
}

static UiWin *ui_window_new(Ui *ui, View *view, File *file) {
static UiWin *ui_window_new(Ui *ui, View *view, File *file, enum UiOption options) {
UiCurses *uic = (UiCurses*)ui;
UiCursesWin *win = calloc(1, sizeof(UiCursesWin));
if (!win)
Expand All @@ -894,7 +902,7 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file) {
.syntax_style = ui_window_syntax_style,
};

if (!(win->win = newwin(0, 0, 0, 0)) || !(win->winstatus = newwin(1, 0, 0, 0))) {
if (!(win->win = newwin(0, 0, 0, 0))) {
ui_window_free((UiWin*)win);
return NULL;
}
Expand Down Expand Up @@ -922,6 +930,8 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file) {
win->next = uic->windows;
uic->windows = win;

ui_window_options_set((UiWin*)win, options);

return &win->uiwin;
}

Expand Down Expand Up @@ -952,19 +962,13 @@ static UiWin *ui_prompt_new(Ui *ui, View *view, File *file) {
UiCurses *uic = (UiCurses*)ui;
if (uic->prompt_win)
return (UiWin*)uic->prompt_win;
UiWin *uiwin = ui_window_new(ui, view, file);
UiWin *uiwin = ui_window_new(ui, view, file, UI_OPTION_NONE);
UiCursesWin *win = (UiCursesWin*)uiwin;
if (!win)
return NULL;
uic->windows = win->next;
if (uic->windows)
uic->windows->prev = NULL;
if (win->winstatus)
delwin(win->winstatus);
if (win->winside)
delwin(win->winside);
win->winstatus = NULL;
win->winside = NULL;
uic->prompt_win = win;
return uiwin;
}
Expand Down
4 changes: 3 additions & 1 deletion ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum UiLayout {
};

enum UiOption {
UI_OPTION_NONE = 0,
UI_OPTION_LINE_NUMBERS_ABSOLUTE = 1 << 0,
UI_OPTION_LINE_NUMBERS_RELATIVE = 1 << 1,
UI_OPTION_SYMBOL_SPACE = 1 << 2,
Expand All @@ -22,6 +23,7 @@ enum UiOption {
UI_OPTION_SYMBOL_EOL = 1 << 5,
UI_OPTION_SYMBOL_EOF = 1 << 6,
UI_OPTION_CURSOR_LINE = 1 << 7,
UI_OPTION_STATUSBAR = 1 << 8,
};

enum UiStyles {
Expand All @@ -43,7 +45,7 @@ struct Ui {
bool (*init)(Ui*, Vis*);
void (*free)(Ui*);
void (*resize)(Ui*);
UiWin* (*window_new)(Ui*, View*, File*);
UiWin* (*window_new)(Ui*, View*, File*, enum UiOption);
void (*window_free)(UiWin*);
void (*window_focus)(UiWin*);
UiWin* (*prompt_new)(Ui*, View*, File*);
Expand Down
2 changes: 1 addition & 1 deletion vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static Win *window_new_file(Vis *vis, File *file) {
win->file = file;
win->jumplist = ringbuf_alloc(31);
win->view = view_new(file->text, vis->lua);
win->ui = vis->ui->window_new(vis->ui, win->view, file);
win->ui = vis->ui->window_new(vis->ui, win->view, file, UI_OPTION_STATUSBAR);
if (!win->jumplist || !win->view || !win->ui) {
window_free(win);
return NULL;
Expand Down

0 comments on commit 8ca992e

Please sign in to comment.