tools: gst-play: don't print 64 whitespaces next to the time indication
authorVivia Nikolaidou <vivia@ahiru.eu>
Tue, 9 Jun 2015 18:24:07 +0000 (21:24 +0300)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 9 Jun 2015 19:08:15 +0000 (20:08 +0100)
Printing 64 whitespaces to erase the "Paused" message (after \r) would make
it wrap to the next line on shorter terminals. Instead we only print the
amount of spaces needed. Also mark the "Paused" string for translation
while we're at it.

tools/gst-play.c

index 52f6d71..c9b6e73 100644 (file)
@@ -458,7 +458,8 @@ play_timeout (gpointer user_data)
 {
   GstPlay *play = user_data;
   gint64 pos = -1, dur = -1;
-  gchar status[64] = { 0, };
+  const gchar *paused = _("Paused");
+  gchar *status;
 
   if (play->buffering)
     return TRUE;
@@ -466,10 +467,14 @@ play_timeout (gpointer user_data)
   gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos);
   gst_element_query_duration (play->playbin, GST_FORMAT_TIME, &dur);
 
-  if (play->desired_state == GST_STATE_PAUSED)
-    g_snprintf (status, sizeof (status), "Paused");
-  else
-    memset (status, ' ', sizeof (status) - 1);
+  if (play->desired_state == GST_STATE_PAUSED) {
+    status = (gchar *) paused;
+  } else {
+    gint len = g_utf8_strlen (paused, -1);
+    status = g_newa (gchar, len + 1);
+    memset (status, ' ', len);
+    status[len] = '\0';
+  }
 
   if (pos >= 0 && dur > 0) {
     gchar dstr[32], pstr[32];