askSessionChoice displays an interactive prompt with the given options and returns the user's choice. options is a list of i18n keys to display; validChoices maps single-char inputs to return values.
(optionKeys []string, validChoices map[string]string, defaultChoice string)
| 56 | // askSessionChoice displays an interactive prompt with the given options and returns the user's choice. |
| 57 | // options is a list of i18n keys to display; validChoices maps single-char inputs to return values. |
| 58 | func askSessionChoice(optionKeys []string, validChoices map[string]string, defaultChoice string) string { |
| 59 | for _, key := range optionKeys { |
| 60 | fmt.Println(i18n.T(key)) |
| 61 | } |
| 62 | fmt.Print(i18n.T("session.prompt_choice")) |
| 63 | |
| 64 | reader := bufio.NewReader(os.Stdin) |
| 65 | input, _ := reader.ReadString('\n') |
| 66 | input = strings.TrimSpace(strings.ToLower(input)) |
| 67 | |
| 68 | if val, ok := validChoices[input]; ok { |
| 69 | return val |
| 70 | } |
| 71 | return defaultChoice |
| 72 | } |
| 73 | |
| 74 | // remoteSessionCtx derives a 10-second-timeout context from the caller's |
| 75 | // context for remote session operations. |
no test coverage detected