/** \file gui.c Curses-based interface for paraslash. */
+#include <regex.h>
#include <signal.h>
#include <sys/types.h>
#include <dirent.h>
+#include <curses.h>
+
#include "gui.cmdline.h"
#include "para.h"
#include "gui.h"
#include "string.h"
-#include <curses.h>
#include "ringbuffer.h"
#include "fd.h"
#include "error.h"
size_t len;
int color;
};
-struct ringbuffer *bot_win_rb;
+static struct ringbuffer *bot_win_rb;
#define NUM_LINES(len) (1 + (len) / bot.cols)
static unsigned scroll_position;
static struct gui_theme theme;
-int _argc;
-char **_argv;
+static int _argc;
+static char **_argv;
static void com_help(void);
static void com_reread_conf(void);
static void com_page_up(void);
static void com_page_down(void);
-struct gui_command command_list[] = {
+static struct gui_command command_list[] = {
{
.key = "?",
.name = "help",
* print aligned string to curses window. This function always prints
* exactly len chars.
*/
-static int align_str(WINDOW* win, const char *string, unsigned int len,
+static int align_str(WINDOW* win, char *str, unsigned int len,
unsigned int align)
{
- int num; /* of spaces */
- char *str;
+ int i, num; /* of spaces */
- if (!win || !string)
+ if (!win || !str)
return -1;
- num = len - strlen(string);
- str = para_strdup(string);
+ num = len - strlen(str);
if (num < 0) {
str[len] = '\0';
num = 0;
}
+ /* replace newlines by spaces */
+ for (i = 0; i < len && str[i]; i++) {
+ if (str[i] == '\n')
+ str[i] = ' ';
+ }
if (align == LEFT) {
waddstr(win, str);
add_spaces(win, num);
waddstr(win, str[0]? str: "");
add_spaces(win, num - num / 2);
}
- free(str);
return 1;
}
*/
static void print_status_bar(void)
{
+ char *tmp;
+
if (!curses_active)
return;
+ tmp = para_strdup(STANDARD_STATUS_BAR);
wmove(sb.win, 0, 0);
- align_str(sb.win, STANDARD_STATUS_BAR, sb.cols, CENTER);
+ align_str(sb.win, tmp, sb.cols, CENTER);
+ free(tmp);
wrefresh(sb.win);
}
wrefresh(top.win);
}
-/*
- * print status line if line starts with known command.
- */
static int update_item(int item_num, char *buf)
{
- free(stat_content[item_num]);
- stat_content[item_num] = para_strdup(buf);
+ char **c = stat_content + item_num;
+
+ free(*c);
+ if (buf && buf[0])
+ goto dup;
+ switch (item_num) {
+ case SI_ARTIST:
+ *c = para_strdup("(artist tag not set)");
+ goto print;
+ case SI_TITLE:
+ *c = para_strdup("(title tag not set)");
+ goto print;
+ case SI_YEAR:
+ *c = para_strdup("????");
+ goto print;
+ case SI_ALBUM:
+ *c = para_strdup("(album tag not set)");
+ goto print;
+ case SI_COMMENT:
+ *c = para_strdup("(comment tag not set)");
+ goto print;
+ }
+dup:
+ *c = para_strdup(buf);
+print:
print_stat_item(item_num);
return 1;
}
static int read_audiod_pipe(int fd)
{
- static char buf[8192];
- static int loaded;
+ static char *buf;
+ static int bufsize, loaded;
int ret;
- if (loaded >= sizeof(buf)) /* overflow */
- return 0;
- ret = read(fd, buf + loaded, sizeof(buf) - loaded);
+ if (loaded >= bufsize) {
+ if (bufsize > 1000 * 1000) {
+ loaded = 0;
+ return 0;
+ }
+ bufsize += bufsize + 1000;
+ buf = para_realloc(buf, bufsize);
+ }
+ assert(loaded < bufsize);
+ ret = read(fd, buf + loaded, bufsize - loaded);
if (ret <= 0)
return ret;
loaded += ret;