3 This is a small interface for the amused music player
5 => https://projects.omarpolo.com/amused.html amused
9 It's written in rc because I found easier to manage subprocesses in it
12 There are two main processes involved: input and ui. The input
13 process handles the keybindings and controls amused, the ui input
14 waits for some events and redraws the interface.
19 $ifs needs to be set to the empty list (or empty string), otherwise
20 we're not able to read spaces as keybindings.
25 rc lacks a break statement, so I'm using a flag variable to quit
29 t=`{dd bs=1 count=1 status=none}
32 This is just a trick to read without echoing back the characters.
46 printf ' unknown keybinding >'$t'<\r'
51 The ui functions render the interface. I'd like to keep a small xterm
52 open, that's why I'm narrowing (with grep -A -B) only to the songs
53 around the currently played one.
57 amused show -p | grep -A3 -B3 '^>' | awk '{printf "%s\r\n", $0}'
59 The awk trick deserves an explanation. Since the input function is
60 very likely running, the terminal is in "raw" mode: we need \r to
61 reposition the character at the start of the line.
65 The uiloop function is the driver for the ui process: it listens to
66 interesting events and redraws the ui when they happen
69 amused monitor next,prev,jump | {
74 A small note of merit: unlike other shells read is not a built in in
75 rc bur rather an external command (/usr/local/plan9/bin/read here.)
80 And that's all. I only need to launch the functions in the correct
81 order and do one render at the start and amused-monitor is done!