gg_interact 0.0.2
gg_interact: ^0.0.2 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.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.