diff options
| author | Michael Biebl <biebl@debian.org> | 2012-06-29 20:12:44 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2012-06-29 20:12:44 +0200 |
| commit | 867254ea7c2b193fecf8cd36cc6e5dc53c290d92 (patch) | |
| tree | 7c698b403882736ab70c3efd524c3460f08c391c /cli/src/utils.c | |
| parent | de06e5715e780baade318f3490ac7a4c9ce84e32 (diff) | |
Imported Upstream version 0.9.5.95 upstream/0.9.5.95
Diffstat (limited to 'cli/src/utils.c')
| -rw-r--r-- | cli/src/utils.c | 38 |
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)")); |