Fix whitespace inconsistencies.
[herrie-working.git] / herrie / src / gui_msgbar.c
blobb6e5f373b9593733f8086e9dd69cb6da951115e7
1 /*
2 * Copyright (c) 2006-2011 Ed Schouten <ed@80386.nl>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
24 * SUCH DAMAGE.
26 /**
27 * @file gui_msgbar.c
28 * @brief Message logging for textual user interface.
31 #include "stdinc.h"
33 #include "gui.h"
34 #include "gui_internal.h"
36 /**
37 * @brief Priority of the current message in the message bar.
39 static int message_prio = 0;
40 /**
41 * @brief Current message in the message bar.
43 static GString *message;
44 /**
45 * @brief Window object of the message bar at the bottom of the screen.
47 static WINDOW *win_msgbar;
49 void
50 gui_msgbar_init(void)
52 win_msgbar = newwin(1, 0, GUI_SIZE_MSGBAR_TOP, 0);
53 clearok(win_msgbar, TRUE);
54 if (gui_draw_colors)
55 wbkgdset(win_msgbar, COLOR_PAIR(GUI_COLOR_BAR));
56 else
57 wbkgdset(win_msgbar, A_REVERSE);
59 message = g_string_sized_new(32);
61 /* Hide the cursor by default */
62 curs_set(0);
64 gui_msgbar_refresh();
67 void
68 gui_msgbar_destroy(void)
70 g_string_free(message, TRUE);
71 delwin(win_msgbar);
72 win_msgbar = NULL;
75 void
76 gui_msgbar_resize(void)
78 gui_lock();
79 wresize(win_msgbar, 1, COLS);
80 mvwin(win_msgbar, GUI_SIZE_MSGBAR_TOP, 0);
81 clearok(win_msgbar, TRUE);
82 gui_unlock();
84 gui_msgbar_refresh();
87 void
88 gui_msgbar_refresh(void)
90 gui_lock();
91 if (win_msgbar != NULL) {
92 werase(win_msgbar);
93 mvwaddstr(win_msgbar, 0, 1, message->str);
94 wnoutrefresh(win_msgbar);
96 gui_unlock();
99 void
100 gui_msgbar_flush(void)
102 gui_lock();
103 g_string_assign(message, "");
104 message_prio = -1;
105 curs_set(0);
106 gui_unlock();
108 gui_msgbar_refresh();
112 * @brief Update the text in the message bar.
114 static void
115 gui_msgbar_update(const char *msg, int prio, int cursor)
117 gui_lock();
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) {
124 gui_unlock();
125 return;
128 g_string_assign(message, msg);
129 message_prio = prio;
130 gui_unlock();
132 curs_set(cursor);
133 gui_msgbar_refresh();
134 gui_draw_done();
137 void
138 gui_msgbar_warn(const char *msg)
140 gui_msgbar_update(msg, 0, 0);
143 void
144 gui_msgbar_ask(const char *msg)
146 gui_msgbar_update(msg, 1, 1);