mirror of
https://github.com/Jguer/yay
synced 2024-09-01 14:18:39 +00:00
Refactor f() to a dedicated function colourHash()
Also enable colourHash() for yogurt mode.
This commit is contained in:
parent
3109ae759e
commit
181663b7cb
17
print.go
17
print.go
|
@ -41,7 +41,7 @@ func (q aurQuery) printSearch(start int) {
|
|||
fmt.Println(res.Name)
|
||||
continue
|
||||
}
|
||||
toprint += boldWhiteFg("aur/") + boldYellowFg(res.Name) +
|
||||
toprint += colourHash("aur") + "/" + boldYellowFg(res.Name) +
|
||||
" " + boldCyanFg(res.Version) +
|
||||
" (" + strconv.Itoa(res.NumVotes) + ") "
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (s repoQuery) printSearch() {
|
|||
fmt.Println(res.Name())
|
||||
continue
|
||||
}
|
||||
toprint += boldWhiteFg(res.DB().Name()+"/") + boldYellowFg(res.Name()) +
|
||||
toprint += colourHash(res.DB().Name()) + "/" + boldYellowFg(res.Name()) +
|
||||
" " + boldCyanFg(res.Version()) + " "
|
||||
|
||||
if len(res.Groups().Slice()) != 0 {
|
||||
|
@ -85,7 +85,7 @@ func (s repoQuery) printSearch() {
|
|||
localDb, err := alpmHandle.LocalDb()
|
||||
if err == nil {
|
||||
if _, err = localDb.PkgByName(res.Name()); err == nil {
|
||||
toprint += greenFgBlackBg("Installed")
|
||||
toprint += greenFgBlueBg("Installed")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,3 +417,14 @@ func boldYellowFgBlackBg(in string) string {
|
|||
|
||||
return in
|
||||
}
|
||||
|
||||
func colourHash(name string) (output string) {
|
||||
if alpmConf.Options&alpm.ConfColor == 0 {
|
||||
return name
|
||||
}
|
||||
var hash = 5381
|
||||
for i := 0; i < len(name); i++ {
|
||||
hash = int(name[i]) + ((hash << 5) + (hash))
|
||||
}
|
||||
return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name)
|
||||
}
|
||||
|
|
12
upgrade.go
12
upgrade.go
|
@ -85,18 +85,8 @@ func (u upSlice) Print(start int) {
|
|||
for k, i := range u {
|
||||
left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
|
||||
|
||||
f := func(name string) (output string) {
|
||||
if alpmConf.Options&alpm.ConfColor == 0 {
|
||||
return name
|
||||
}
|
||||
var hash = 5381
|
||||
for i := 0; i < len(name); i++ {
|
||||
hash = int(name[i]) + ((hash << 5) + (hash))
|
||||
}
|
||||
return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name)
|
||||
}
|
||||
fmt.Print(yellowFg(fmt.Sprintf("%2d ", len(u)+start-k-1)))
|
||||
fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name))
|
||||
fmt.Print(colourHash(i.Repository), "/", boldWhiteFg(i.Name))
|
||||
|
||||
w := 70 - len(i.Repository) - len(i.Name) + len(left)
|
||||
fmt.Printf(fmt.Sprintf("%%%ds", w),
|
||||
|
|
Loading…
Reference in a new issue