commit bbc6de2ef2db399c00e09872070261bd2e5057c2
parent 55b2007ed7b7d2ced7301cb1468cf364b3500ec8
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Fri, 5 May 2023 13:08:12 -0700
Give more verbose feedback for various commands
The seek, play, next, and previous commands return the new item's
path; toggle returns the new player status. This eliminates the
need to use for further commands to get more information (which,
by that point, could be entirely unrelated to the command initially
run as explained below).
Initially I was thinking about minimizing I/O, and since sometimes
you don't need this extra information, I figured you should have
to specially request it, but without the ability to group commands
together so that other clients can't interpose their own commands
between them, this method is necessary to guarantee the information
is related to the command run.
Diffstat:
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/aps/command.c b/aps/command.c
@@ -111,11 +111,14 @@ com_seek(struct aps *aps, int fd, int argc, char **argv)
{
char *err;
- if (argc)
- err = aps_seek(aps, *argv);
- else
- err = "No pattern";
- return err;
+ if (!argc)
+ return "No pattern";
+
+ if ((err = aps_seek(aps, *argv)))
+ return err;
+ if (aps_bufline(aps, fd, aps->queue->path))
+ return errstr;
+ return NULL;
}
char *
@@ -123,8 +126,6 @@ com_play(struct aps *aps, int fd, int argc, char **argv)
{
char *err;
- if (!aps->queue)
- return "Empty queue";
if (argc && (err = com_seek(aps, fd, argc, argv)))
return err;
if (pplay(aps->player, aps->queue->path))
@@ -153,7 +154,7 @@ com_toggle(struct aps *aps, int fd, int argc, char **argv)
{
if (ptoggle(aps->player))
return errstr;
- return NULL;
+ return com_status(aps, fd, 0, NULL);
}
char *
@@ -173,6 +174,8 @@ com_next(struct aps *aps, int fd, int argc, char **argv)
return "Empty queue";
if (aps_play(aps, aps->queue->next))
return errstr;
+ if (aps_bufline(aps, fd, aps->queue->path))
+ return errstr;
return NULL;
}
@@ -183,6 +186,8 @@ com_previous(struct aps *aps, int fd, int argc, char **argv)
return "Empty queue";
if (aps_play(aps, aps->queue->prev))
return errstr;
+ if (aps_bufline(aps, fd, aps->queue->path))
+ return errstr;
return NULL;
}