aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-02 03:17:07 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-02 03:17:07 +0200
commit7e35164e775ee3c395ed42805fc9e3692d50cfe1 (patch)
treede6af3998f41bf16b02c9528a39c91d9b3e2b740
parente4f3f8ebf0431357245db5fbddbef886f4736e65 (diff)
downloadnncmpp-7e35164e775ee3c395ed42805fc9e3692d50cfe1.tar.gz
nncmpp-7e35164e775ee3c395ed42805fc9e3692d50cfe1.tar.xz
nncmpp-7e35164e775ee3c395ed42805fc9e3692d50cfe1.zip
Finer progress bar thanks to Unicode
-rw-r--r--nncmpp.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/nncmpp.c b/nncmpp.c
index c8f964f..9628861 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -788,6 +788,35 @@ app_write_time (struct row_buffer *buf, int seconds, chtype attrs)
}
static void
+app_write_gauge (struct row_buffer *buf, float ratio, int width)
+{
+ // Always compute it in exactly eight times the resolution,
+ // because sometimes Unicode is even useful
+ int len_left = ratio * width * 8 + 0.5;
+
+ static const char *partials[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"};
+ int remainder = len_left % N_ELEMENTS (partials);
+ len_left /= N_ELEMENTS (partials);
+
+ // Assuming that if we can show the 1/8 box then we can show them all
+ const char *partial = NULL;
+ // TODO: cache this setting and make it configurable since it doesn't seem
+ // to work 100% (e.g. incompatible with undelining in urxvt)
+ if (!app_is_character_in_locale (L'▏'))
+ len_left += remainder >= (int) N_ELEMENTS (partials) / 2;
+ else
+ partial = partials[remainder];
+
+ int len_right = width - len_left;
+ while (len_left-- > 0)
+ row_buffer_append (buf, " ", APP_ATTR (ELAPSED));
+ if (partial && len_right-- > 0)
+ row_buffer_append (buf, partial, APP_ATTR (REMAINS));
+ while (len_right-- > 0)
+ row_buffer_append (buf, " ", APP_ATTR (REMAINS));
+}
+
+static void
app_redraw_status (void)
{
if (g_ctx.state != PLAYER_STOPPED)
@@ -842,13 +871,8 @@ app_redraw_status (void)
if (!stopped && g_ctx.song_elapsed >= 0 && g_ctx.song_duration >= 1
&& remaining > 0)
{
- int len_elapsed = (int) ((float) g_ctx.song_elapsed
- / g_ctx.song_duration * remaining + 0.5);
- int len_remains = remaining - len_elapsed;
- while (len_elapsed-- > 0)
- row_buffer_append (&buf, " ", APP_ATTR (ELAPSED));
- while (len_remains-- > 0)
- row_buffer_append (&buf, " ", APP_ATTR (REMAINS));
+ app_write_gauge (&buf,
+ (float) g_ctx.song_elapsed / g_ctx.song_duration, remaining);
}
else while (remaining-- > 0)
row_buffer_append (&buf, " ", a_normal);