summary refs log tree commit diff
path: root/cli/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/utils.c')
-rw-r--r--cli/src/utils.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/cli/src/utils.c b/cli/src/utils.c
index 24bc998c..8030d5e1 100644
--- a/cli/src/utils.c
+++ b/cli/src/utils.c
@@ -69,7 +69,7 @@ ssid_to_printable (const char *str, gsize len)
 	int i;
 
 	if (str == NULL || len == 0)
-		 return NULL;
+		return NULL;
 
 	if (g_utf8_validate (str, len, NULL))
 		return g_strdup_printf ("'%.*s'", (int) len, str);
@@ -137,6 +137,38 @@ nmc_ip6_address_as_string (const struct in6_addr *ip, GError **error)
 }
 
 /*
+ * Erase terminal line using ANSI escape sequences.
+ * It prints <ESC>[2K sequence to erase the line and then \r to return back
+ * to the beginning of the line.
+ *
+ * http://www.termsys.demon.co.uk/vtansi.htm
+ */
+void
+nmc_terminal_erase_line (void)
+{
+	printf ("\33[2K\r");
+	fflush (stdout);
+}
+
+/*
+ * Print animated progress for an operation.
+ * Repeated calls of the function will show rotating slash in terminal followed
+ * by the string passed in 'str' argument.
+ */
+void
+nmc_terminal_show_progress (const char *str)
+{
+	static int idx = 0;
+	const char slashes[4] = {'|', '/', '-', '\\'};
+
+	nmc_terminal_erase_line ();
+	printf ("%c %s", slashes[idx++], str ? str : "");
+	fflush (stdout);
+	if (idx == 4)
+		idx = 0;
+}
+
+/*
  * Find out how many columns an UTF-8 string occupies on the screen
  */
 int
@@ -244,7 +276,7 @@ print_fields (const NmcPrintFields fields, const NmcOutputField field_values[])
 	int table_width = 0;
 	char *line = NULL;
 	char *indent_str;
-	const char *not_set_str = _("not set");
+	const char *not_set_str = "--";
 	int i;
 	gboolean multiline = fields.flags & NMC_PF_FLAG_MULTILINE;
 	gboolean terse = fields.flags & NMC_PF_FLAG_TERSE;
@@ -439,7 +471,7 @@ nmc_is_nm_running (NmCli *nmc, GError **error)
 			g_set_error (error, 0, 0, "%s", nmc->return_text->str);
 		goto done;
 	}
- 
+
 	if (!org_freedesktop_DBus_name_has_owner (proxy, NM_DBUS_SERVICE, &has_owner, &err)) {
 		g_string_printf (nmc->return_text, _("Error: NameHasOwner request failed: %s"),
 		                 (err && err->message) ? err->message : _("(unknown)"));