summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 965afb8)
raw | patch | inline | side by side (parent: 965afb8)
author | Max Kellermann <max@duempel.org> | |
Sun, 11 Oct 2009 12:55:23 +0000 (14:55 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sun, 11 Oct 2009 12:55:23 +0000 (14:55 +0200) |
Side effect: playlists and directories are rendered with different
colors (configuration "browser-directory" and "browser-playlist").
colors (configuration "browser-directory" and "browser-playlist").
NEWS | patch | blob | history | |
doc/config.sample | patch | blob | history | |
src/colors.c | patch | blob | history | |
src/colors.h | patch | blob | history | |
src/screen_browser.c | patch | blob | history |
index 4ce914c5decf67f3758fdd3307840b7f5a80a2fa..15ed5c3ed3da214cab19d742380e8b35f3563267 100644 (file)
--- a/NEWS
+++ b/NEWS
* screen_play: repaint after the "select-playing" command
* screen_text: start searching at window origin, not bottom
* strfsong: support multiple values for a tag
+* screen_browser: different colors for directories and playlists
ncmpc 0.15 - 2009-09-24
diff --git a/doc/config.sample b/doc/config.sample
index e064ebbedbe72dd9fd8558247ae61291617ffc92..9bd61c75d3322370acd2f224b53faeb7253b8173 100644 (file)
--- a/doc/config.sample
+++ b/doc/config.sample
## Set the bold text color in the main area of ncmpc.
#color list-bold = brightgreen
+## Sets the text color of directories in the browser
+#color browser-directory = yellow
+
+## Sets the text color of playlists in the browser
+#color browser-playlist = red
+
## Set the color of the progress indicator.
#color progressbar = white
diff --git a/src/colors.c b/src/colors.c
index 14c7cc76277ae3064bfca6225b05c6335c68bc90..a6c7e2cca9c665a741596483ac385bdf66a84a18 100644 (file)
--- a/src/colors.c
+++ b/src/colors.c
[COLOR_STATUS_BOLD] = { NAME_STATUS_BOLD, COLOR_BRIGHT_YELLOW, A_BOLD },
[COLOR_STATUS_TIME] = { NAME_STATUS_TIME, COLOR_RED, A_NORMAL },
[COLOR_STATUS_ALERT] = { NAME_ALERT, COLOR_BRIGHT_RED, A_BOLD },
+ [COLOR_DIRECTORY] = {
+ .name = "browser-directory",
+ .fg = COLOR_YELLOW,
+ .attrs = A_NORMAL,
+ },
+ [COLOR_PLAYLIST] = {
+ .name = "browser-playlist",
+ .fg = COLOR_RED,
+ .attrs = A_NORMAL,
+ },
};
#ifdef ENABLE_COLORS
diff --git a/src/colors.h b/src/colors.h
index 305e39678656f6afe816255ea72ef277786fdd20..d317760f23c421330c6750992b848eabeeff7224 100644 (file)
--- a/src/colors.h
+++ b/src/colors.h
COLOR_STATUS_BOLD,
COLOR_STATUS_TIME,
COLOR_STATUS_ALERT,
+ COLOR_DIRECTORY,
+ COLOR_PLAYLIST,
COLOR_END
};
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 3b0fc00ccf2a5610880c06cde0ece8e8e93f4649..16a2f5e7045c48233741e19aada820c76b1cdf02 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
#include "strfsong.h"
#include "mpdclient.h"
#include "filelist.h"
+#include "colors.h"
+#include "paint.h"
#include <mpd/client.h>
@@ -384,6 +386,10 @@ browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c)
}
#endif
+static void
+screen_browser_paint_callback(WINDOW *w, unsigned i, unsigned y,
+ unsigned width, bool selected, void *data);
+
bool
browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd)
return true;
case CMD_LIST_JUMP:
screen_jump(browser->lw, browser_lw_callback,
- NULL, browser->filelist);
+ screen_browser_paint_callback, browser->filelist);
return true;
#ifdef HAVE_GETMOUSE
return false;
}
+static void
+screen_browser_paint_directory(WINDOW *w, unsigned width,
+ bool selected, const char *name)
+{
+ row_color(w, COLOR_DIRECTORY, selected);
+
+ waddch(w, '[');
+ waddstr(w, name);
+ waddch(w, ']');
+
+ /* erase the unused space after the text */
+ row_clear_to_eol(w, width, selected);
+}
+
+static void
+screen_browser_paint_song(WINDOW *w, unsigned width, bool selected,
+ bool highlight, const struct mpd_song *song)
+{
+ char buffer[width * 4];
+
+ strfsong(buffer, sizeof(buffer), options.list_format, song);
+ row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST,
+ selected, buffer);
+}
+
+static void
+screen_browser_paint_playlist(WINDOW *w, unsigned width,
+ bool selected, const char *name)
+{
+ row_paint_text(w, width, COLOR_PLAYLIST, selected, name);
+}
+
+static void
+screen_browser_paint_callback(WINDOW *w, unsigned i,
+ G_GNUC_UNUSED unsigned y, unsigned width,
+ bool selected, void *data)
+{
+ const struct filelist *fl = (const struct filelist *) data;
+ const struct filelist_entry *entry;
+ const struct mpd_entity *entity;
+ bool highlight;
+ const struct mpd_directory *directory;
+ const struct mpd_playlist *playlist;
+ char *p;
+
+ assert(fl != NULL);
+ assert(i < filelist_length(fl));
+
+ entry = filelist_get(fl, i);
+ assert(entry != NULL);
+
+ entity = entry->entity;
+ if (entity == NULL) {
+ screen_browser_paint_directory(w, width, selected, "..");
+ return;
+ }
+
+#ifndef NCMPC_MINI
+ highlight = (entry->flags & HIGHLIGHT) != 0;
+#else
+ highlight = false;
+#endif
+
+ if (highlight)
+ colors_use(w, COLOR_LIST_BOLD);
+ else
+ colors_use(w, COLOR_LIST);
+
+ switch (mpd_entity_get_type(entity)) {
+ case MPD_ENTITY_TYPE_DIRECTORY:
+ directory = mpd_entity_get_directory(entity);
+ p = utf8_to_locale(g_basename(mpd_directory_get_path(directory)));
+ screen_browser_paint_directory(w, width, selected, p);
+ g_free(p);
+ break;
+
+ case MPD_ENTITY_TYPE_SONG:
+ screen_browser_paint_song(w, width, selected, highlight,
+ mpd_entity_get_song(entity));
+ break;
+
+ case MPD_ENTITY_TYPE_PLAYLIST:
+ playlist = mpd_entity_get_playlist(entity);
+ p = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
+ screen_browser_paint_playlist(w, width, selected, p);
+ g_free(p);
+ break;
+
+ default:
+ waddstr(w, "<unknown>");
+ }
+
+ whline(w, ' ', width);
+
+ if (selected)
+ wattroff(w, A_REVERSE);
+}
+
void
screen_browser_paint(const struct screen_browser *browser)
{
- list_window_paint(browser->lw, browser_lw_callback, browser->filelist);
+ list_window_paint2(browser->lw, screen_browser_paint_callback,
+ browser->filelist);
}