[lastbash-cvs] SF.net SVN: lastbash: [231] lastbash/lastbash
Status: Beta
Brought to you by:
cstroie
From: <cs...@us...> - 2007-04-24 17:53:59
|
Revision: 231 http://lastbash.svn.sourceforge.net/lastbash/?rev=231&view=rev Author: cstroie Date: 2007-04-24 10:53:56 -0700 (Tue, 24 Apr 2007) Log Message: ----------- New method for string padding, improving the l10n display. Modified Paths: -------------- lastbash/lastbash Modified: lastbash/lastbash =================================================================== --- lastbash/lastbash 2007-04-17 17:17:51 UTC (rev 230) +++ lastbash/lastbash 2007-04-24 17:53:56 UTC (rev 231) @@ -415,6 +415,20 @@ fi fi + # Compute some string sizes and padding + local L LL + LBL_MAXLENGTH=0 + for L in LBL_ARTIST LBL_ALBUM LBL_TRACK LBL_LENGTH LBL_ACTION + do + LL=${!L} + if [ "${#LL}" -gt "${LBL_MAXLENGTH}" ] + then + LBL_MAXLENGTH="${#LL}" + TCURRENT_PADDING="${LL}" + fi + done + TCURRENT_PADDING=${TCURRENT_PADDING//?/ } + # INIT done debug "${FUNCNAME}: Init done" } @@ -985,6 +999,9 @@ T_LASTLINE=$(( T_LINES - 1 )) T_LASTCOLUMN=$(( T_COLUMNS - 1 )) + # One line of T_COLUMNS space characters + printf -v T_EMPTYLINE "%${T_COLUMNS}s" + # Scroll area related settings TSCROLL_FIRST=10 TSCROLL_LAST=$(( T_LASTLINE - 2 )) @@ -1009,6 +1026,11 @@ HISTORY_FIELD_SIZE[1]=$(( ${UNIT} * ${HISTORY_FIELD_UNITS[1]} )) HISTORY_FIELD_SIZE[2]=$(( ${VAR_LINE} - ${HISTORY_FIELD_SIZE[0]} - ${HISTORY_FIELD_SIZE[1]} )) HISTORY_FIELD_SIZE[3]="6" + # Create the padds + HISTORY_FIELD_PADD[0]=${T_EMPTYLINE:0:${HISTORY_FIELD_SIZE[0]}} + HISTORY_FIELD_PADD[1]=${T_EMPTYLINE:0:${HISTORY_FIELD_SIZE[1]}} + HISTORY_FIELD_PADD[2]=${T_EMPTYLINE:0:${HISTORY_FIELD_SIZE[2]}} + HISTORY_FIELD_PADD[3]=${T_EMPTYLINE:0:${HISTORY_FIELD_SIZE[3]}} # Compute the current max line length TCURRENT_MAX=$(( ${T_COLUMNS} - 13 )) @@ -1053,28 +1075,20 @@ # Add the artist, if the field units are not null if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] then - S="${HISTORY_FIELD_SIZE[0]}" - printf -v FIELD " %-${S}s" "${LBL_ARTIST:0:$S}" - LINE="${LINE}${FIELD}" + LINE="${LINE} ${LBL_ARTIST}${HISTORY_FIELD_PADD[0]:${#LBL_ARTIST}}" fi # Add the album, if the field units are not null if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] then - S="${HISTORY_FIELD_SIZE[1]}" - printf -v FIELD " %-${S}s" "${LBL_ALBUM:0:$S}" - LINE="${LINE}${FIELD}" + LINE="${LINE} ${LBL_ALBUM}${HISTORY_FIELD_PADD[1]:${#LBL_ALBUM}}" fi # Add the track title - S="${HISTORY_FIELD_SIZE[2]}" - printf -v FIELD " %-${S}s" "${LBL_TRACK:0:$S}" - LINE="${LINE}${FIELD}" + LINE="${LINE} ${LBL_TRACK}${HISTORY_FIELD_PADD[2]:${#LBL_TRACK}}" # Add the track duration - S="${HISTORY_FIELD_SIZE[3]}" - printf -v FIELD " %${S}s " "${LBL_LENGTH:0:$S}" - LINE="${LINE}${FIELD}" + LINE="${LINE} ${HISTORY_FIELD_PADD[3]:${#LBL_LENGTH}}${LBL_LENGTH:0:6} " # Move the cursor and print tput cup 8 0 @@ -1158,36 +1172,29 @@ #----------------------------------------------------------------------------- function tui_current() { - local LINE - - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}" tput cup 2 2 - echo -ne "${LINE}${T_EL}" + echo -ne "${T_ATTR_BOLD}${TCURRENT_PADDING:${#LBL_ARTIST}}${LBL_ARTIST}${T_ATTR_NORMAL} : ${META_ARTIST:0:$TCURRENT_MAX}${T_EL}" - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_TRACK}" "${META_TRACK:0:$TCURRENT_MAX}" tput cup 3 2 - echo -ne "${LINE}${T_EL}" + echo -ne "${T_ATTR_BOLD}${TCURRENT_PADDING:${#LBL_TRACK}}${LBL_TRACK}${T_ATTR_NORMAL} : ${META_TRACK:0:$TCURRENT_MAX}${T_EL}" - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ALBUM}" "${META_ALBUM:0:$TCURRENT_MAX}" tput cup 4 2 - echo -ne "${LINE}${T_EL}" + echo -ne "${T_ATTR_BOLD}${TCURRENT_PADDING:${#LBL_ALBUM}}${LBL_ALBUM}${T_ATTR_NORMAL} : ${META_ALBUM:0:$TCURRENT_MAX}${T_EL}" - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_LENGTH}" "${META_MIN_SEC}" tput cup 5 2 - echo -ne "${LINE}${T_EL}" + echo -ne "${T_ATTR_BOLD}${TCURRENT_PADDING:${#LBL_LENGTH}}${LBL_LENGTH}${T_ATTR_NORMAL} : ${META_MIN_SEC:0:$TCURRENT_MAX}${T_EL}" - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ACTION}" "${META_ACTION}" tput cup 6 2 - echo -ne "${LINE}${T_EL}" + echo -ne "${T_ATTR_BOLD}${TCURRENT_PADDING:${#LBL_ACTION}}${LBL_ACTION}${T_ATTR_NORMAL} : ${META_ACTION:0:$TCURRENT_MAX}${T_EL}" # Set the xterm title and save the now_playing file if [ "${META_STREAMING}" == "true" ] then set_term_title "${META_ARTIST} - ${META_TRACK}" save_nowplaying "${META_ARTIST} - ${META_TRACK}" - save_html "1" || tui_sbar "Error while creating the HTML file." + save_html "1" || tui_sbar $"Error while creating the HTML file." else - set_term_title "${PROG_TITLE}: Not streaming" + set_term_title $"Not streaming" save_nowplaying save_html fi @@ -1356,27 +1363,28 @@ # Add the artist, if the field units are not null if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] then - S="${HISTORY_FIELD_SIZE[0]}" - printf -v FIELD " %-${S}s" "${HISTORY_ARTIST[$1]:0:$S}" - LINE="${LINE}${FIELD}" + L="${HISTORY_FIELD_SIZE[0]}" + S="${HISTORY_ARTIST[$1]:0:$L}" + LINE="${LINE} ${S}${HISTORY_FIELD_PADD[0]:${#S}}" fi # Add the album, if the field units are not null if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] then - S="${HISTORY_FIELD_SIZE[1]}" - printf -v FIELD " %-${S}s" "${HISTORY_ALBUM[$1]:0:$S}" - LINE="${LINE}${FIELD}" + L="${HISTORY_FIELD_SIZE[1]}" + S="${HISTORY_ALBUM[$1]:0:$L}" + LINE="${LINE} ${S}${HISTORY_FIELD_PADD[1]:${#S}}" fi # Add the track title - S="${HISTORY_FIELD_SIZE[2]}" - printf -v FIELD " %-${S}s" "${HISTORY_TRACK[$1]:0:$S}" - LINE="${LINE}${FIELD}" + L="${HISTORY_FIELD_SIZE[2]}" + S="${HISTORY_TRACK[$1]:0:$L}" + LINE="${LINE} ${S}${HISTORY_FIELD_PADD[2]:${#S}}" # Add the track duration - printf -v FIELD " %6s " "${HISTORY_MIN_SEC[$1]}" - LINE="${LINE}${FIELD}" + L="${HISTORY_FIELD_SIZE[3]}" + S="${HISTORY_MIN_SEC[$1]:0:$L}" + LINE="${LINE} ${HISTORY_FIELD_PADD[3]:${#S}}${S} " # Output the line echo -n "${LINE}" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |