Skip to content

Commit

Permalink
Draw progress bar on statusline
Browse files Browse the repository at this point in the history
Styles:
 - line (default)
 - shuttle
 - color
 - color_shuttle
  • Loading branch information
gavtroy committed Sep 14, 2024
1 parent 59bfea1 commit 7ee2711
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 22 deletions.
12 changes: 12 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,15 @@ color_statusline_fg (black) [`Color`]
color_statusline_attr (default) [`Attributes`]
Status line attributes.

color_statusline_progress_bg (blue) [`Color`]
Status line background color of progress bar, when enabled.

color_statusline_progress_fg (white) [`Color`]
Status line foreground color of progress bar, when enabled.

color_statusline_progress_attr (default) [`Attributes`]
Status line attributes of progress bar, when enabled.

color_titleline_bg (blue) [`Color`]
Background color of the line displaying currently playing track.

Expand Down Expand Up @@ -1170,6 +1179,9 @@ play_sorted (false)
Play tracks from the library in the sorted view (2) order instead of
tree view (1) order. Used only when play_library is true.

progress_bar (line) [disabled, line, shuttle, color, color_shuttle]
Draw a bar in the status line showing current progression through a track.

repeat (false)
Repeat after all tracks played.

Expand Down
2 changes: 2 additions & 0 deletions data/amazon.theme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set color_info=136
set color_separator=202
set color_statusline_bg=232
set color_statusline_fg=208
set color_statusline_progress_bg=166
set color_statusline_progress_fg=232
set color_titleline_bg=232
set color_titleline_fg=220
set color_win_title_bg=232
Expand Down
2 changes: 2 additions & 0 deletions data/cyan.theme
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set color_info=lightyellow
set color_separator=cyan
set color_statusline_bg=default
set color_statusline_fg=cyan
set color_statusline_progress_bg=cyan
set color_statusline_progress_fg=black
set color_titleline_bg=blue
set color_titleline_fg=white
set color_win_bg=default
Expand Down
2 changes: 2 additions & 0 deletions data/default.theme
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set color_info=lightyellow
set color_separator=blue
set color_statusline_bg=gray
set color_statusline_fg=black
set color_statusline_progress_bg=blue
set color_statusline_progress_fg=white
set color_titleline_bg=blue
set color_titleline_fg=white
set color_win_bg=default
Expand Down
2 changes: 2 additions & 0 deletions data/dracula.theme
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set color_info=231
set color_separator=004
set color_statusline_bg=default
set color_statusline_fg=231
set color_statusline_progress_bg=010
set color_statusline_progress_fg=236
set color_titleline_bg=010
set color_titleline_fg=236
set color_win_bg=default
Expand Down
2 changes: 2 additions & 0 deletions data/gray-88.theme
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set color_info=green
set color_separator=darkgray
set color_statusline_bg=80
set color_statusline_fg=85
set color_statusline_progress_bg=darkgray
set color_statusline_progress_fg=85
set color_titleline_bg=darkgray
set color_titleline_fg=85
set color_win_bg=80
Expand Down
2 changes: 2 additions & 0 deletions data/green-mono-88.theme
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ set color_separator=green
# Bottom status line
set color_statusline_bg=black
set color_statusline_fg=green
set color_statusline_progress_bg=green
set color_statusline_progress_fg=black

# Bottom title line
set color_titleline_bg=green
Expand Down
2 changes: 2 additions & 0 deletions data/green.theme
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ set color_win_title_fg=green
# Status line color.
set color_statusline_bg=default
set color_statusline_fg=gray
set color_statusline_progress_bg=234
set color_statusline_progress_fg=gray

# Color of the line displaying currently playing track.
set color_titleline_bg=default
Expand Down
2 changes: 2 additions & 0 deletions data/gruvbox-alt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set color_titleline_fg=235
# bottom status line: bg0_s/dark-aqua
set color_statusline_bg=236
set color_statusline_fg=72
set color_statusline_progress_bg=234
set color_statusline_progress_fg=72

