Select shows a selection dialog with the given options. Returns the selected string, or empty string and false if the user declines/cancels.
(ctx context.Context, message string, options []string)
| 1219 | // Select shows a selection dialog with the given options. |
| 1220 | // Returns the selected string, or empty string and false if the user declines/cancels. |
| 1221 | func (ui *SessionUI) Select(ctx context.Context, message string, options []string) (string, bool, error) { |
| 1222 | if err := ui.session.assertElicitation(); err != nil { |
| 1223 | return "", false, err |
| 1224 | } |
| 1225 | rpcResult, err := ui.session.RPC.UI.Elicitation(ctx, &rpc.UIElicitationRequest{ |
| 1226 | Message: message, |
| 1227 | RequestedSchema: rpc.UIElicitationSchema{ |
| 1228 | Type: rpc.UIElicitationSchemaTypeObject, |
| 1229 | Properties: map[string]rpc.UIElicitationSchemaProperty{ |
| 1230 | "selection": &rpc.UIElicitationStringEnumField{ |
| 1231 | Enum: options, |
| 1232 | }, |
| 1233 | }, |
| 1234 | Required: []string{"selection"}, |
| 1235 | }, |
| 1236 | }) |
| 1237 | if err != nil { |
| 1238 | return "", false, err |
| 1239 | } |
| 1240 | if rpcResult.Action == rpc.UIElicitationResponseActionAccept { |
| 1241 | if value, ok := rpcResult.Content["selection"].(rpc.UIElicitationStringValue); ok { |
| 1242 | return string(value), true, nil |
| 1243 | } |
| 1244 | } |
| 1245 | return "", false, nil |
| 1246 | } |
| 1247 | |
| 1248 | // Input shows a text input dialog. Returns the entered text, or empty string and |
| 1249 | // false if the user declines/cancels. |
nothing calls this directly
no test coverage detected