[lastbash-cvs] lastbash lastbash,1.76,1.77
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-05 16:42:43
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2471 Modified Files: lastbash Log Message: Better support for quitting by trapping signals. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.76 retrieving revision 1.77 diff -u -d -r1.76 -r1.77 --- lastbash 5 Dec 2006 15:39:26 -0000 1.76 +++ lastbash 5 Dec 2006 16:42:36 -0000 1.77 @@ -236,6 +236,29 @@ fi } +# Function: Quit {{{1 +#----------------------------------------------------------------------------- +function quit() +{ + # $1 - exit code + + if [ "${FIRST_INSTANCE}" ] + then + # One last message + tui_sbar "Quitting. Good bye." + + # Stop the player, if running + player_stop + + # Restore the terminal + term_exit + + # Eventually, save the settings + #save_settings + fi + exit $1 +} + # Function: Save the settings {{{1 #----------------------------------------------------------------------------- function save_settings() @@ -1612,7 +1635,8 @@ "LOVE") tui_lastfm_command_love ;; "RTP") tui_lastfm_rtp ;; # Quit - #"QUIT") DONE="y" ;; + # FIXME Terminal left in wrong status + "QUIT") quit 0 ;; # Any other command *) tui_sbar "Command not understood: $1" @@ -1673,6 +1697,23 @@ tui_history_redisplay } +# Function: Receive the INT and TERM signals {{{1 +#----------------------------------------------------------------------------- +function sigint() +{ + quit 0 +} + +# Function: Receive the EXIT signal {{{1 +#----------------------------------------------------------------------------- +function sigexit() +{ + if [ "${FIRST_INSTANCE}" ] + then + # Remove stale files + rm -f "${PID_FILE}" "${PLAYER_PIPE}" "${COMMAND_FILE}" "${COMMAND_FILE_LOCK}" + fi +} # Function: The read key loop {{{1 #----------------------------------------------------------------------------- @@ -1744,11 +1785,14 @@ debug " Debug started on `date`" debug "------------------------------------------------" +# Set a parameter, if this is the first instance +first_instance && FIRST_INSTANCE="y" + # This should be the Last.fm station if [[ "$1" =~ "^lastfm://" ]] then # This is the new station to tune into - if first_instance + if [ "${FIRST_INSTANCE}" ] then # Store the station to load after the init LASTFM_STATION="$1" @@ -1765,7 +1809,7 @@ fi # Check if this is not the first instance -if ! first_instance +if [ ! "${FIRST_INSTANCE}" ] then # Check if there is a command to execute if [ "${LASTFM_COMMAND}" ] @@ -1774,7 +1818,7 @@ exit 0 else # Nothing to do - echo "There is another program instance running" + echo "There is another program instance running (PID: $(<${PID_FILE}))" exit 1 fi fi @@ -1788,10 +1832,14 @@ # Now, let's save the PID echo -n $$ > "${PID_FILE}" # And trap the HUP signal -trap sighup SIGHUP +trap sighup HUP # Trap the WINCH signal, too -trap sigwinch SIGWINCH +trap sigwinch WINCH + +# Trap INT, TERM and EXIT signals +trap sigint INT TERM +trap sigexit EXIT # Initialize the terminal term_init @@ -1808,17 +1856,12 @@ tui_metadata # Enter the readkey loop read_key_loop - # Stop the player - player_stop else # Wait for the user read the status and exit read -n 1 -s -t ${REFRESH_INTERVAL} JUNK fi -# Restore the terminal -term_exit - -# On exit, save the data -#save_settings +# Quit +quit 0 # vim: set ft=sh nowrap nu foldmethod=marker: |