# command-line colors: bg/orange/light-red/light-yellow
set color_cmdline_bg=235
Expand Down
2 changes: 2 additions & 0 deletions data/gruvbox-warm.theme
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set color_separator=246
# bottom status line
set color_statusline_bg=236
set color_statusline_fg=66
set color_statusline_progress_bg=237
set color_statusline_progress_fg=66

# bottom title line
set color_titleline_bg=237
Expand Down
2 changes: 2 additions & 0 deletions data/gruvbox.theme
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set color_separator=246
# bottom status line
set color_statusline_bg=237
set color_statusline_fg=72
set color_statusline_progress_bg=234
set color_statusline_progress_fg=72

# bottom title line
set color_titleline_bg=236
Expand Down
3 changes: 2 additions & 1 deletion data/jellybeans.theme
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ set color_titleline_attr=default

set color_statusline_bg=237
set color_statusline_fg=145
set color_statusline_attr=default
set color_statusline_progress_bg=233
set color_statusline_progress_fg=145

# Text
set color_win_cur=183
Expand Down
4 changes: 3 additions & 1 deletion data/night.theme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set color_info=220
set color_separator=002
set color_statusline_bg=234
set color_statusline_fg=045
set color_statusline_progress_bg=default
set color_statusline_progress_fg=045
set color_titleline_bg=default
set color_titleline_fg=046
set color_win_bg=default
Expand All @@ -24,4 +26,4 @@ set color_win_sel_bg=235
set color_win_sel_fg=045
set color_win_title_bg=234
set color_win_title_fg=045
### }}}
### }}}
2 changes: 2 additions & 0 deletions data/solarized-dark.theme
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set color_separator=240
# bottom status line
set color_statusline_bg=0
set color_statusline_fg=37
set color_statusline_progress_bg=233
set color_statusline_progress_fg=37

# bottom title line
set color_titleline_bg=0
Expand Down
2 changes: 2 additions & 0 deletions data/solarized-light.theme
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set color_separator=245
# bottom status line
set color_statusline_bg=0
set color_statusline_fg=37
set color_statusline_progress_bg=233
set color_statusline_progress_fg=37

# bottom title line
set color_titleline_bg=0
Expand Down
2 changes: 2 additions & 0 deletions data/spotify.theme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set color_info=81
set color_separator=47
set color_statusline_bg=232
set color_statusline_fg=34
set color_statusline_progress_bg=234
set color_statusline_progress_fg=34
set color_titleline_bg=232
set color_titleline_fg=83
set color_win_title_bg=232
Expand Down
2 changes: 2 additions & 0 deletions data/xterm-white.theme
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set color_info=lightblue
set color_separator=default
set color_statusline_bg=default
set color_statusline_fg=default
set color_statusline_progress_bg=gray
set color_statusline_progress_fg=default
set color_titleline_bg=gray
set color_titleline_fg=default
set color_win_bg=default
Expand Down
2 changes: 2 additions & 0 deletions data/zenburn.theme
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ set color_win_title_fg=174
# Status line color.
set color_statusline_bg=237
set color_statusline_fg=142
set color_statusline_progress_bg=240
set color_statusline_progress_fg=142

# Color of currently playing track.
set color_win_cur=172
Expand Down
36 changes: 32 additions & 4 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ int tree_width_percent = 33;
int tree_width_max = 0;
int pause_on_output_change = 0;
int block_key_paste = 1;
int progress_bar = 1;

int colors[NR_COLORS] = {
-1,
Expand All @@ -107,26 +108,28 @@ int colors[NR_COLORS] = {
COLOR_BLACK,
COLOR_BLUE,

COLOR_WHITE | BRIGHT,
COLOR_BLUE,
COLOR_WHITE | BRIGHT,
-1,

COLOR_YELLOW | BRIGHT,
COLOR_BLUE,

COLOR_YELLOW | BRIGHT,
COLOR_BLUE | BRIGHT,

-1,
COLOR_WHITE,

COLOR_YELLOW | BRIGHT,
COLOR_WHITE,

COLOR_BLACK,
COLOR_BLUE,

COLOR_WHITE | BRIGHT,
COLOR_BLUE,

COLOR_WHITE | BRIGHT,
-1,

-1,
};

Expand Down Expand Up @@ -1368,6 +1371,27 @@ static void toggle_block_key_paste(void *data)
block_key_paste ^= 1;
}

