diff options
| -rw-r--r-- | editor.c | 29 | ||||
| -rw-r--r-- | editor.h | 5 |
2 files changed, 33 insertions, 1 deletions
@@ -1,6 +1,7 @@ #define _BSD_SOURCE #include <stdlib.h> #include <string.h> +#include <stdarg.h> #include <unistd.h> #include "editor.h" #include "util.h" @@ -32,6 +33,7 @@ static void editor_prompt_resize(Prompt *prompt, int width, int height); static void editor_prompt_move(Prompt *prompt, int x, int y); static void editor_prompt_draw(Prompt *prompt); static void editor_prompt_update(Prompt *prompt); +static void editor_info_draw(Editor *ed); static void editor_window_resize(EditorWin *win, int width, int height) { window_resize(win->win, width, win->statuswin ? height - 1 : height); @@ -147,7 +149,9 @@ void editor_window_vsplit(Editor *ed, const char *filename) { void editor_resize(Editor *ed, int width, int height) { ed->width = width; ed->height = height; - if (ed->prompt->active) { + if (ed->info[0]) { + ed->height--; + } else if (ed->prompt->active) { ed->height--; editor_prompt_resize(ed->prompt, ed->width, 1); editor_prompt_move(ed->prompt, 0, ed->height); @@ -246,6 +250,8 @@ void editor_draw(Editor *ed) { } editor_window_draw(ed->win); } + if (ed->info[0]) + editor_info_draw(ed); wnoutrefresh(stdscr); } @@ -520,6 +526,27 @@ char *editor_prompt_get(Editor *ed) { return buf; } +void editor_info_show(Editor *ed, const char *msg, ...) { + va_list ap; + va_start(ap, msg); + vsnprintf(ed->info, sizeof(ed->info), msg, ap); + va_end(ap); + editor_resize(ed, ed->width, ed->height); +} + +void editor_info_hide(Editor *ed) { + if (!ed->info[0]) + return; + ed->info[0] = '\0'; + ed->height++; + editor_draw(ed); +} + +static void editor_info_draw(Editor *ed) { + attrset(A_BOLD); + mvaddstr(ed->height, 0, ed->info); +} + static unsigned int color_hash(short fg, short bg) { if (fg == -1) @@ -95,6 +95,7 @@ struct Editor { Syntax *syntaxes; /* NULL terminated array of syntax definitions */ Register registers[REG_LAST]; /* register used for copy and paste */ Prompt *prompt; /* used to get user input */ + char info[255]; /* a user message currently being displayed */ Regex *search_pattern; /* last used search pattern */ void (*windows_arrange)(Editor*); /* current layout which places the windows */ void (*statusbar)(EditorWin*); /* configurable user hook to draw statusbar */ @@ -151,6 +152,10 @@ char *editor_prompt_get(Editor *vis); /* replace the current command line content with the one given */ void editor_prompt_set(Editor *vis, const char *line); +/* display a message to the user */ +void editor_info_show(Editor*, const char *msg, ...); +void editor_info_hide(Editor*); + /* register a callback which is called whenever the statusbar needs to * be redrawn */ void editor_statusbar_set(Editor*, void (*statusbar)(EditorWin*)); |
