From: Richard Hughes Date: Wed, 15 Feb 2023 16:37:08 +0000 (+0000) Subject: trivial: Move the uint prompt to FuConsole X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=7e0ba9ff97eb2abd9e3d8149bfed5cc47ee84fec;p=fwupd.git trivial: Move the uint prompt to FuConsole --- diff --git a/src/fu-console.c b/src/fu-console.c index f68801418..554a28760 100644 --- a/src/fu-console.c +++ b/src/fu-console.c @@ -138,11 +138,18 @@ fu_console_print_kv(FuConsole *self, const gchar *title, const gchar *msg) } guint -fu_console_input_uint(FuConsole *self, guint maxnum) +fu_console_input_uint(FuConsole *self, guint maxnum, const gchar *format, ...) { gint retval; guint answer = 0; + va_list args; + g_autofree gchar *tmp = NULL; + + va_start(args, format); + tmp = g_strdup_vprintf(format, args); + va_end(args); + fu_console_print_full(self, FU_CONSOLE_PRINT_FLAG_NONE, "%s [0-%u]: ", tmp, maxnum); do { char buffer[64]; diff --git a/src/fu-console.h b/src/fu-console.h index d31066152..c75aa489d 100644 --- a/src/fu-console.h +++ b/src/fu-console.h @@ -37,7 +37,7 @@ gboolean fu_console_setup(FuConsole *self, GError **error); guint -fu_console_input_uint(FuConsole *self, guint maxnum); +fu_console_input_uint(FuConsole *self, guint maxnum, const gchar *format, ...) G_GNUC_PRINTF(3, 4); gboolean fu_console_input_bool(FuConsole *self, gboolean def, const gchar *format, ...) G_GNUC_PRINTF(3, 4); diff --git a/src/fu-tool.c b/src/fu-tool.c index c97ba3502..2ea5cbdda 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -543,8 +543,6 @@ fu_util_prompt_for_device(FuUtilPrivate *priv, GPtrArray *devices_opt, GError ** return NULL; } - /* TRANSLATORS: get interactive prompt */ - fu_console_print_literal(priv->console, _("Choose a device:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < devices_filtered->len; i++) { @@ -555,7 +553,9 @@ fu_util_prompt_for_device(FuUtilPrivate *priv, GPtrArray *devices_opt, GError ** fu_device_get_id(dev), fu_device_get_name(dev)); } - idx = fu_console_input_uint(priv->console, devices_filtered->len); + + /* TRANSLATORS: get interactive prompt */ + idx = fu_console_input_uint(priv->console, devices_filtered->len, "%s", _("Choose device")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, @@ -2212,15 +2212,14 @@ fu_util_prompt_for_firmware_type(FuUtilPrivate *priv, GError **error) guint idx; firmware_types = fu_context_get_firmware_gtype_ids(fu_engine_get_context(priv->engine)); - /* TRANSLATORS: get interactive prompt */ - fu_console_print_literal(priv->console, _("Choose a firmware type:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < firmware_types->len; i++) { const gchar *id = g_ptr_array_index(firmware_types, i); fu_console_print(priv->console, "%u.\t%s", i + 1, id); } - idx = fu_console_input_uint(priv->console, firmware_types->len); + /* TRANSLATORS: get interactive prompt */ + idx = fu_console_input_uint(priv->console, firmware_types->len, "%s", _("Choose firmware")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, @@ -3122,15 +3121,14 @@ fu_util_prompt_for_volume(FuUtilPrivate *priv, GError **error) return g_object_ref(volume); } - /* TRANSLATORS: get interactive prompt */ - fu_console_print_literal(priv->console, _("Choose a volume:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < volumes->len; i++) { volume = g_ptr_array_index(volumes, i); fu_console_print(priv->console, "%u.\t%s", i + 1, fu_volume_get_id(volume)); } - idx = fu_console_input_uint(priv->console, volumes->len); + /* TRANSLATORS: get interactive prompt */ + idx = fu_console_input_uint(priv->console, volumes->len, "%s", _("Choose volume")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, @@ -3251,9 +3249,6 @@ fu_util_switch_branch(FuUtilPrivate *priv, gchar **values, GError **error) } else { guint idx; - /* TRANSLATORS: get interactive prompt, where branch is the - * supplier of the firmware, e.g. "non-free" or "free" */ - fu_console_print_literal(priv->console, _("Choose a branch:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < branches->len; i++) { @@ -3263,7 +3258,9 @@ fu_util_switch_branch(FuUtilPrivate *priv, gchar **values, GError **error) i + 1, fu_util_branch_for_display(branch_tmp)); } - idx = fu_console_input_uint(priv->console, branches->len); + /* TRANSLATORS: get interactive prompt, where branch is the + * supplier of the firmware, e.g. "non-free" or "free" */ + idx = fu_console_input_uint(priv->console, branches->len, "%s", _("Choose branch")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, diff --git a/src/fu-util.c b/src/fu-util.c index 9023987e8..8c814ed3a 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -231,8 +231,6 @@ fu_util_prompt_for_device(FuUtilPrivate *priv, GPtrArray *devices, GError **erro return NULL; } - /* TRANSLATORS: get interactive prompt */ - fu_console_print_literal(priv->console, _("Choose a device:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < devices_filtered->len; i++) { @@ -243,7 +241,8 @@ fu_util_prompt_for_device(FuUtilPrivate *priv, GPtrArray *devices, GError **erro fwupd_device_get_id(dev), fwupd_device_get_name(dev)); } - idx = fu_console_input_uint(priv->console, devices_filtered->len); + /* TRANSLATORS: get interactive prompt */ + idx = fu_console_input_uint(priv->console, devices_filtered->len, "%s", _("Choose device")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, @@ -1964,8 +1963,6 @@ fu_util_prompt_for_release(FuUtilPrivate *priv, GPtrArray *rels, GError **error) return g_object_ref(rel); } - /* TRANSLATORS: get interactive prompt */ - fu_console_print_literal(priv->console, _("Choose a release:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < rels->len; i++) { @@ -1975,7 +1972,8 @@ fu_util_prompt_for_release(FuUtilPrivate *priv, GPtrArray *rels, GError **error) i + 1, fwupd_release_get_version(rel_tmp)); } - idx = fu_console_input_uint(priv->console, rels->len); + /* TRANSLATORS: get interactive prompt */ + idx = fu_console_input_uint(priv->console, rels->len, "%s", _("Choose release")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR, @@ -2953,9 +2951,6 @@ fu_util_switch_branch(FuUtilPrivate *priv, gchar **values, GError **error) } else { guint idx; - /* TRANSLATORS: get interactive prompt, where branch is the - * supplier of the firmware, e.g. "non-free" or "free" */ - fu_console_print_literal(priv->console, _("Choose a branch:")); /* TRANSLATORS: this is to abort the interactive prompt */ fu_console_print(priv->console, "0.\t%s", _("Cancel")); for (guint i = 0; i < branches->len; i++) { @@ -2965,7 +2960,9 @@ fu_util_switch_branch(FuUtilPrivate *priv, gchar **values, GError **error) i + 1, fu_util_branch_for_display(branch_tmp)); } - idx = fu_console_input_uint(priv->console, branches->len); + /* TRANSLATORS: get interactive prompt, where branch is the + * supplier of the firmware, e.g. "non-free" or "free" */ + idx = fu_console_input_uint(priv->console, branches->len, "%s", _("Choose branch")); if (idx == 0) { g_set_error_literal(error, FWUPD_ERROR,