int ask_string_full(
char **ret,
+ const char *prefill,
GetCompletionsCallback get_completions,
void *userdata,
const char *text, ...) {
_cleanup_free_ char *string = NULL;
size_t n = 0;
- if (get_completions) {
- /* Figure out what string to preselect the query with */
+ if (prefill) {
+ /* Prefill query with explicit data if specified */
+
+ string = strdup(prefill);
+ if (!string)
+ return -ENOMEM;
+
+ n = strlen(string);
+
+ } else if (get_completions) {
+ /* Otherwise, figure out what string to preselect the query with */
_cleanup_strv_free_ char **completions = NULL;
r = get_completions("", GET_COMPLETIONS_PRESELECT, &completions, userdata);
if (r < 0)
} GetCompletionsFlags;
typedef int (*GetCompletionsCallback)(const char *key, GetCompletionsFlags flags, char ***ret_list, void *userdata);
-int ask_string_full(char **ret, GetCompletionsCallback get_completions, void *userdata, const char *text, ...) _printf_(4, 5);
-#define ask_string(ret, text, ...) ask_string_full(ret, NULL, NULL, text, ##__VA_ARGS__)
+int ask_string_full(char **ret, const char *prefill, GetCompletionsCallback get_completions, void *userdata, const char *text, ...) _printf_(5, 6);
+#define ask_string(ret, text, ...) ask_string_full(ret, NULL, NULL, NULL, text, ##__VA_ARGS__)
bool any_key_to_proceed(void);
int show_menu(char **x, size_t n_columns, size_t column_width, unsigned ellipsize_percentage, const char *grey_prefix, bool with_numbers);
r = prompt_loop("Please enter the new system locale name or number",
GLYPH_WORLD,
+ /* prefill= */ NULL,
locales,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 60,
r = prompt_loop("Please enter the new system message locale name or number",
GLYPH_WORLD,
+ /* prefill= */ NULL,
locales,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 60,
return prompt_loop(
"Please enter the new keymap name or number",
GLYPH_KEYBOARD,
+ /* prefill= */ NULL,
kmaps,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 60,
return prompt_loop(
"Please enter the new timezone name or number",
GLYPH_CLOCK,
+ /* prefill= */ NULL,
zones,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 30,
r = prompt_loop("Please enter the new hostname",
GLYPH_LABEL,
+ /* prefill= */ NULL,
/* menu= */ NULL,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 100,
return prompt_loop(
"Please enter the new root shell",
GLYPH_SHELL,
+ /* prefill= */ NULL,
/* menu= */ NULL,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 0,
_cleanup_free_ char *s = NULL;
r = ask_string_full(
&s,
+ /* prefill= */ NULL,
group_completion_callback,
&available,
"%s Please enter an auxiliary group for user %s (empty to continue, \"list\" to list available groups): ",
return prompt_loop(
q,
GLYPH_SHELL,
+ /* prefill= */ NULL,
/* menu= */ NULL,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 0,
r = prompt_loop("Please enter user name to create",
GLYPH_IDCARD,
+ /* prefill= */ NULL,
/* menu= */ NULL,
/* accepted= */ NULL,
/* ellipsize_percentage= */ 60,
int prompt_loop(
const char *text,
Glyph emoji,
+ const char *prefill, /* if non-NULL: prefill prompt with this string */
char **menu, /* if non-NULL: choices to suggest */
char **accepted, /* if non-NULL: choices to accept (should be a superset of 'menu') */
unsigned ellipsize_percentage,
_cleanup_free_ char *p = NULL;
r = ask_string_full(
&p,
+ prefill,
get_completions,
&(CompletionData) { menu, accepted },
"%s%s%s%s: ",
int prompt_loop(const char *text,
Glyph emoji,
+ const char *prefill,
char **menu,
char **accepted,
unsigned ellipsize_percentage,
r = prompt_loop("Please enter target disk device",
GLYPH_COMPUTER_DISK,
+ /* prefill= */ NULL,
menu,
accepted,
/* ellipsize_percentage= */ 20,
"Please type 'keep' to install the OS in addition to what the disk already contains, or 'erase' to erase all data on the disk" :
"Please type 'erase' to confirm that all data on the disk shall be erased",
GLYPH_BROOM,
+ /* prefill= */ NULL,
/* menu= */ l,
/* accepted= */ l,
/* ellipsize_percentage= */ 20,
_cleanup_free_ char *reply = NULL;
r = prompt_loop("Type 'yes' to register OS installation in firmware variables of the local system, 'no' otherwise",
GLYPH_ROCKET,
+ /* prefill= */ NULL,
/* menu= */ l,
/* accepted= */ l,
/* ellipsize_percentage= */ 20,
r = prompt_loop(arg_summary ? "Please type 'yes' to confirm the choices above and begin the installation" :
"Please type 'yes' to begin the installation",
GLYPH_WARNING_SIGN,
+ /* prefill= */ NULL,
/* menu= */ l,
/* accepted= */ l,
/* ellipsize_percentage= */ 20,