Thread: [lastbash-cvs] lastbash lastbash,1.112,1.113
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2007-01-24 12:16:41
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1498 Modified Files: lastbash Log Message: Experimental support of user input for station change. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.112 retrieving revision 1.113 diff -u -d -r1.112 -r1.113 --- lastbash 24 Jan 2007 10:04:25 -0000 1.112 +++ lastbash 24 Jan 2007 12:16:34 -0000 1.113 @@ -202,7 +202,18 @@ debug "${FUNCNAME}: No missing programs" fi - # Check a minimum terminal size + # TODO Check some needed terminal capabilities + if tput longname >/dev/null 2>&1 + then + local TERM_LONGNAME="$(tput longname 2>/dev/null)" + debug "${FUNCNAME}: Using $(tput longname 2>/dev/null)" + else + debug "${FUNCNAME}: Unknown terminal: ${TERM}" + echo "Unknown terminal: ${TERM}" + exit 1 + fi + + # Ask for a minimum terminal size T_LINES=$(tput lines) T_COLUMNS=$(tput cols) if [ "${T_LINES}" -lt 15 ] || [ "${T_COLUMNS}" -lt 40 ] @@ -791,6 +802,9 @@ #----------------------------------------------------------------------------- function term_init() { + # Initialize the terminal according to the type of terminal + # in the environmental variable TERM + tput init # Enter special mode tput smcup # Set a welcome xterm title @@ -1626,6 +1640,238 @@ tui_sbar } +# Function: TUI for changing the station: input dialog {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_input() +{ + # $1 - PARAMETER to store the input in + # $2 - prompt + + local RET READ_PARAMS + + # Move the cursor on lower-left corner and print + tput cup ${T_LINES} 0 + echo -ne "${T_COLOR_WHITE}${T_BGCOLOR_BLUE}${T_EL}" + # Make cursor normal visible + tput cnorm + # Enable terminal echo mode + stty echo + + # Add the prompt, if specified + [ "$2" ] && READ_PARAMS="-p $2: " + # Read the user input + if read -t 10 -e "${READ_PARAMS}" ${1} + then + [ "${!1}" ] && RET="0" || RET="1" + else + RET="2" + fi + + # Disable terminal echo mode + stty -echo + # Make cursor invisible + tput civis + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: full url {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_url() +{ + local RET INPUT + + if tui_station_change_input INPUT "Last.fm URL" + then + if tui_lastfm_station "${INPUT}" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: global tags {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_globaltags() +{ + local RET INPUT + + if tui_station_change_input INPUT "Tags" + then + if tui_lastfm_station "lastfm://globaltags/${INPUT}" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: group station {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_group() +{ + local RET INPUT + + if tui_station_change_input INPUT "Group" + then + if tui_lastfm_station "lastfm://group/${INPUT}" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: neighbours' station {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_neighbours() +{ + local RET INPUT + + if tui_station_change_input INPUT "User's neighbours" + then + if tui_lastfm_station "lastfm://user/${INPUT}/neighbours" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: recommended {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_recommended() +{ + local RET INPUT + + if tui_station_change_input INPUT "Recommended to user" + then + if tui_lastfm_station "lastfm://user/${INPUT}/recommended/100" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: similar artists {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_similarartists() +{ + local RET INPUT + + if tui_station_change_input INPUT "Similar artists to" + then + if tui_lastfm_station "lastfm://artist/${INPUT}/similarartists" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + +# Function: TUI for changing the station: fan {{{1 +#----------------------------------------------------------------------------- +function tui_station_change_fan() +{ + local RET INPUT + + if tui_station_change_input INPUT "Artist fan" + then + if tui_lastfm_station "lastfm://artist/${INPUT}/fans" + then + RET="0" + # Restore the metadata + tui_metadata + else + RET="1" + # Restore the status bar + tui_sbar + fi + else + RET="2" + # Restore the status bar + tui_sbar + fi + + # Return the status code + return "${RET}" +} + # Function: Check if the player is running {{{1 #----------------------------------------------------------------------------- function player_running() @@ -2109,6 +2355,14 @@ "${CTRL_L}") sigwinch ;; # Toggle debug mode "${CTRL_D}") tui_debug_toggle ;; + # Change station + "u") tui_station_change_url ;; + "t") tui_station_change_globaltags ;; + "g") tui_station_change_group ;; + "n") tui_station_change_neighbours ;; + "c") tui_station_change_recommended ;; + "a") tui_station_change_similarartists ;; + "f") tui_station_change_fan ;; # Player commands "x") player_load ;; "${CTRL_X}") player_start ;; |