瀏覽代碼

Prettify repository download messages

Michael Rees 7 年之前
父節點
當前提交
3df03c3291
共有 3 個文件被更改,包括 33 次插入34 次删除
  1. 1 1
      config.go
  2. 4 33
      install.go
  3. 28 0
      print.go

+ 1 - 1
config.go

@@ -186,7 +186,7 @@ func continueTask(s string, def string) (cont bool) {
 	}
 
 	var response string
-	fmt.Print(boldGreenFg(arrow+" "+s), boldWhiteFg(postFix))
+	fmt.Print(boldGreenFg(arrow+" "+s+" "), boldWhiteFg(postFix))
 
 	n, err := fmt.Scanln(&response)
 	if err != nil || n == 0 {

+ 4 - 33
install.go

@@ -4,9 +4,7 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
-	"strconv"
 
-	alpm "github.com/jguer/go-alpm"
 	rpc "github.com/mikkeloscar/aur"
 	gopkg "github.com/mikkeloscar/gopkgbuild"
 )
@@ -70,37 +68,10 @@ func install(parser *arguments) error {
 			}
 		}
 
-		fmt.Println()
-
-		p1 := func(a []*alpm.Package) {
-			for _, v := range a {
-				fmt.Print("  ", v.Name())
-			}
-		}
-
-		p2 := func(a []*rpc.Pkg) {
-			for _, v := range a {
-				fmt.Print("  ", v.Name)
-			}
-		}
-
-		fmt.Print("Repo (" + strconv.Itoa(len(dc.Repo)) + "):")
-		p1(dc.Repo)
-		fmt.Println()
-
-		fmt.Print("Repo Make (" + strconv.Itoa(len(dc.RepoMake)) + "):")
-		p1(dc.RepoMake)
-		fmt.Println()
-
-		fmt.Print("Aur (" + strconv.Itoa(len(dc.Aur)) + "):")
-		p2(dc.Aur)
-		fmt.Println()
-
-		fmt.Print("Aur Make (" + strconv.Itoa(len(dc.AurMake)) + "):")
-		p2(dc.AurMake)
-		fmt.Println()
-
-		fmt.Println()
+		printDownloadsFromRepo("Repo", dc.Repo)
+		printDownloadsFromRepo("Repo Make", dc.RepoMake)
+		printDownloadsFromAur("AUR", dc.Aur)
+		printDownloadsFromAur("AUR Make", dc.AurMake)
 
 		askCleanBuilds(dc.AurMake)
 		askCleanBuilds(dc.Aur)

+ 28 - 0
print.go

@@ -94,6 +94,34 @@ func (s repoQuery) printSearch() {
 	}
 }
 
+// printDownloadsFromRepo prints repository packages to be downloaded
+func printDownloadsFromRepo(repoType string, repo []*alpm.Package) {
+	var packages string
+	for _, v := range repo {
+		packages += v.Name() + " "
+	}
+	if len(repo) > 0 {
+		printDownloads(repoType, packages, len(repo))
+	}
+}
+
+// printDownloadsFromAur prints AUR packages to be downloaded
+func printDownloadsFromAur(repoType string, repo []*rpc.Pkg) {
+	var packages string
+	for _, v := range repo {
+		packages += v.Name + " "
+	}
+	if len(repo) > 0 {
+		printDownloads(repoType, packages, len(repo))
+	}
+}
+
+func printDownloads(repoType, packages string, numPackages int) {
+	fmt.Println(
+		redFg("["+repoType+", "+strconv.Itoa(numPackages)+" packages] ") +
+			yellowFg(packages))
+}
+
 func printDeps(repoDeps []string, aurDeps []string) {
 	if len(repoDeps) != 0 {
 		fmt.Print(boldGreenFg(arrow + " Repository dependencies: "))