'       automatic music status viewer

'       keys

'       I       show ip addresses (if permitted)
'       C       show client
'       L       like currently playing song
'       W       show listener locations
'       A       show all channels

'       defaults
       where = 1
       delay = 1

'       funcs
       def fnchomp$( s$ ) = th_sed$( s$, "\s+$" )

'       unset baud
       th_exec "\set baud 0" ; devnull$

1       ' main loop
       opt$ = "" : optclient$ = "" : optip$ = "" : optwhere$ = "" : optall$ = ""

'       get options
       if ip then optip$ = "/ip "
       if client then optclient$ = "/client "
       if where then optwhere$ = "/where "
       if all then optall$ = "/all "

'       set options
       opt$ = optclient$ + optip$ + optwhere$ + optall$

'       get music
       th_exec "music /truncate " + opt$ + " " ; music$
       lp = 0 : o$ = ""
       for i = 0 to len( music$ )
               o$ = o$ + mid$( music$, i, 1 )
               if mid$( music$, i, 1 ) = chr$(13) then lp = lp + 1
               if lp >= height - 2 then gosub 3 : goto 2
       next i

       home : ? chr$(27) + "[2J" ; : ? o$

2       ' get key
       k$ = polkey$( delay )

       if k$ = "l" then th_exec "run like.bas" : sleep 2
       if k$ = "i" then ip = not ip
       if k$ = "w" then where = not where
       if k$ = "c" then client = not client
       if k$ = "a" then all = not all

       goto 1

3       ' print up to screen height and add ellipsis
       o$ = o$ + chr$(13) + chr$(10) + "  ..."
       home : ? chr$(27) + "[2J" ; : ? o$
       return