gg_interact 0.1.0
gg_interact: ^0.1.0 copied to clipboard
Interactive terminal prompts for the gg suite - select, input and confirm, with headless detection.
gg_interact #
Interactive terminal prompts for the gg suite: select, input and confirm, with headless detection.
import 'package:gg_interact/gg_interact.dart';
throwWhenNotATerminal('the name prompt', 'pass --name');
final prompts = GgPrompts.current;
final index = await prompts.select(prompt: 'Language', options: ['Dart', 'TS']);
final name = await prompts.inputUntilValid(
prompt: 'Name',
validate: (v) => v.isEmpty ? 'Please enter a name.' : null,
onInvalid: print,
);
final ok = await prompts.confirm(prompt: 'Create $name?');
GgPrompts.currentis what every gg prompt goes through. An embedder without a terminal — gg in Node, say — answers by assigning it; tests assign a scripted subclass and reset it withGgPrompts.current = null.selectandinputare the two prompts an embedder implements.confirmandinputUntilValidare built on them.editTextopens a whole text in the user's editor —GG_EDITOR, else VS Code (code --wait; on Linux only with a display), elseVISUALorEDITOR— and returns what was saved. VS Code, its forks and Sublime Text get their wait flag when a variable lacks it. It answers null without a terminal, without an editor, when the editor cannot be started, and by default for an embedder, so the caller falls back toinput. An editor ending with an error code cancels, like in git.throwWhenNotATerminalfails fast in CI, pipes and scripts instead of waiting forever for an answer.- A Wasm build has no
dart:ffi; its prompts throwGgPromptsUnsupportedErroruntil an embedder supplies some.
The prompts used to live in gg_one_core, which re-exports them unchanged.