Jelajahi Sumber

Tweak editor input loop

New line before output
Use less bold
Highlight editor and visual variables
Use cyan for highlighting
Use arrow prefix
Use loop instead of goto
morganamilo 7 tahun lalu
induk
melakukan
60b111545a
1 mengubah file dengan 20 tambahan dan 19 penghapusan
  1. 20 19
      config.go

+ 20 - 19
config.go

@@ -186,26 +186,27 @@ func editor() (string, []string) {
 		}
 		fallthrough
 	default:
-		fmt.Println(bold(red("Warning:")),
-			bold(magenta("$EDITOR")), "is not set")
-		fmt.Println("Please add $EDITOR or to your environment variables.")
-
-	editorLoop:
-		fmt.Print(green("Edit PKGBUILD with:"))
-		editorInput, err := getInput("")
-		if err != nil {
-			fmt.Println(err)
-			goto editorLoop
-		}
-
-		editorArgs := strings.Fields(editorInput)
-
-		editor, err := exec.LookPath(editorArgs[0])
-		if err != nil {
-			fmt.Println(err)
-			goto editorLoop
+		fmt.Println()
+		fmt.Println(bold(red(arrow) + " Warning:"), cyan("$EDITOR"), "is not set")
+		fmt.Println(bold(arrow) + " Please add " + cyan("$EDITOR") + " or " + cyan("$VISUAL") + " to your environment variables.")
+
+		for {
+			fmt.Print(green(bold(arrow)) + green(" Edit PKGBUILD with: "))
+			editorInput, err := getInput("")
+			if err != nil {
+				fmt.Println(err)
+				continue
+			}
+
+			editorArgs := strings.Fields(editorInput)
+
+			editor, err := exec.LookPath(editorArgs[0])
+			if err != nil {
+				fmt.Println(err)
+				continue
+			}
+			return editor, editorArgs[1:]
 		}
-		return editor, editorArgs[1:]
 	}
 }