Update of /cvsroot/lastbash/lastbash
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9583
Modified Files:
lastbash
Log Message:
Keep the history in memory and redisplay it when resize. Added support for toggling the scrolling direction.
Index: lastbash
===================================================================
RCS file: /cvsroot/lastbash/lastbash/lastbash,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- lastbash 5 Dec 2006 12:53:49 -0000 1.75
+++ lastbash 5 Dec 2006 15:39:26 -0000 1.76
@@ -950,6 +950,14 @@
#-----------------------------------------------------------------------------
function tui_history()
{
+ # $1 - index of HISTORY array to display
+
+ # Return if the index is invalid
+ if [ "$1" -ge "${#HISTORY_ARTIST[*]}" ] || [ "$1" -lt 0 ]
+ then
+ return
+ fi
+
# Define the scroll area
tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST}
@@ -973,7 +981,7 @@
fi
# Display the history line
- tui_history_line
+ tui_history_line "$1"
# Increment the current line number
(( TSCROLL_CURRENT++ ))
@@ -982,16 +990,62 @@
tput csr 0 ${T_LINES}
}
+# Function: Re-display the whole history area {{{1
+#-----------------------------------------------------------------------------
+function tui_history_redisplay()
+{
+ local SCROLL_LINES="$(( TSCROLL_LAST - TSCROLL_FIRST + 1 ))"
+ [ "${SCROLL_LINES}" -lt 0 ] && SCROLL_LINES="0"
+ local HLAST="${#HISTORY_ARTIST[*]}"
+ local HFIRST="$(( HLAST - SCROLL_LINES ))"
+ [ "${HFIRST}" -lt 0 ] && HFIRST="0"
+ local INDEX HINDEX SLINE
+
+ # Define the scroll area
+ tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST}
+
+ for (( INDEX=0; INDEX < SCROLL_LINES; INDEX++ ))
+ do
+ # Compute the index to display
+ if [ "${HISTORY_SCROLL_DOWN}" == "y" ]
+ then
+ HINDEX="$(( HLAST - INDEX - 1 ))"
+ else
+ HINDEX="$(( HFIRST + INDEX ))"
+ fi
+
+ # Compute the scroll line number
+ SLINE="$(( TSCROLL_FIRST + INDEX ))"
+
+ # Check the index, move the cursor and print the line
+ if [ "${HINDEX}" -lt "${HLAST}" ] && [ "${HINDEX}" -ge 0 ]
+ then
+ # Move the cursor on the determined line
+ tput cup ${SLINE} 0
+ # Display the history line
+ tui_history_line "${HINDEX}"
+ fi
+ done
+
+ # Compute the scroll line number
+ TSCROLL_CURRENT="$(( TSCROLL_FIRST + HLAST ))"
+
+ # Restore the whole screen as scrolling area
+ tput csr 0 ${T_LINES}
+}
+
# Function: Display the line in history area {{{1
#-----------------------------------------------------------------------------
function tui_history_line()
{
+ # $1 - index in HISTORY array
+
local FIELD LINE S
# Start with the love/ban indicator
- if [ "${PREV_ACTION}" ]
+ if [ "${HISTORY_ACTION[$1]}" ]
then
- LINE=" ${PREV_ACTION:0:1}"
+ LINE=" ${HISTORY_ACTION[$1]:0:1}"
else
LINE=" "
fi
@@ -1000,7 +1054,7 @@
if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ]
then
S="${HISTORY_FIELD_SIZE[0]}"
- printf -v FIELD " %-${S}s" "${PREV_ARTIST:0:$S}"
+ printf -v FIELD " %-${S}s" "${HISTORY_ARTIST[$1]:0:$S}"
LINE="${LINE}${FIELD}"
fi
@@ -1008,17 +1062,17 @@
if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ]
then
S="${HISTORY_FIELD_SIZE[1]}"
- printf -v FIELD " %-${S}s" "${PREV_ALBUM:0:$S}"
+ printf -v FIELD " %-${S}s" "${HISTORY_ALBUM[$1]:0:$S}"
LINE="${LINE}${FIELD}"
fi
# Add the track title
S="${HISTORY_FIELD_SIZE[2]}"
- printf -v FIELD " %-${S}s" "${PREV_TRACK:0:$S}"
+ printf -v FIELD " %-${S}s" "${HISTORY_TRACK[$1]:0:$S}"
LINE="${LINE}${FIELD}"
# Add the track duration
- printf -v FIELD " %6s " "${PREV_MIN_SEC}"
+ printf -v FIELD " %6s " "${HISTORY_MIN_SEC[$1]}"
LINE="${LINE}${FIELD}"
# Output the line
@@ -1029,7 +1083,7 @@
#-----------------------------------------------------------------------------
function tui_metadata()
{
- local RET
+ local RET HINDEX
# Save the current metadata
local PREV_ARTIST="${META_ARTIST}"
@@ -1051,15 +1105,6 @@
[ "${META_TRACK}" != "${PREV_TRACK}" ] || \
[ "${META_DURATION}" != "${PREV_DURATION}" ]
then
- # Save in history
- HINDEX="${#HISTORY_ARTIST[*]}"
- HISTORY_ARTIST[$HINDEX]="${PREV_ARTIST}"
- HISTORY_ALBUM[$HINDEX]="${PREV_ALBUM}"
- HISTORY_TRACK[$HINDEX]="${PREV_TRACK}"
- HISTORY_DURATION[$HINDEX]="${PREV_DURATION}"
- HISTORY_MIN_SEC[$HINDEX]="${PREV_MIN_SEC}"
- HISTORY_ACTION[$HINDEX]="${META_ACTION}"
-
# Clear the action
unset META_ACTION META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN
@@ -1070,12 +1115,23 @@
else
unset META_MIN_SEC
fi
+
# Refresh the display
tui_current
+
# Add to history if there is anything to add
if [ "${PREV_ARTIST}" ] || [ "${PREV_ALBUM}" ] || [ "${PREV_TRACK}" ]
then
- tui_history
+ # Save in history
+ HINDEX="${#HISTORY_ARTIST[*]}"
+ HISTORY_ARTIST[$HINDEX]="${PREV_ARTIST}"
+ HISTORY_ALBUM[$HINDEX]="${PREV_ALBUM}"
+ HISTORY_TRACK[$HINDEX]="${PREV_TRACK}"
+ HISTORY_DURATION[$HINDEX]="${PREV_DURATION}"
+ HISTORY_MIN_SEC[$HINDEX]="${PREV_MIN_SEC}"
+ HISTORY_ACTION[$HINDEX]="${META_ACTION}"
+
+ tui_history "${HINDEX}"
fi
fi
RET="0"
@@ -1338,6 +1394,27 @@
return "${RET}"
}
+# Function: TUI for toggling history scrolling direction {{{1
+#-----------------------------------------------------------------------------
+function tui_scroll_toggle()
+{
+ if [ "${HISTORY_SCROLL_DOWN}" == "y" ]
+ then
+ tui_sbar "History scroll upward"
+ HISTORY_SCROLL_DOWN="n"
+ else
+ tui_sbar "History scroll downward"
+ HISTORY_SCROLL_DOWN="y"
+ fi
+
+ # Redisplay the scrolling area
+ tui_history_redisplay
+
+ # Sleep one moment and restore the status bar
+ sleep 1
+ tui_sbar
+}
+
# Function: Send commands to the player {{{1
#-----------------------------------------------------------------------------
function player_command()
@@ -1593,7 +1670,7 @@
# Redisplay the TUI
tui_start
tui_current
- tui_history
+ tui_history_redisplay
}
@@ -1612,6 +1689,7 @@
"k") tui_lastfm_command_skip ;;
"p") tui_lastfm_rtp ;;
"d") tui_lastfm_discovery ;;
+ "s") tui_scroll_toggle ;;
# Redisplay the TUI
"${CTRL_L}") sigwinch ;;
# Player commands
|