Update of /cvsroot/lastbash/lastbash
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21272
Modified Files:
lastbash
Log Message:
First use of ncurses.
Index: lastbash
===================================================================
RCS file: /cvsroot/lastbash/lastbash/lastbash,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- lastbash 29 Nov 2006 12:53:38 -0000 1.55
+++ lastbash 29 Nov 2006 14:37:52 -0000 1.56
@@ -60,7 +60,7 @@
# Internal stuff
PLAYERS="mplayer"
-REQ_PROGRAMS="md5sum dd"
+REQ_PROGRAMS="tput md5sum dd"
declare -a HTTP_HEADERS HTTP_RESPONSE
CR=$'\x0d'
LF=$'\x0a'
@@ -402,13 +402,43 @@
function term_init()
{
# Enter special mode
- echo -ne '\e[?1049h'
+ tput smcup
# Set a welcome xterm title
set_xterm "Welcome to ${PROG_TITLE}!"
+
+ # Define colors
+ T_COLOR_BLACK="$(tput setaf 0)"
+ T_COLOR_RED="$(tput setaf 1)"
+ T_COLOR_GREEN="$(tput setaf 2)"
+ T_COLOR_YELLOW="$(tput setaf 3)"
+ T_COLOR_BLUE="$(tput setaf 4)"
+ T_COLOR_MAGENTA="$(tput setaf 5)"
+ T_COLOR_CYAN="$(tput setaf 6)"
+ T_COLOR_WHITE="$(tput setaf 7)"
+ T_BGCOLOR_BLACK="$(tput setab 0)"
+ T_BGCOLOR_RED="$(tput setab 1)"
+ T_BGCOLOR_GREEN="$(tput setab 2)"
+ T_BGCOLOR_YELLOW="$(tput setab 3)"
+ T_BGCOLOR_BLUE="$(tput setab 4)"
+ T_BGCOLOR_MAGENTA="$(tput setab 5)"
+ T_BGCOLOR_CYAN="$(tput setab 6)"
+ T_BGCOLOR_WHITE="$(tput setab 7)"
+
+ # Define attributes
+ T_BOLD="$(tput bold)"
+ T_REV="$(tput rev)"
+ T_BLINK="$(tput blink)"
+ T_INVIS="$(tput invis)"
+ T_ULINE="$(tput smul)"
+ T_NORMAL="\e[0m"
+
+ # Some more escape sequences
+ T_EL="$(tput el)"
+
# Set the initial terminal size related settings
term_resize
# Make cursor invisible
- echo -ne '\e[?25l' # tput civis
+ tput civis
}
# Function: Exit the terminal {{{1
@@ -418,13 +448,13 @@
# Set a goodbye xterm title
set_xterm "Thank you for flying ${PROG_TITLE}!"
# Make sure to reset the scrolling area
- echo -ne "\e[0;${T_LINES}r"
+ tput csr 0 ${T_LINES}
# Move the cursor on upper-left corner and clear the entire screen
- echo -ne "\e[H\e[2J"
- # Make cursor visible
- echo -ne '\e[?12;25h' # tput cvvis
+ tput clear
+ # Make cursor normal visible
+ tput cnorm
# Exit special mode
- echo -ne '\e[?1049l'
+ tput rmcup
}
# Function: Compute some lengths when the terminal has been resized {{{1
@@ -432,16 +462,15 @@
function term_resize()
{
# Find the screen size
- STTY_SIZE=$(stty size)
- T_LINES=${STTY_SIZE% *}
- T_COLUMNS=${STTY_SIZE#* }
+ T_LINES=$(tput lines)
+ T_COLUMNS=$(tput cols)
# FIXME Request a minimal size or exit
T_LASTLINE=$(( T_LINES - 1 ))
T_LASTCOLUMN=$(( T_COLUMNS - 1 ))
# Scroll area related settings
- TSCROLL_FIRST=11
- TSCROLL_LAST=$(( T_LINES - 2 ))
+ TSCROLL_FIRST=10
+ TSCROLL_LAST=$(( T_LASTLINE - 2 ))
TSCROLL_CURRENT=${TSCROLL_FIRST}
# Set the info line field sizes
@@ -473,7 +502,7 @@
function tui_start()
{
# Move the cursor on upper-left corner and clear the entire screen
- echo -ne "\e[H\e[2J"
+ tput clear
# Display the main parts
tui_header
@@ -491,7 +520,8 @@
# Format the header line
printf -v H_LINE " %${S}s " "${PROG_TITLE} v${PROG_VER}"
# Move the cursor on upper-left corner and print
- echo -ne "\e[H\e[0;37;44m${H_LINE}\e[0;39m\e[0;49m"
+ tput home
+ echo -ne "\e[0;37;44m${H_LINE}\e[0;39m\e[0;49m"
}
# Function: Display the history header {{{1
@@ -530,7 +560,8 @@
LINE="${LINE}${FIELD}"
# Move the cursor and print
- echo -ne "\e[9;0H\e[0;37;44m${LINE}\e[0;39m\e[0;49m"
+ tput cup 8 0
+ echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m"
}
@@ -565,7 +596,8 @@
printf -v LINE " %-${S}s %-15s [%s] " "Not streaming" "$LASTFM_USER" "$LEDS"
fi
# Move the cursor on lower-left corner and print
- echo -ne "\e[${T_LINES};0H\e[0;37;44m${LINE}\e[0;39m\e[0;49m"
+ tput cup ${T_LINES} 0
+ echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m"
}
# Function: Display the keys {{{1
@@ -576,7 +608,8 @@
printf -v LINE " \e[1;44m%1s\e[0;44m %s " "R" "Refresh" "L" "Love" "B" "Ban" "K" "Skip" "P" "RTP" "D" "Discovery" "Q" "Quit"
# Move the cursor on lower-left corner and print
- echo -ne "\e[${T_LINES};0H\e[0;37;44m Keys: ${LINE}\e[K\e[0;39m\e[0;49m"
+ tput cup ${T_LINES} 0
+ echo -ne "\e[0;37;44m Keys: ${LINE}${T_EL}\e[0;39m\e[0;49m"
}
# Function: Display the current metadata {{{1
@@ -586,16 +619,20 @@
local LINE ACTION
printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}"
- echo -ne "\e[3;2H${LINE}\e[K"
+ tput cup 2 2
+ echo -ne "${LINE}${T_EL}"
printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_TRACK}" "${META_TRACK:0:$TCURRENT_MAX}"
- echo -ne "\e[4;2H${LINE}\e[K"
+ tput cup 3 2
+ echo -ne "${LINE}${T_EL}"
printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ALBUM}" "${META_ALBUM:0:$TCURRENT_MAX}"
- echo -ne "\e[5;2H${LINE}\e[K"
+ tput cup 4 2
+ echo -ne "${LINE}${T_EL}"
printf -v LINE "\e[1m%7s\e[0m : %d:%02d" "${LBL_LENGTH}" "${META_MIN}" "${META_SEC}"
- echo -ne "\e[6;2H${LINE}\e[K"
+ tput cup 5 2
+ echo -ne "${LINE}${T_EL}"
if [ "${META_ACTION_LOVE}" ]
then
@@ -611,7 +648,8 @@
fi
printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ACTION}" "${ACTION}"
- echo -ne "\e[7;2H${LINE}\e[K"
+ tput cup 6 2
+ echo -ne "${LINE}${T_EL}"
# Set the xterm title
if [ "${META_STREAMING}" == "true" ]
@@ -627,24 +665,24 @@
function tui_history()
{
# Define the scroll area
- echo -ne "\e[${TSCROLL_FIRST};${TSCROLL_LAST}r"
+ tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST}
if [ "${HISTORY_SCROLL_DOWN}" == "y" ]
then
# Move the cursor on the first line of the scrolling area
- echo -ne "\e[${TSCROLL_FIRST};0H"
+ tput cup ${TSCROLL_FIRST} 0
# Scroll down one line
- echo -ne "\eM"
+ tput il1
else
if [ ${TSCROLL_CURRENT} -gt ${TSCROLL_LAST} ]
then
# Move the cursor on the last line of the scrolling area
- echo -ne "\e[${TSCROLL_LAST};0H"
+ tput cup ${TSCROLL_LAST} 0
# Scroll up one line
- echo -ne "\x0A"
+ tput ind
else
# Move the cursor on the current line
- echo -ne "\e[${TSCROLL_CURRENT};0H"
+ tput cup ${TSCROLL_CURRENT} 0
fi
fi
@@ -655,7 +693,7 @@
(( TSCROLL_CURRENT++ ))
# Restore the whole screen as scrolling area
- echo -ne "\e[0;${T_LINES}r"
+ tput csr 0 ${T_LINES}
}
# Function: Display the line in history area {{{1
|