char/dns-ez
cloudflare dns management via plaintext zonefiles
git clone https://git.t4t.associates/char/dns-ez
736d1a4
main
1use std:: io::{ self , IsTerminal , Write }; 2 3use crate :: reconcile:: Action ; 4 5/// Ask a yes/no question on stdin; anything but "y"/"yes" is a no. 6pub fn prompt ( prompt : & str ) ->bool { 7print! ( "{prompt}" ); 8let _ = io:: stdout (). flush (); 9let mut input =String :: new (); 10let _ = io:: stdin (). read_line ( & mut input); 11matches! ( input. trim (). to_ascii_lowercase (). as_str (), "y" |"yes" ) 12} 13 14/// Print an action line, color-coded if stdout is a terminal. 15pub fn print_action ( action : & Action , prune : bool ) { 16let ( code, text) =match action{ 17Action :: Create ( _) =>( 32 , action. describe ()), 18Action :: Update { ..} =>( 33 , action. describe ()), 19Action :: Delete ( _) if !prune =>( 31 , format! ( "{} (skipped: --no-prune)" , action. describe ())), 20Action :: Delete ( _) =>( 31 , action. describe ()), 21}; 22println! ( "{}" , paint ( code, & text)); 23} 24 25fn paint ( code : u8 , text : & str ) ->String { 26if io:: stdout (). is_terminal () { 27format! ( "\x1b[{code}m{text}\x1b[0m" ) 28} else { 29 text. to_string () 30} 31}