tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit f1996f51ba1744260bba4d7c3aa5d9a84c97236e
parent 862b65a3a02afa19d4998565d4bb438bef3ed2ec
Author: Louis Burda <quent.burda@gmail.com>
Date:   Thu, 16 Mar 2023 13:32:35 +0100

Update liblist and add keybind to sort tracks and tags

Diffstat:
MMakefile | 2+-
Msrc/main.c | 1-
Msrc/tui.c | 45+++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -41,7 +41,7 @@ build/%.d: | build; include $(DEPS) $(LIBLIST_A): - make -C lib/liblist build/liblist.a + make -C lib/liblist DEBUG=1 build/liblist.a tmus: $(OBJS) $(LIBLIST_A) $(CC) -o tmus $^ $(CFLAGS) $(LDLIBS) diff --git a/src/main.c b/src/main.c @@ -40,7 +40,6 @@ init(void) on_exit(cleanup, NULL); signal(SIGINT, stop); signal(SIGTERM, exit); - signal(SIGKILL, exit); } void diff --git a/src/tui.c b/src/tui.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #define NCURSES_WIDECHAR 1 #define _GNU_SOURCE @@ -53,6 +54,8 @@ static bool toggle_current_tag(void); static void select_only_current_tag(void); static void seek_next_selected_tag(void); static void delete_current_tag(void); +static bool tag_name_cmp(struct link *l1, struct link *l2); +static void sort_visible_tags(void); static bool tag_pane_input(wint_t c); static void tag_pane_vis(struct pane *pane, int sel); @@ -63,6 +66,8 @@ static bool rename_current_track(void); static bool delete_current_track(void); static void queue_current_track(void); static void unqueue_last_track(void); +static bool track_vis_name_cmp(struct link *l1, struct link *l2); +static void sort_visible_tracks(void); static bool track_pane_input(wint_t c); static void track_pane_vis(struct pane *pane, int sel); @@ -416,6 +421,23 @@ delete_current_tag(void) } bool +tag_name_cmp(struct link *l1, struct link *l2) +{ + struct tag *t1, *t2; + + t1 = LINK_UPCAST(l1, struct tag, link); + t2 = LINK_UPCAST(l2, struct tag, link); + + return strcmp(t1->name, t2->name) <= 0; +} + +void +sort_visible_tags(void) +{ + list_sort(&tags, false, tag_name_cmp); +} + +bool tag_pane_input(wint_t c) { switch (c) { @@ -452,6 +474,9 @@ tag_pane_input(wint_t c) case L'D': /* delete tag */ delete_current_tag(); break; + case KEY_CTRL(L's'): + sort_visible_tags(); + break; default: return false; } @@ -622,6 +647,23 @@ unqueue_last_track(void) } bool +track_vis_name_cmp(struct link *l1, struct link *l2) +{ + struct track *t1, *t2; + + t1 = tracks_vis_track(l1); + t2 = tracks_vis_track(l2); + + return strcmp(t1->name, t2->name) <= 0; +} + +void +sort_visible_tracks(void) +{ + list_sort(tracks_vis, false, track_vis_name_cmp); +} + +bool track_pane_input(wint_t c) { switch (c) { @@ -663,6 +705,9 @@ track_pane_input(wint_t c) case L'D': /* delete track */ delete_current_track(); break; + case KEY_CTRL(L's'): /* sort track in view */ + sort_visible_tracks(); + break; default: return false; }