2 * Copyright (c) 2006-2011 Ed Schouten <ed@80386.nl>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * @brief Message logging for textual user interface.
34 #include "gui_internal.h"
37 * @brief Priority of the current message in the message bar.
39 static int message_prio
= 0;
41 * @brief Current message in the message bar.
43 static GString
*message
;
45 * @brief Window object of the message bar at the bottom of the screen.
47 static WINDOW
*win_msgbar
;
52 win_msgbar
= newwin(1, 0, GUI_SIZE_MSGBAR_TOP
, 0);
53 clearok(win_msgbar
, TRUE
);
55 wbkgdset(win_msgbar
, COLOR_PAIR(GUI_COLOR_BAR
));
57 wbkgdset(win_msgbar
, A_REVERSE
);
59 message
= g_string_sized_new(32);
61 /* Hide the cursor by default */
68 gui_msgbar_destroy(void)
70 g_string_free(message
, TRUE
);
76 gui_msgbar_resize(void)
79 wresize(win_msgbar
, 1, COLS
);
80 mvwin(win_msgbar
, GUI_SIZE_MSGBAR_TOP
, 0);
81 clearok(win_msgbar
, TRUE
);
88 gui_msgbar_refresh(void)
91 if (win_msgbar
!= NULL
) {
93 mvwaddstr(win_msgbar
, 0, 1, message
->str
);
94 wnoutrefresh(win_msgbar
);
100 gui_msgbar_flush(void)
103 g_string_assign(message
, "");
108 gui_msgbar_refresh();
112 * @brief Update the text in the message bar.
115 gui_msgbar_update(const char *msg
, int prio
, int cursor
)
120 * Do not attempt to set the message when there is a message on
121 * screen with a higher priority
123 if (prio
< message_prio
) {
128 g_string_assign(message
, msg
);
133 gui_msgbar_refresh();
138 gui_msgbar_warn(const char *msg
)
140 gui_msgbar_update(msg
, 0, 0);
144 gui_msgbar_ask(const char *msg
)
146 gui_msgbar_update(msg
, 1, 1);