//! The strict confirm prompt, carried over from Koh 2 unchanged. //! //! Before anything that rewrites the working tree, Koh shows what will happen //! and asks one question. Only a lowercase `y` confirms: `Y`, `yes`, or a //! padded ` y ` all cancel. `--yes` skips the question; without a terminal and //! without `--yes` the command refuses rather than hanging. module cli import os pub fn interactive() bool { return os.is_atty(0) != 0 } pub fn confirm(yes bool) !bool { if yes { return true } if !interactive() { return error('needs --yes when not interactive') } done_working() print(' continue? [y/N] ') answer := os.get_line() println('') return answer.trim_right('\r') == 'y' } // require_true is confirm for a second, stricter question: the answer has to // match `expected` exactly. `strip` uses it for the typed path. pub fn typed_confirm(prompt_text string, expected string) bool { done_working() print(' ${prompt_text} ') answer := os.get_line() println('') return answer.trim_right('\r') == expected }