options: remove double-semicolon
[ncmpc.git] / src / screen_utils.c
blobab1b39b0163c6c25a32de3bf9cff58b0f7d19935
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "screen_utils.h"
21 #include "screen.h"
22 #include "mpdclient.h"
23 #include "config.h"
24 #include "i18n.h"
25 #include "options.h"
26 #include "colors.h"
27 #include "wreadln.h"
29 #include <mpd/client.h>
31 void
32 screen_bell(void)
34 if (options.audible_bell)
35 beep();
36 if (options.visible_bell)
37 flash();
40 int
41 screen_getch(const char *prompt)
43 WINDOW *w = screen.status_bar.window.w;
44 int key = -1;
46 colors_use(w, COLOR_STATUS_ALERT);
47 werase(w);
48 wmove(w, 0, 0);
49 waddstr(w, prompt);
51 echo();
52 curs_set(1);
54 while ((key = wgetch(w)) == ERR)
57 #ifdef HAVE_GETMOUSE
58 /* ignore mouse events */
59 if (key == KEY_MOUSE)
60 return screen_getch(prompt);
61 #endif
63 noecho();
64 curs_set(0);
66 return key;
69 char *
70 screen_readln(const char *prompt,
71 const char *value,
72 GList **history,
73 GCompletion *gcmp)
75 struct window *window = &screen.status_bar.window;
76 WINDOW *w = window->w;
77 char *line = NULL;
79 wmove(w, 0,0);
80 curs_set(1);
81 colors_use(w, COLOR_STATUS_ALERT);
82 line = wreadln(w, prompt, value, window->cols, history, gcmp);
83 curs_set(0);
84 return line;
87 char *
88 screen_read_password(const char *prompt)
90 struct window *window = &screen.status_bar.window;
91 WINDOW *w = window->w;
92 char *ret;
94 wmove(w, 0,0);
95 curs_set(1);
96 colors_use(w, COLOR_STATUS_ALERT);
98 if (prompt == NULL)
99 prompt = _("Password");
100 ret = wreadln_masked(w, prompt, NULL, window->cols, NULL, NULL);
102 curs_set(0);
103 return ret;
106 void
107 screen_display_completion_list(GList *list)
109 static GList *prev_list = NULL;
110 static guint prev_length = 0;
111 static guint offset = 0;
112 WINDOW *w = screen.main_window.w;
113 guint length, y=0;
115 length = g_list_length(list);
116 if (list == prev_list && length == prev_length) {
117 offset += screen.main_window.rows;
118 if (offset >= length)
119 offset = 0;
120 } else {
121 prev_list = list;
122 prev_length = length;
123 offset = 0;
126 colors_use(w, COLOR_STATUS_ALERT);
127 while (y < screen.main_window.rows) {
128 GList *item = g_list_nth(list, y+offset);
130 wmove(w, y++, 0);
131 wclrtoeol(w);
132 if (item) {
133 gchar *tmp = g_strdup(item->data);
134 waddstr(w, g_basename(tmp));
135 g_free(tmp);
139 wrefresh(w);
140 doupdate();
141 colors_use(w, COLOR_LIST);
144 #ifndef NCMPC_MINI
145 void
146 set_xterm_title(const char *format, ...)
148 /* the current xterm title exists under the WM_NAME property */
149 /* and can be retrieved with xprop -id $WINDOWID */
151 if (options.enable_xterm_title) {
152 if (g_getenv("WINDOWID")) {
153 char *msg;
154 va_list ap;
156 va_start(ap,format);
157 msg = g_strdup_vprintf(format,ap);
158 va_end(ap);
159 printf("%c]0;%s%c", '\033', msg, '\007');
160 g_free(msg);
161 } else
162 options.enable_xterm_title = FALSE;
165 #endif