diff --git a/main.go b/main.go index 3675a47..3ea3b8c 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "github.com/beevik/etree" in "github.com/charmbracelet/freeze/input" "github.com/charmbracelet/freeze/svg" + "github.com/charmbracelet/huh" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" "github.com/charmbracelet/x/exp/term/ansi" @@ -133,6 +134,36 @@ func main() { config.Output = defaultOutputFilename } + istty := isatty.IsTerminal(os.Stdout.Fd()) + + // Check if file already exists + if _, err := os.Stat(config.Output); err == nil && istty { + var confirm bool + var newOutputFilename string + + confirmOverwriteForm := + huh.NewConfirm(). + Title(fmt.Sprintf("'%s' already exists. Would you like to overwrite this file?", config.Output)). + Value(&confirm) + + newOutputFileNameForm := huh.NewInput(). + Title("Enter new output filename to use"). + Value(&newOutputFilename) + + err = confirmOverwriteForm.Run() + if err != nil { + printErrorFatal("could not retrive overwrite confirmation", err) + } + + if !confirm { + err := newOutputFileNameForm.Run() + if err != nil { + printErrorFatal("could not retrieve new output filename to use", err) + } + config.Output = newOutputFilename + } + } + scale = 1 if autoHeight && autoWidth && strings.HasSuffix(config.Output, ".png") { scale = 4 @@ -386,8 +417,6 @@ func main() { } } - istty := isatty.IsTerminal(os.Stdout.Fd()) - switch { case strings.HasSuffix(config.Output, ".png"): // use libsvg conversion.