]> git.proxmox.com Git - fwupd.git/commitdiff
trivial: Move the uint prompt to FuConsole
authorRichard Hughes <richard@hughsie.com>
Wed, 15 Feb 2023 16:37:08 +0000 (16:37 +0000)
committerRichard Hughes <richard@hughsie.com>
Wed, 15 Feb 2023 17:16:28 +0000 (17:16 +0000)
src/fu-console.c
src/fu-console.h
src/fu-tool.c
src/fu-util.c

index f68801418fdc1fb920628b149585a2b526427ac9..554a28760163013485630411d68b6ea6bfe00c8b 100644 (file)
@@ -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];
 
index d3106615239ef359d9f54e3fff6c91b95c4e4082..c75aa489dbadd3a159ac2138d7aa1f6c8bdac80d 100644 (file)
@@ -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);
 
index c97ba350266298bb4fb4ce806d943deac23d1812..2ea5cbddaa07a49afe6b4e07ca8c7d730b6200a2 100644 (file)
@@ -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,
index 9023987e81bfb9a4256629d24d5334863b9e538a..8c814ed3aec30b3089f223c170ec6526eb8ebc3f 100644 (file)
@@ -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,