From 964d1abdb0e6d27df2e7041e7db20433f4fb3ce9 Mon Sep 17 00:00:00 2001
From: Luke Shumaker <lukeshu@sbcglobal.net>
Date: Tue, 1 Jul 2014 16:10:20 -0400
Subject: Make term_title gettext-aware (BREAKS COMPATIBILITY)

---
 src/dagpkg                   | 2 +-
 src/lib/libremessages        | 4 ++--
 src/lib/libremessages.1.ronn | 7 +++----
 src/lib/librexgettext        | 2 +-
 src/treepkg                  | 8 ++++----
 5 files changed, 11 insertions(+), 12 deletions(-)

(limited to 'src')

diff --git a/src/dagpkg b/src/dagpkg
index e1487d5..075bbe3 100755
--- a/src/dagpkg
+++ b/src/dagpkg
@@ -187,7 +187,7 @@ nl ${log} | while read order pkg; do
 	test -d "$pkg" || cp -r "$w" "$pkg"
 	pushd "$pkg" &>/dev/null
 
-	term_title "$pkg($order)"
+	term_title "%s(%s)" "$pkg" "$order"
 
 	msg "Building %s" ${pkg}
 
diff --git a/src/lib/libremessages b/src/lib/libremessages
index 188affd..db2fdde 100755
--- a/src/lib/libremessages
+++ b/src/lib/libremessages
@@ -112,7 +112,7 @@ flag() {
 	done
 }
 
-# Usage: term_title This will be the term title
+# Usage: term_title MESG [ARGS...]
 # Sets the terminal title
 term_title() {
 	[[ $# -ge 1 ]] || panic
@@ -121,7 +121,7 @@ term_title() {
 		screen|tmux) fmt='\ek%s\e\\';;
 		xterm*|rxvt*) fmt='\e]0;%s\a';;
 	esac
-	printf "$fmt" "$*"
+	printf "$fmt" "$(printf -- "$@")"
 }
 
 # Usage: setup_traps [handler]
diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn
index e660816..6f1ecf5 100644
--- a/src/lib/libremessages.1.ronn
+++ b/src/lib/libremessages.1.ronn
@@ -65,10 +65,6 @@ Unless otherwise noted, these do not implicitly call `gettext`.
      For the times when you can't reasonably continue, similar to
      "assert" in some programming languages.
 
-   * `term_title` <MESSAGE>...:
-     Joins all arguments with whitespace, and sets the terminal title
-     to that.
-
    * `setup_traps` [<HANDLER>]:
      Sets traps on TERM, HUP, QUIT and INT signals, as sell as the ERR
      event, similar to makepkg.  If <HANDLER> is specified, instead of
@@ -138,6 +134,9 @@ For each of these, <MESSAGE> is fed through `gettext` automatically.
    * `stat_done`:
      Prints a "done" type message to terminate `stat_busy`.
 
+   * `term_title` <MESSAGE> [<ARGS>...]:
+     Sets the terminal title to the specified message.
+
 ### TEMPORARY DIRECTORY MANAGEMENT
 
 These are used by devtools, and not used within the rest of
diff --git a/src/lib/librexgettext b/src/lib/librexgettext
index f680784..3bee937 100755
--- a/src/lib/librexgettext
+++ b/src/lib/librexgettext
@@ -21,7 +21,7 @@ export TEXTDOMAINDIR='/usr/share/locale'
 
 default_simple=(
 	--keyword={eval_,}{gettext,'ngettext:1,2'}
-	--keyword={_,print}
+	--keyword={_,print,term_title}
 	--keyword={msg,msg2,warning,error,stat_busy,die}
 	--keyword={lock,slock}:3
 )
diff --git a/src/treepkg b/src/treepkg
index 9d3c0c3..f417010 100755
--- a/src/treepkg
+++ b/src/treepkg
@@ -27,11 +27,11 @@ check_vars libretools FULLBUILDCMD || exit 1
 #check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1
 load_files makepkg
 
-term_title "${0##*/}"
+term_title "%s" "${0##*/}"
 
 # End inmediately but print an useful message
 trap_exit() {
-	term_title "${0##*/}: $(_ 'Error!')"
+	term_title "%s: Error!" "${0##*/}"
 	error "%s: %s (leftovers on %s" "${0##*/}" "$*" "${BUILDDIR}"
 	exit 1
 }
@@ -204,7 +204,7 @@ if [[ ${DEPTH} -eq 0 ]]; then
 			${VERBOSE} && msg "Building %s" "${_pkg/_/ }" || true
 
 			# Remove leading zeros and space if any
-			term_title "$(echo ${_pkg/_/ } | sed "s/^0\+ \?//")"
+			term_title "%s" "$(echo ${_pkg/_/ } | sed "s/^0\+ \?//")"
 
 			# Run build command
 			pushd "${BUILDDIR}/${_pkg}" >/dev/null
@@ -237,5 +237,5 @@ if [[ ${DEPTH} -eq 0 ]]; then
 
 fi
 
-term_title "$(_ Done)"
+term_title "Done"
 exit $?
-- 
cgit v1.2.3-54-g00ecf