1
0
mirror of https://github.com/byReqz/go-etcher.git synced 2024-12-25 12:41:49 +00:00

add confirmation dialog and made progressbar prettier

This commit is contained in:
Nils 2022-01-13 00:09:48 +01:00
parent 8390130252
commit 8454440711
Signed by: byreqz
GPG Key ID: 396A62D7D436749E

33
main.go
View File

@ -60,10 +60,19 @@ func GetDest() string {
}
func WriteImage(image *os.File, target *os.File, size int64) (int64, error) {
bar := progressbar.DefaultBytes(
size,
"Writing image",
)
bar := progressbar.NewOptions(int(size),
progressbar.OptionSetWriter(os.Stderr),
// progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(50),
progressbar.OptionSetDescription("Writing image file..."),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "=",
SaucerHead: ">",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
writer := io.MultiWriter(target, bar)
written, err := io.Copy(writer, image)
if err != nil {
@ -147,14 +156,22 @@ func main() {
fmt.Println("\r[", color.GreenString("✓"), "] Opening files ")
}
fmt.Println("[", color.BlueString("i"), "] Input device/file:", input)
fmt.Println("[", color.BlueString("i"), "] Output device/file:", device)
fmt.Print(color.HiWhiteString("Do you want to continue? [y/N]: "))
var yesno string
_, _ = fmt.Scanln(&yesno)
yesno = strings.TrimSpace(yesno)
if ! (yesno == "y" || yesno == "Y") {
log.Fatal("aborted")
}
written, err := WriteImage(image, target, stat.Size())
if err != nil {
s.Stop()
fmt.Println("\r[", color.RedString("✘"), "] Writing image,", written, "bytes written")
fmt.Println("\r[", color.RedString("✘"), "] Writing image,", written, "bytes written ")
log.Fatal(err)
} else {
s.Stop()
fmt.Println("\r[", color.GreenString("✓"), "] Writing image,", written, "bytes written")
fmt.Println("\r[", color.GreenString("✓"), "] Writing image,", written, "bytes written ")
}
s.Prefix = "[ "