From ec8cc5501e073df6d8c76ef5f41c3cfe4ebf5bbc Mon Sep 17 00:00:00 2001 From: Jguer Date: Sun, 16 Oct 2016 23:02:48 +0100 Subject: [PATCH] Added new prints --- actions.go | 7 ++++--- aur/aur.go | 26 +++++++++++++++----------- pacman.go | 13 +++++++------ yay.go | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/actions.go b/actions.go index 04a5c179..b416c8b4 100644 --- a/actions.go +++ b/actions.go @@ -3,13 +3,14 @@ package main import ( "bufio" "fmt" - "github.com/jguer/go-alpm" - "github.com/jguer/yay/aur" "math" "os" "os/exec" "strconv" "strings" + + "github.com/jguer/go-alpm" + "github.com/jguer/yay/aur" ) func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags []string) (err error) { @@ -31,7 +32,7 @@ func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags []string) ( args = append(args, "pacman", "-S") - fmt.Printf("\x1B[32m%s\033[0m\nNumbers:", "Type numbers to install. Separate each number with a space.") + fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers:", "Type numbers to install. Separate each number with a space.") reader := bufio.NewReader(os.Stdin) numberString, err = reader.ReadString('\n') if err != nil { diff --git a/aur/aur.go b/aur/aur.go index 2c967ffc..88a95680 100644 --- a/aur/aur.go +++ b/aur/aur.go @@ -3,15 +3,15 @@ package aur import ( "bytes" "encoding/json" - "errors" "fmt" - "github.com/jguer/go-alpm" "io" "net/http" "os" "os/exec" "sort" "strings" + + "github.com/jguer/go-alpm" ) var version = "undefined" @@ -88,16 +88,16 @@ func (r *Query) PrintSearch(start int) { for i, res := range r.Results { switch { case start != SearchMode && res.Installed == true: - fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s \033[0m(%d) \x1B[32;40mInstalled\033[0m\n%s\n", + fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m(%d) \x1b[32;40mInstalled\x1b[0m\n%s\n", start+i, "aur", res.Name, res.Version, res.NumVotes, res.Description) case start != SearchMode && res.Installed != true: - fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s \033[0m(%d)\n%s\n", + fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m(%d)\n%s\n", start+i, "aur", res.Name, res.Version, res.NumVotes, res.Description) case start == SearchMode && res.Installed == true: - fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s \x1B[32;40mInstalled\033[0m\n%s\n", + fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[32;40mInstalled\x1b[0m\n%s\n", "aur", res.Name, res.Version, res.Description) case start == SearchMode && res.Installed != true: - fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n", + fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s\x1b[0m\n%s\n", "aur", res.Name, res.Version, res.Description) } } @@ -165,7 +165,7 @@ func Install(pkg string, baseDir string, conf *alpm.PacmanConfig, flags []string } if info.Resultcount == 0 { - return errors.New("Package '" + pkg + "' does not exist") + return fmt.Errorf("Package %s does not exist", pkg) } info.Results[0].Install(baseDir, conf, flags) @@ -174,6 +174,9 @@ func Install(pkg string, baseDir string, conf *alpm.PacmanConfig, flags []string // UpdatePackages handles AUR updates func UpdatePackages(baseDir string, conf *alpm.PacmanConfig, flags []string) error { + + fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m") + h, err := conf.CreateHandle() defer h.Release() if err != nil { @@ -222,7 +225,7 @@ func UpdatePackages(baseDir string, conf *alpm.PacmanConfig, flags []string) err // Leaving this here for now, warn about downgrades later if int64(info.Results[0].LastModified) > pkg.InstallDate().Unix() { - fmt.Printf("\033[1m\x1b[32m==>\x1b[33;1m %s: \033[0m%s \x1b[33;1m-> \033[0m%s\n", + fmt.Printf("\x1b[1m\x1b[32m==>\x1b[33;1m %s: \x1b[0m%s \x1b[33;1m-> \x1b[0m%s\n", pkg.Name(), pkg.Version(), info.Results[0].Version) outdated = append(outdated, pkg.Name()) } @@ -230,12 +233,13 @@ func UpdatePackages(baseDir string, conf *alpm.PacmanConfig, flags []string) err //If there are no outdated packages, don't prompt if len(outdated) == 0 { + fmt.Println(" there is nothing to do") return nil } // Install updated packages if NoConfirm(flags) == false { - fmt.Println("\033[1m\x1b[32m==> Proceed with upgrade\033[0m\033[1m (Y/n)\033[0m") + fmt.Println("\x1b[1m\x1b[32m==> Proceed with upgrade\x1b[0m\x1b[1m (Y/n)\x1b[0m") var response string fmt.Scanln(&response) if strings.ContainsAny(response, "n & N") { @@ -284,7 +288,7 @@ func (a *Result) Install(baseDir string, conf *alpm.PacmanConfig, flags []string dir.WriteString("/") if NoConfirm(flags) == false { - fmt.Println("\033[1m\x1b[32m==> Edit PKGBUILD?\033[0m\033[1m (y/N)\033[0m") + fmt.Println("\x1b[1m\x1b[32m==> Edit PKGBUILD?\x1b[0m\x1b[1m (y/N)\x1b[0m") fmt.Scanln(&response) if strings.ContainsAny(response, "y & Y") { editcmd := exec.Command(Editor, dir.String()+"PKGBUILD") @@ -324,7 +328,7 @@ func (a *Result) Dependencies(conf *alpm.PacmanConfig) (final []string, err erro } if len(info.Results) == 0 { - return final, errors.New("Failed to get deps from RPC") + return final, fmt.Errorf("Failed to get deps from RPC") } var found bool diff --git a/pacman.go b/pacman.go index 8bc75b39..87cc2a24 100644 --- a/pacman.go +++ b/pacman.go @@ -2,11 +2,12 @@ package main import ( "fmt" - "github.com/jguer/go-alpm" - "github.com/jguer/yay/aur" "os" "os/exec" "strings" + + "github.com/jguer/go-alpm" + "github.com/jguer/yay/aur" ) // RepoSearch describes a Repository search. @@ -128,16 +129,16 @@ func SearchRepos(pkgName string, conf *alpm.PacmanConfig, mode int) (err error) switch { case mode != SearchMode && installed == true: - fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s \x1B[32;40mInstalled\033[0m\n%s\n", + fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[32;40mInstalled\x1b[0m\n%s\n", i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description()) case mode != SearchMode && installed != true: - fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n", + fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s\x1b[0m\n%s\n", i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description()) case mode == SearchMode && installed == true: - fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s \x1B[32;40mInstalled\033[0m\n%s\n", + fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[32;40mInstalled\x1b[0m\n%s\n", db.Name(), pkg.Name(), pkg.Version(), pkg.Description()) case mode == SearchMode && installed != true: - fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n", + fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s\x1b[0m\n%s\n", db.Name(), pkg.Name(), pkg.Version(), pkg.Description()) } i++ diff --git a/yay.go b/yay.go index 3c79353d..a1db6273 100644 --- a/yay.go +++ b/yay.go @@ -71,7 +71,7 @@ func main() { } case "-S": err = InstallPackage(pkgs, &conf, flag) - case "-Syu": + case "-Syu", "-Suy": err = updateAndInstall(&conf, flag) case "yogurt": for _, pkg := range pkgs {