diff options
| -rw-r--r-- | config.def.h | 22 | ||||
| -rw-r--r-- | editor.c | 10 | ||||
| -rw-r--r-- | editor.h | 6 | ||||
| -rw-r--r-- | vis.c | 2 |
4 files changed, 17 insertions, 23 deletions
diff --git a/config.def.h b/config.def.h index 49a87fd..7ae374d 100644 --- a/config.def.h +++ b/config.def.h @@ -61,19 +61,19 @@ static Command cmds[] = { { /* array terminator */ }, }; -/* draw a statubar, do whatever you want with the given curses window */ -static void statusbar(WINDOW *win, bool active, const char *filename, size_t line, size_t col) { - int width, height; - getmaxyx(win, height, width); - (void)height; - wattrset(win, active ? A_REVERSE|A_BOLD : A_REVERSE); - mvwhline(win, 0, 0, ' ', width); - mvwprintw(win, 0, 0, "%s", filename); - char buf[width + 1]; - int len = snprintf(buf, width, "%d, %d", line, col); +/* draw a statubar, do whatever you want with win->statuswin curses window */ +static void statusbar(EditorWin *win) { + size_t line, col; + window_cursor_getxy(win->win, &line, &col); + wattrset(win->statuswin, vis->win == win ? A_REVERSE|A_BOLD : A_REVERSE); + mvwhline(win->statuswin, 0, 0, ' ', win->width); + mvwprintw(win->statuswin, 0, 0, "%s %s", text_filename(win->text), + text_modified(win->text) ? "[+]" : ""); + char buf[win->width + 1]; + int len = snprintf(buf, win->width, "%d, %d", line, col); if (len > 0) { buf[len] = '\0'; - mvwaddstr(win, 0, width - len - 1, buf); + mvwaddstr(win->statuswin, 0, win->width - len - 1, buf); } } @@ -47,19 +47,15 @@ static void editor_window_move(EditorWin *win, int x, int y) { } static void editor_window_statusbar_draw(EditorWin *win) { - size_t line, col; - if (win->statuswin && win->editor->statusbar) { - window_cursor_getxy(win->win, &line, &col); - win->editor->statusbar(win->statuswin, win->editor->win == win, - text_filename(win->text), line, col); - } + if (win->statuswin && win->editor->statusbar) + win->editor->statusbar(win); } static void editor_window_cursor_moved(Win *win, void *data) { editor_window_statusbar_draw(data); } -void editor_statusbar_set(Editor *ed, editor_statusbar_t statusbar) { +void editor_statusbar_set(Editor *ed, void (*statusbar)(EditorWin*)) { ed->statusbar = statusbar; } @@ -28,8 +28,6 @@ typedef struct { bool active; /* whether the prompt is currently shown or not */ } Prompt; -typedef void (*editor_statusbar_t)(WINDOW *win, bool active, const char *filename, size_t line, size_t col); - enum Reg { REG_a, REG_b, @@ -99,7 +97,7 @@ struct Editor { Prompt *prompt; /* used to get user input */ Regex *search_pattern; /* last used search pattern */ void (*windows_arrange)(Editor*); /* current layout which places the windows */ - editor_statusbar_t statusbar; /* configurable user hook to draw statusbar */ + void (*statusbar)(EditorWin*); /* configurable user hook to draw statusbar */ bool running; /* (TODO move elsewhere?) */ }; @@ -149,7 +147,7 @@ void editor_prompt_set(Editor *vis, const char *line); void editor_prompt_show(Editor *vis, const char *title); void editor_prompt_hide(Editor *vis); -void editor_statusbar_set(Editor*, editor_statusbar_t); +void editor_statusbar_set(Editor*, void (*statusbar)(EditorWin*)); /* look up a curses color pair for the given combination of fore and * background color */ @@ -60,7 +60,7 @@ struct Mode { typedef struct { char *name; /* is used to match against argv[0] to enable this config */ Mode *mode; /* default mode in which the editor should start in */ - editor_statusbar_t statusbar; /* routine which is called whenever the cursor is moved within a window */ + void (*statusbar)(EditorWin*); /* routine which is called whenever the cursor is moved within a window */ } Config; typedef struct { |
