[lastbash-cvs] lastbash lastbash,1.92,1.93
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-08 13:49:15
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30145 Modified Files: lastbash Log Message: Debugging function improved. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.92 retrieving revision 1.93 diff -u -d -r1.92 -r1.93 --- lastbash 8 Dec 2006 12:48:54 -0000 1.92 +++ lastbash 8 Dec 2006 13:49:10 -0000 1.93 @@ -68,6 +68,7 @@ declare -a HISTORY_ARTIST HISTORY_ALBUM HISTORY_TRACK HISTORY_DURATION HISTORY_MIN_SEC HISTORY_ACTION CR=$'\x0d' LF=$'\x0a' +CTRL_D=$'\x04' CTRL_L=$'\x0c' NUMBER_REGEXP="+([0-9])" @@ -102,18 +103,18 @@ #----------------------------------------------------------------------------- function debug_header() { - debug "------------------------------------------------" + debug "--------------------------------------------------------" debug " Debug session started on `date`" - debug "------------------------------------------------" + debug "--------------------------------------------------------" } # Function: Write the debug footer {{{1 #----------------------------------------------------------------------------- function debug_footer() { - debug "------------------------------------------------" + debug "--------------------------------------------------------" debug " Debug session ended on `date`" - debug "------------------------------------------------" + debug "--------------------------------------------------------" } # Function: Set the xterm title {{{1 @@ -163,7 +164,7 @@ fi # Check some required programs - debug "Checking for missing programs..." + debug "${FUNCNAME}: Checking for missing programs..." for P in ${REQ_PROGRAMS} do type -t "${P}" >/dev/null 2>&1 || MP="${MP}${P} " @@ -171,11 +172,11 @@ if [ "${MP}" ] then - debug "Missing: ${MP}" + debug "${FUNCNAME}: Missing programs: ${MP}" echo "The following required programs are missing: ${MP}" exit 1 else - debug "No missing programs." + debug "${FUNCNAME}: No missing programs" fi # Check a minimum terminal size @@ -184,7 +185,7 @@ if [ "${T_LINES}" -lt 15 ] || [ "${T_COLUMNS}" -lt 40 ] then echo "Minimum terminal size is 40x15, your is ${T_COLUMNS}x${T_LINES}" - debug "Terminal size insufficient: ${T_COLUMNS}x${T_LINES}" + debug "${FUNCNAME}: Terminal size insufficient: ${T_COLUMNS}x${T_LINES}" exit 1 fi @@ -200,11 +201,11 @@ then if [ "${REFRESH_INTERVAL}" -lt "30" ] then - debug "Refresh interval too short: ${REFRESH_INTERVAL}" + debug "${FUNCNAME}: Refresh interval too short: ${REFRESH_INTERVAL}" REFRESH_INTERVAL="30" fi else - debug "Refresh interval not numerical: ${REFRESH_INTERVAL}" + debug "${FUNCNAME}: Refresh interval not numerical: ${REFRESH_INTERVAL}" REFRESH_INTERVAL="30" fi @@ -212,27 +213,27 @@ if [ "${PLAYER}" == "auto" ] then PLAYER="" - debug "Searching for available and supported players..." + debug "${FUNCNAME}: Searching for available and supported players..." # Search for the first supported player for P in ${PLAYERS} do - debug "Trying ${P}..." + debug "${FUNCNAME}: Trying ${P}..." if type -t "${P}" >/dev/null 2>&1 then - debug "Player found: ${P}" + debug "${FUNCNAME}: Player found: ${P}" PLAYER="${P}" break fi done # No player is present - [ ! "${PLAYER}" ] && debug "No supported player found." + [ ! "${PLAYER}" ] && debug "${FUNCNAME}: no supported player found" else if type -t "${PLAYER}" >/dev/null 2>&1 then - debug "Player found: ${PLAYER}" + debug "${FUNCNAME}: Player found: ${PLAYER}" else # The player is not present, switching to none - debug "Player ${PLAYER} not found." + debug "${FUNCNAME}: Player ${PLAYER} not found" PLAYER="" fi fi @@ -240,18 +241,18 @@ # Check for http client if [ "${HTTP_CLIENT}" == "builtin" ] then - debug "Using the builtin HTTP client." + debug "${FUNCNAME}: Using the builtin HTTP client" elif [ "${HTTP_CLIENT}" == "auto" ] then HTTP_CLIENT="" - debug "Searching for available and supported HTTP clients..." + debug "${FUNCNAME}: Searching for available and supported HTTP clients..." # Search for the first supported http client for P in ${HTTP_CLIENTS} do - debug "Trying ${P}..." + debug "${FUNCNAME}: Trying ${P}..." if type -t "${P}" >/dev/null 2>&1 then - debug "HTTP client found: ${P}" + debug "${FUNCNAME}: HTTP client found: ${P}" HTTP_CLIENT="${P}" break fi @@ -259,16 +260,16 @@ # No HTTP client is present if [ ! "${HTTP_CLIENT}" ] then - debug "No supported HTTP client found, using the builtin one." + debug "${FUNCNAME}: No supported HTTP client found, using the builtin one" HTTP_CLIENT="builtin" fi else if type -t "${HTTP_CLIENT}" >/dev/null 2>&1 then - debug "HTTP client found: ${HTTP_CLIENT}" + debug "${FUNCNAME}: HTTP client found: ${HTTP_CLIENT}" else # The HTTP client is not present, switching to builtin - debug "HTTP client ${HTTP_CLIENT} not found." + debug "${FUNCNAME}: HTTP client ${HTTP_CLIENT} not found" HTTP_CLIENT="builtin" fi fi @@ -286,7 +287,7 @@ tui_sbar "Quitting. Good bye." # Stop the player, if running - player_stop + player_quit # Restore the terminal term_exit @@ -655,14 +656,14 @@ if [ "${WS_RESPONSE}" != "OK" ] then RET="2" - debug "${FUNCNAME}: Command failed, unknown error" + debug "${FUNCNAME}: Command \"$2\" failed, unknown error" else RET="0" - debug "${FUNCNAME}: Command sent" + debug "${FUNCNAME}: Command \"$2\" sent successfully" fi else RET="1" - debug "${FUNCNAME}: Command failed" + debug "${FUNCNAME}: Command \"$2\" failed" fi # Return the status code @@ -711,7 +712,7 @@ "7") RET="8"; ERRMSG="Streaming system is offline for maintenance" ;; *) RET="255"; ERRMSG="Changing station failed for unknown error" ;; esac - debug "${FUNCNAME}: ${WS_ERROR}. ${ERRMSG}" + debug "${FUNCNAME}: Error ${WS_ERROR}. ${ERRMSG}" else RET="0" debug "${FUNCNAME}: Station changed" @@ -962,10 +963,11 @@ # - R: the player is running # - P: record to profile is on # - D: Discovery mode is on + # - B: Debug mode is on L1="-" [ "${META_RTP}" == "1" ] && L2="P" || L2="-" [ "${META_DISCOVERY}" == "1" ] && L3="D" || L3="-" - L4="-" + [ "${DEBUG}" == "y" ] && L4="B" || L4="-" # Compute the main field size S=$(( T_COLUMNS - 27 )) @@ -1567,12 +1569,12 @@ if [ "${DEBUG}" == "y" ] then tui_sbar "Debug mode disabled" - DEBUG="n" debug_footer + DEBUG="n" else tui_sbar "Debug mode enabled" - DEBUG="y" debug_header + DEBUG="y" fi # Sleep one moment and restore the status bar @@ -1591,6 +1593,7 @@ if [ -p "${PLAYER_PIPE}" ] then echo "$1" > "${PLAYER_PIPE}" + debug "${FUNCNAME} (${PLAYER}): $1" fi } @@ -1599,14 +1602,14 @@ function player_start() { # Return if no player is to be used - [ "${USE_PLAYER}" != "y" ] || return + [ "${USE_PLAYER}" != "y" ] && return if ! type -t mkfifo >/dev/null 2>&1 then tui_sbar "No way to control the player, mkfifo is absent" "2" - debug "No way to control the player, mkfifo is absent" + debug "${FUNCNAME}: mkfifo is absent" USE_PLAYER="n" - return + return 1 fi # Set the status line @@ -1618,15 +1621,26 @@ rm -f "${PLAYER_PIPE}" fi mkfifo -m 600 "${PLAYER_PIPE}" + if [ -p "${PLAYER_PIPE}" ] + then + debug "${FUNCNAME}: Pipe created" + else + debug "${FUNCNAME}: Pipe not created" + tui_sbar "Unable to create the player controlling pipe" "1" + return 1 + fi # Start the player in background if [ "${PLAYER}" == "mplayer" ] then mplayer -cache 512 -idle -slave -quiet -input file="${PLAYER_PIPE}" >/dev/null 2>&1 & + debug "${FUNCNAME}: Player ${PLAYER} started" elif [ "${PLAYER}" == "mpg123" ] then mpg123 --remote --remote-err --quiet <"${PLAYER_PIPE}" >/dev/null 2>&1 & + debug "${FUNCNAME}: Player ${PLAYER} started" else + debug "${FUNCNAME}: No player started" tui_sbar "No supported player found" fi @@ -1634,7 +1648,7 @@ sleep 1 # Update the status line - tui_sbar "Player started" + tui_sbar "Player started (${PLAYER})" [ "${AUTO_PLAY}" == "y" ] && player_load } @@ -1644,13 +1658,12 @@ function player_load() { # Return if no player is to be used - [ "${USE_PLAYER}" != "y" ] || return + [ "${USE_PLAYER}" != "y" ] && return # Set the status line tui_sbar "Loading the stream..." # Load the stream and start playing - tui_sbar "Playing..." if [ "${PLAYER}" == "mplayer" ] then player_command "loadfile ${LASTFM_STREAM}" @@ -1658,6 +1671,7 @@ then player_command "load ${LASTFM_STREAM}" else + debug "${FUNCNAME}: No player running" tui_sbar "No supported player is running" fi @@ -1672,13 +1686,12 @@ #----------------------------------------------------------------------------- function player_stop() { - [ "${USE_PLAYER}" != "y" ] || return + [ "${USE_PLAYER}" != "y" ] && return # Set the status line - tui_sbar "Stop playing..." + tui_sbar "Stop playing the stream..." player_command "stop" - rm -f "${PLAYER_PIPE}" # Restore the status bar sleep 1 @@ -1689,7 +1702,7 @@ #----------------------------------------------------------------------------- function player_quit() { - [ "${USE_PLAYER}" != "y" ] || return + [ "${USE_PLAYER}" != "y" ] && return # Set the status line tui_sbar "Closing the player..." @@ -1702,13 +1715,17 @@ killall mpg123 else tui_sbar "No supported player is running" + debug "${FUNCNAME}: No player running" fi + # Wait a second + sleep 1 + # Remove the FIFO rm -f "${PLAYER_PIPE}" # Set the status line - tui_sbar "Player closed" "1" + tui_sbar "Player closed" } # Function: Check if another instance is running {{{1 @@ -1869,10 +1886,11 @@ "k") tui_lastfm_command_skip ;; "p") tui_lastfm_rtp ;; "d") tui_lastfm_discovery ;; - "D") tui_debug_toggle ;; "s") tui_scroll_toggle ;; # Redisplay the TUI "${CTRL_L}") sigwinch ;; + # Toggle debug mode + "${CTRL_D}") tui_debug_toggle ;; # Player commands "x") player_load ;; "X") player_start ;; |