const char * const progress_bar_names[] = {
"disabled", "line", "shuttle", "color", "color_shuttle", NULL
};

static void get_progress_bar(void *data, char *buf, size_t size)
{
strscpy(buf, progress_bar_names[progress_bar], size);
}

static void set_progress_bar(void *data, const char *buf)
{
parse_enum(buf, 0, 4, progress_bar_names, &progress_bar);
}

static void toggle_progress_bar(void *data)
{
progress_bar++;
progress_bar %= NR_PROGRESS_BAR_MODES;
update_statusline();
}

/* }}} */

/* special callbacks (id set) {{{ */
Expand Down Expand Up @@ -1639,6 +1663,7 @@ static const struct {
DT(pause_on_output_change)
DN(pl_env_vars)
DT(block_key_paste)
DT(progress_bar)
{ NULL, NULL, NULL, NULL, 0 }
};

Expand All @@ -1650,6 +1675,8 @@ static const char * const color_names[NR_COLORS] = {
"color_separator",
"color_statusline_bg",
"color_statusline_fg",
"color_statusline_progress_bg",
"color_statusline_progress_fg",
"color_titleline_bg",
"color_titleline_fg",
"color_win_bg",
Expand All @@ -1673,6 +1700,7 @@ static const char * const color_names[NR_COLORS] = {
static const char * const attr_names[NR_ATTRS] = {
"color_cmdline_attr",
"color_statusline_attr",
"color_statusline_progress_attr",
"color_titleline_attr",
"color_win_attr",
"color_win_cur_sel_attr",
Expand Down
24 changes: 19 additions & 5 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,39 @@ enum {
COLOR_SEPARATOR,
COLOR_STATUSLINE_BG,
COLOR_STATUSLINE_FG,
COLOR_TITLELINE_BG,
COLOR_STATUSLINE_PROGRESS_BG,

COLOR_STATUSLINE_PROGRESS_FG,
COLOR_TITLELINE_BG,
COLOR_TITLELINE_FG,
COLOR_WIN_BG,

COLOR_WIN_CUR,
COLOR_WIN_CUR_SEL_BG,

COLOR_WIN_CUR_SEL_FG,
COLOR_WIN_DIR,

COLOR_WIN_FG,
COLOR_WIN_INACTIVE_CUR_SEL_BG,

COLOR_WIN_INACTIVE_CUR_SEL_FG,
COLOR_WIN_INACTIVE_SEL_BG,

COLOR_WIN_INACTIVE_SEL_FG,
COLOR_WIN_SEL_BG,

COLOR_WIN_SEL_FG,
COLOR_WIN_TITLE_BG,

COLOR_WIN_TITLE_FG,
COLOR_TRACKWIN_ALBUM_BG,

COLOR_TRACKWIN_ALBUM_FG,

NR_COLORS
};

enum {
COLOR_CMDLINE_ATTR,
COLOR_STATUSLINE_ATTR,
COLOR_STATUSLINE_PROGRESS_ATTR,
COLOR_TITLELINE_ATTR,
COLOR_WIN_ATTR,
COLOR_WIN_CUR_SEL_ATTR,
Expand All @@ -125,6 +129,15 @@ enum shuffle_mode {
SHUFFLE_TRUE
};

enum progress_bar_mode {
PROGRESS_BAR_DISABLED,
PROGRESS_BAR_LINE,
PROGRESS_BAR_SHUTTLE,
PROGRESS_BAR_COLOR,
PROGRESS_BAR_COLOR_SHUTTLE,
NR_PROGRESS_BAR_MODES
};

#define BRIGHT (1 << 3)

extern char *cdda_device;
Expand Down Expand Up @@ -165,6 +178,7 @@ extern int tree_width_percent;
extern int tree_width_max;
extern int pause_on_output_change;
extern int block_key_paste;
extern int progress_bar;

extern const char * const aaa_mode_names[];
extern const char * const view_names[NR_VIEWS + 1];
Expand Down
Loading

0 comments on commit 7ee2711

Please sign in to comment.