summaryrefslogtreecommitdiff
path: root/src/fruits/cmc/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/fruits/cmc/ui')
-rw-r--r--src/fruits/cmc/ui/widgets/now_playing.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/fruits/cmc/ui/widgets/now_playing.c b/src/fruits/cmc/ui/widgets/now_playing.c
index 56405b3..1a4303d 100644
--- a/src/fruits/cmc/ui/widgets/now_playing.c
+++ b/src/fruits/cmc/ui/widgets/now_playing.c
@@ -162,23 +162,28 @@ void cmc_now_playing_render(struct cmc_now_playing *np, struct cmc_list_entry *e
ncplane_putstr_yx(np->n, 1, x1 + 2, timestr);
if (entry) {
- u32 rslash = al_str_rfind(&entry->brief, '/');
str part;
+ u32 rslash = al_str_rfind(&entry->brief, '/');
if (rslash != AL_STR_NO_POS) {
part = al_str_substr(&entry->brief, rslash + 1, entry->brief.length);
} else {
part = entry->brief;
}
- char *c_str = al_str_to_c_str(&part);
+ // x1 = Position of right side "|".
+ // x2 = First character of entry brief.
s32 x2 = 6 + width1;
- // @TODO: Can mid be negative.
s32 mid = x1 - x2;
- ncplane_putnstr_yx(np->n, 1, x2, MIN(al_strlen(c_str), (size_t)mid), c_str);
- if (part.length >= mid) {
- ncplane_putnstr_yx(np->n, 1, x2 + mid - 1, 1, ".");
- ncplane_putnstr_yx(np->n, 1, x2 + mid - 2, 1, ".");
+ if (mid >= 1) {
+ char *c_str = al_str_to_c_str(&part);
+ ncplane_putnstr_yx(np->n, 1, x2, MIN(al_strlen(c_str), (size_t)mid), c_str);
+ if (part.length >= (u32)mid) {
+ ncplane_putnstr_yx(np->n, 1, x2 + mid - 1, 1, ".");
+ if (mid >= 2) {
+ ncplane_putnstr_yx(np->n, 1, x2 + mid - 2, 1, ".");
+ }
+ }
+ al_free(c_str);
}
- al_free(c_str);
bool visual_cached = false;
struct cmc_now_playing_visual *visual;