aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-10 12:44:25 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-10 12:44:25 +0200
commit49196eba130b3ab4f0939f13d071aef3d0a70eab (patch)
tree4d3f5d95dac9a8d01677ed66245f18796c63f695
parente46158f31369b8b16ed9ea3885b9def08afc4a55 (diff)
downloadvis-49196eba130b3ab4f0939f13d071aef3d0a70eab.tar.gz
vis-49196eba130b3ab4f0939f13d071aef3d0a70eab.tar.xz
Simplify drawing of the window statusbar
-rw-r--r--config.def.h22
-rw-r--r--editor.c10
-rw-r--r--editor.h6
-rw-r--r--vis.c2
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);
}
}
diff --git a/editor.c b/editor.c
index 1371812..c2aa585 100644
--- a/editor.c
+++ b/editor.c
@@ -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;
}
diff --git a/editor.h b/editor.h
index 388f8d5..2f47b52 100644
--- a/editor.h
+++ b/editor.h
@@ -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 */
diff --git a/vis.c b/vis.c
index 3aefc9a..a6b5d12 100644
--- a/vis.c
+++ b/vis.c
@@ -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 {