prompt.v

1011 B · raw

1//! The strict confirm prompt, carried over from Koh 2 unchanged.2//!3//! Before anything that rewrites the working tree, Koh shows what will happen4//! and asks one question. Only a lowercase `y` confirms: `Y`, `yes`, or a5//! padded ` y ` all cancel. `--yes` skips the question; without a terminal and6//! without `--yes` the command refuses rather than hanging.78module cli910import os1112pub fn interactive() bool {13	return os.is_atty(0) != 014}1516pub fn confirm(yes bool) !bool {17	if yes {18		return true19	}20	if !interactive() {21		return error('needs --yes when not interactive')22	}23	print('  continue? [y/N] ')24	answer := os.get_line()25	println('')26	return answer.trim_right('\r') == 'y'27}2829// require_true is confirm for a second, stricter question: the answer has to30// match `expected` exactly. `strip` uses it for the typed path.31pub fn typed_confirm(prompt_text string, expected string) bool {32	print('  ${prompt_text} ')33	answer := os.get_line()34	println('')35	return answer.trim_right('\r') == expected36}