diff options
author | Max Kellermann <max@duempel.org> | 2008-09-15 12:27:28 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-15 12:27:28 +0200 |
commit | 001ff5ee87b755c8c5371690222fc3ac16ba0602 (patch) | |
tree | cc3103aaf1a279f0f6314b31cd9f29ed137c97f9 /src/screen.c | |
parent | 4ebba1b36f4f171fb5daa25a8578e21d2740c517 (diff) | |
download | mpd-001ff5ee87b755c8c5371690222fc3ac16ba0602.tar.gz mpd-001ff5ee87b755c8c5371690222fc3ac16ba0602.tar.xz mpd-001ff5ee87b755c8c5371690222fc3ac16ba0602.zip |
screen: moved code to paint_top_window2()
Nearly all of the code in paint_top_window() is on indent level 2,
just because it depends on a condition. Make this more readable and
move to indent level 1 by moving this code to a separate function.
Diffstat (limited to 'src/screen.c')
-rw-r--r-- | src/screen.c | 142 |
1 files changed, 74 insertions, 68 deletions
diff --git a/src/screen.c b/src/screen.c index 911c94c28..f4ced308c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -186,9 +186,80 @@ screen_next_mode(mpdclient_t *c, int offset) } static void -paint_top_window(char *header, mpdclient_t *c, int clear) +paint_top_window2(char *header, mpdclient_t *c) { char flags[5]; + WINDOW *w = screen->top_window.w; + char buf[32]; + + if (header[0]) { + colors_use(w, COLOR_TITLE_BOLD); + mvwaddstr(w, 0, 0, header); + } else { + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Help ")); + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Playlist ")); + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Browse ")); +#ifdef ENABLE_ARTIST_SCREEN + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Artist ")); +#endif +#ifdef ENABLE_SEARCH_SCREEN + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Search ")); +#endif +#ifdef ENABLE_LYRICS_SCREEN + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Lyrics ")); +#endif + } + if (c->status->volume==MPD_STATUS_NO_VOLUME) { + g_snprintf(buf, 32, _("Volume n/a ")); + } else { + g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume); + } + colors_use(w, COLOR_TITLE); + mvwaddstr(w, 0, screen->top_window.cols-my_strlen(buf), buf); + + flags[0] = 0; + if( c->status->repeat ) + g_strlcat(flags, "r", sizeof(flags)); + if( c->status->random ) + g_strlcat(flags, "z", sizeof(flags));; + if( c->status->crossfade ) + g_strlcat(flags, "x", sizeof(flags)); + if( c->status->updatingDb ) + g_strlcat(flags, "U", sizeof(flags)); + colors_use(w, COLOR_LINE); + mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols); + if (flags[0]) { + wmove(w,1,screen->top_window.cols-strlen(flags)-3); + waddch(w, '['); + colors_use(w, COLOR_LINE_BOLD); + waddstr(w, flags); + colors_use(w, COLOR_LINE); + waddch(w, ']'); + } + wnoutrefresh(w); +} + +static void +paint_top_window(char *header, mpdclient_t *c, int clear) +{ static int prev_volume = -1; static int prev_header_len = -1; WINDOW *w = screen->top_window.w; @@ -203,73 +274,8 @@ paint_top_window(char *header, mpdclient_t *c, int clear) wclrtoeol(w); } - if (prev_volume!=c->status->volume || clear) { - char buf[32]; - - if (header[0]) { - colors_use(w, COLOR_TITLE_BOLD); - mvwaddstr(w, 0, 0, header); - } else { - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Help ")); - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Playlist ")); - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Browse ")); -#ifdef ENABLE_ARTIST_SCREEN - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Artist ")); -#endif -#ifdef ENABLE_SEARCH_SCREEN - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Search ")); -#endif -#ifdef ENABLE_LYRICS_SCREEN - colors_use(w, COLOR_TITLE_BOLD); - waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE)); - colors_use(w, COLOR_TITLE); - waddstr(w, _(":Lyrics ")); -#endif - } - if (c->status->volume==MPD_STATUS_NO_VOLUME) { - g_snprintf(buf, 32, _("Volume n/a ")); - } else { - g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume); - } - colors_use(w, COLOR_TITLE); - mvwaddstr(w, 0, screen->top_window.cols-my_strlen(buf), buf); - - flags[0] = 0; - if( c->status->repeat ) - g_strlcat(flags, "r", sizeof(flags)); - if( c->status->random ) - g_strlcat(flags, "z", sizeof(flags));; - if( c->status->crossfade ) - g_strlcat(flags, "x", sizeof(flags)); - if( c->status->updatingDb ) - g_strlcat(flags, "U", sizeof(flags)); - colors_use(w, COLOR_LINE); - mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols); - if (flags[0]) { - wmove(w,1,screen->top_window.cols-strlen(flags)-3); - waddch(w, '['); - colors_use(w, COLOR_LINE_BOLD); - waddstr(w, flags); - colors_use(w, COLOR_LINE); - waddch(w, ']'); - } - wnoutrefresh(w); - } + if (prev_volume!=c->status->volume || clear) + paint_top_window2(header, c); } static void |