Added new prints

This commit is contained in:
Jguer 2016-10-16 23:02:48 +01:00
parent c0a87c67a9
commit ec8cc5501e
4 changed files with 27 additions and 21 deletions

View file

@ -3,13 +3,14 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/jguer/go-alpm"
"github.com/jguer/yay/aur"
"math" "math"
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
"github.com/jguer/go-alpm"
"github.com/jguer/yay/aur"
) )
func searchAndInstall(pkgName string, conf *alpm.PacmanConfig, flags []string) (err error) { 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") 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) reader := bufio.NewReader(os.Stdin)
numberString, err = reader.ReadString('\n') numberString, err = reader.ReadString('\n')
if err != nil { if err != nil {

View file

@ -3,15 +3,15 @@ package aur
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/jguer/go-alpm"
"io" "io"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"sort" "sort"
"strings" "strings"
"github.com/jguer/go-alpm"
) )
var version = "undefined" var version = "undefined"
@ -88,16 +88,16 @@ func (r *Query) PrintSearch(start int) {
for i, res := range r.Results { for i, res := range r.Results {
switch { switch {
case start != SearchMode && res.Installed == true: 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) start+i, "aur", res.Name, res.Version, res.NumVotes, res.Description)
case start != SearchMode && res.Installed != true: 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) start+i, "aur", res.Name, res.Version, res.NumVotes, res.Description)
case start == SearchMode && res.Installed == true: 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) "aur", res.Name, res.Version, res.Description)
case start == SearchMode && res.Installed != true: 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) "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 { 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) 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 // UpdatePackages handles AUR updates
func UpdatePackages(baseDir string, conf *alpm.PacmanConfig, flags []string) error { 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() h, err := conf.CreateHandle()
defer h.Release() defer h.Release()
if err != nil { 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 // Leaving this here for now, warn about downgrades later
if int64(info.Results[0].LastModified) > pkg.InstallDate().Unix() { 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) pkg.Name(), pkg.Version(), info.Results[0].Version)
outdated = append(outdated, pkg.Name()) 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 there are no outdated packages, don't prompt
if len(outdated) == 0 { if len(outdated) == 0 {
fmt.Println(" there is nothing to do")
return nil return nil
} }
// Install updated packages // Install updated packages
if NoConfirm(flags) == false { 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 var response string
fmt.Scanln(&response) fmt.Scanln(&response)
if strings.ContainsAny(response, "n & N") { if strings.ContainsAny(response, "n & N") {
@ -284,7 +288,7 @@ func (a *Result) Install(baseDir string, conf *alpm.PacmanConfig, flags []string
dir.WriteString("/") dir.WriteString("/")
if NoConfirm(flags) == false { 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) fmt.Scanln(&response)
if strings.ContainsAny(response, "y & Y") { if strings.ContainsAny(response, "y & Y") {
editcmd := exec.Command(Editor, dir.String()+"PKGBUILD") 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 { 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 var found bool

View file

@ -2,11 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"github.com/jguer/go-alpm"
"github.com/jguer/yay/aur"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"github.com/jguer/go-alpm"
"github.com/jguer/yay/aur"
) )
// RepoSearch describes a Repository search. // RepoSearch describes a Repository search.
@ -128,16 +129,16 @@ func SearchRepos(pkgName string, conf *alpm.PacmanConfig, mode int) (err error)
switch { switch {
case mode != SearchMode && installed == true: 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()) i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode != SearchMode && installed != true: 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()) i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode == SearchMode && installed == true: 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()) db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode == SearchMode && installed != true: 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()) db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
} }
i++ i++

2
yay.go
View file

@ -71,7 +71,7 @@ func main() {
} }
case "-S": case "-S":
err = InstallPackage(pkgs, &conf, flag) err = InstallPackage(pkgs, &conf, flag)
case "-Syu": case "-Syu", "-Suy":
err = updateAndInstall(&conf, flag) err = updateAndInstall(&conf, flag)
case "yogurt": case "yogurt":
for _, pkg := range pkgs { for _, pkg := range pkgs {