runRequestedPalette runs the command palette when a handler flagged it, then executes the user's selection in place. It is called from the executor, where go-prompt has already torn down raw mode, so the alt-screen overlay can own the terminal and hand it back cleanly. Returns true when the selectio
()
| 1250 | // own the terminal and hand it back cleanly. Returns true when the selection |
| 1251 | // asks to exit the REPL. A no-op outside an interactive terminal. |
| 1252 | func (cli *ChatCLI) runRequestedPalette() bool { |
| 1253 | if !cli.paletteRequested { |
| 1254 | return false |
| 1255 | } |
| 1256 | cli.paletteRequested = false |
| 1257 | target := cli.paletteTarget |
| 1258 | cli.paletteTarget = "" |
| 1259 | if !theme.ActiveProfile().IsTerminal() { |
| 1260 | return false |
| 1261 | } |
| 1262 | var m palette.Model |
| 1263 | if target == "" { |
| 1264 | m = palette.NewRoot(cli.paletteSuggest) |
| 1265 | } else { |
| 1266 | m = palette.NewScoped(cli.paletteSuggest, target) |
| 1267 | } |
| 1268 | sel, err := palette.Run(context.Background(), m) |
| 1269 | if err != nil { |
| 1270 | cli.logger.Warn("command palette failed", zap.Error(err)) |
| 1271 | return false |
| 1272 | } |
| 1273 | if sel == "" { |
| 1274 | return false // canceled |
| 1275 | } |
| 1276 | // Execute the selection as if typed. suppressPaletteOnce stops a bare, |
| 1277 | // pickable selection (e.g. "/config", "/switch") from reopening the |
| 1278 | // overlay; the trigger consumes and clears it on this very call. |
| 1279 | cli.suppressPaletteOnce = true |
| 1280 | exit := cli.commandHandler.HandleCommand(context.Background(), sel) |
| 1281 | cli.suppressPaletteOnce = false |
| 1282 | cli.paletteRequested = false // ignore any re-trigger raised during execution |
| 1283 | return exit |
| 1284 | } |
| 1285 | |
| 1286 | func (cli *ChatCLI) restoreTerminal() { |
| 1287 | if runtime.GOOS == "windows" { |