aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-12 16:42:12 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-12 17:38:40 +0200
commitad1cea9e79f191d6efb8ba7ba183c94c63e56e37 (patch)
tree03f6b36b1383ff6aded36e6d4bd0453d5a45ace3
parentec7be68e7b0250fd366fc512e18a50e460aeed31 (diff)
downloadvis-ad1cea9e79f191d6efb8ba7ba183c94c63e56e37.tar.gz
vis-ad1cea9e79f191d6efb8ba7ba183c94c63e56e37.tar.xz
Add facility to display a message to the user
-rw-r--r--editor.c29
-rw-r--r--editor.h5
2 files changed, 33 insertions, 1 deletions
diff --git a/editor.c b/editor.c
index bc3cbaa..c228f0e 100644
--- a/editor.c
+++ b/editor.c
@@ -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)
diff --git a/editor.h b/editor.h
index 1b94d78..ef1b4d3 100644
--- a/editor.h
+++ b/editor.h
@@ -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*));