diff --git a/src/screen_text.c b/src/screen_text.c
index 1222f27cf115464826915c0f7aef8306e9c250d5..938d65627d69a2f63e1857d01656312dd3f7e3c1 100644 (file)
--- a/src/screen_text.c
+++ b/src/screen_text.c
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
* Project homepage: http://musicpd.org
-
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
-
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-
+ *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
#include "screen_text.h"
-#include "screen_utils.h"
+#include "screen_find.h"
#include "charset.h"
#include <assert.h>
g_free(g_ptr_array_index(text->lines, i));
g_ptr_array_set_size(text->lines, 0);
+ list_window_set_length(text->lw, 0);
}
void
-screen_text_set(struct screen_text *text, const GString *str)
+screen_text_append(struct screen_text *text, const char *str)
{
- const char *p, *eol, *next;
-
assert(str != NULL);
- screen_text_clear(text);
-
- p = str->str;
- while ((eol = strchr(p, '\n')) != NULL) {
+ const char *eol;
+ while ((eol = strchr(str, '\n')) != NULL) {
char *line;
- next = eol + 1;
+ const char *next = eol + 1;
/* strip whitespace at end */
- while (eol > p && (unsigned char)eol[-1] <= 0x20)
+ while (eol > str && (unsigned char)eol[-1] <= 0x20)
--eol;
/* create copy and append it to text->lines */
- line = g_malloc(eol - p + 1);
- memcpy(line, p, eol - p);
- line[eol - p] = 0;
+ line = g_malloc(eol - str + 1);
+ memcpy(line, str, eol - str);
+ line[eol - str] = 0;
g_ptr_array_add(text->lines, line);
/* reset control characters */
- for (eol = line + (eol - p); line < eol; ++line)
+ for (eol = line + (eol - str); line < eol; ++line)
if ((unsigned char)*line < 0x20)
*line = ' ';
- p = next;
+ str = next;
}
- if (*p != 0)
- g_ptr_array_add(text->lines, g_strdup(p));
+ if (*str != 0)
+ g_ptr_array_add(text->lines, g_strdup(str));
+
+ list_window_set_length(text->lw, text->lines->len);
}
const char *
-screen_text_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
- void *data)
+screen_text_list_callback(unsigned idx, void *data)
{
const struct screen_text *text = data;
- static char buffer[256];
- char *value;
- if (idx >= text->lines->len)
- return NULL;
+ assert(idx < text->lines->len);
- value = utf8_to_locale(g_ptr_array_index(text->lines, idx));
+ char *value = utf8_to_locale(g_ptr_array_index(text->lines, idx));
+
+ static char buffer[256];
g_strlcpy(buffer, value, sizeof(buffer));
g_free(value);
bool
screen_text_cmd(struct screen_text *text,
- G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
+ gcc_unused struct mpdclient *c, command_t cmd)
{
- if (list_window_scroll_cmd(text->lw, text->lines->len, cmd)) {
+ if (list_window_scroll_cmd(text->lw, cmd)) {
screen_text_repaint(text);
return true;
}
- text->lw->selected = text->lw->start + text->lw->rows;
- if (screen_find(text->lw, text->lines->len,
- cmd, screen_text_list_callback, text)) {
+ list_window_set_cursor(text->lw, text->lw->start);
+ if (screen_find(text->lw, cmd, screen_text_list_callback, text)) {
/* center the row */
- list_window_center(text->lw, text->lines->len,
- text->lw->selected);
+ list_window_center(text->lw, text->lw->selected);
screen_text_repaint(text);
return true;
}