mirror of
https://github.com/Jguer/yay
synced 2024-07-22 18:56:44 +00:00
fix(display): adapt padding to match pacman's.
This change fixes part of #1332 related to splitting information into multiple lines. Change is implemented based on current pacman's code.
This commit is contained in:
parent
5c05811ae5
commit
5ae510ad6f
|
@ -3,8 +3,12 @@ package text
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,6 +17,8 @@ const (
|
||||||
opSymbol = "::"
|
opSymbol = "::"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cachedColumnCount = -1
|
||||||
|
|
||||||
func OperationInfoln(a ...interface{}) {
|
func OperationInfoln(a ...interface{}) {
|
||||||
fmt.Fprint(os.Stdout, append([]interface{}{Bold(Cyan(opSymbol + " ")), boldCode}, a...)...)
|
fmt.Fprint(os.Stdout, append([]interface{}{Bold(Cyan(opSymbol + " ")), boldCode}, a...)...)
|
||||||
fmt.Fprintln(os.Stdout, ResetCode)
|
fmt.Fprintln(os.Stdout, ResetCode)
|
||||||
|
@ -59,10 +65,47 @@ func Errorln(a ...interface{}) {
|
||||||
fmt.Fprintln(os.Stderr, append([]interface{}{Bold(Red(smallArrow))}, a...)...)
|
fmt.Fprintln(os.Stderr, append([]interface{}{Bold(Red(smallArrow))}, a...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintInfoValue(str, value string) {
|
func getColumnCount() int {
|
||||||
if value == "" {
|
if cachedColumnCount > 0 {
|
||||||
value = gotext.Get("None")
|
return cachedColumnCount
|
||||||
|
}
|
||||||
|
if count, err := strconv.Atoi(os.Getenv("COLUMNS")); err == nil {
|
||||||
|
cachedColumnCount = count
|
||||||
|
return cachedColumnCount
|
||||||
|
}
|
||||||
|
if ws, err := unix.IoctlGetWinsize(syscall.Stdout, unix.TIOCGWINSZ); err == nil {
|
||||||
|
cachedColumnCount = int(ws.Col)
|
||||||
|
return cachedColumnCount
|
||||||
|
}
|
||||||
|
return 80
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrintInfoValue(key string, values ...string) {
|
||||||
|
// 16 (text) + 1 (:) + 1 ( )
|
||||||
|
const (
|
||||||
|
keyLength = 18
|
||||||
|
delimCount = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
str := fmt.Sprintf(Bold("%-16s: "), key)
|
||||||
|
if len(values) == 0 || (len(values) == 1 && values[0] == "") {
|
||||||
|
fmt.Fprintf(os.Stdout, "%s%s\n", str, gotext.Get("None"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stdout, Bold("%-16s%s")+" %s\n", str, ":", value)
|
maxCols := getColumnCount()
|
||||||
|
cols := keyLength + len(values[0])
|
||||||
|
str += values[0]
|
||||||
|
for _, value := range values[1:] {
|
||||||
|
if maxCols > keyLength && cols+len(value)+delimCount >= maxCols {
|
||||||
|
cols = keyLength
|
||||||
|
str += "\n" + strings.Repeat(" ", keyLength)
|
||||||
|
} else if cols != keyLength {
|
||||||
|
str += strings.Repeat(" ", delimCount)
|
||||||
|
cols += delimCount
|
||||||
|
}
|
||||||
|
str += value
|
||||||
|
cols += len(value)
|
||||||
|
}
|
||||||
|
fmt.Println(str)
|
||||||
}
|
}
|
||||||
|
|
19
print.go
19
print.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
rpc "github.com/mikkeloscar/aur"
|
rpc "github.com/mikkeloscar/aur"
|
||||||
|
@ -106,19 +105,19 @@ func (s repoQuery) printSearch(dbExecutor db.Executor) {
|
||||||
func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
|
func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
|
||||||
text.PrintInfoValue(gotext.Get("Repository"), "aur")
|
text.PrintInfoValue(gotext.Get("Repository"), "aur")
|
||||||
text.PrintInfoValue(gotext.Get("Name"), a.Name)
|
text.PrintInfoValue(gotext.Get("Name"), a.Name)
|
||||||
text.PrintInfoValue(gotext.Get("Keywords"), strings.Join(a.Keywords, " "))
|
text.PrintInfoValue(gotext.Get("Keywords"), a.Keywords...)
|
||||||
text.PrintInfoValue(gotext.Get("Version"), a.Version)
|
text.PrintInfoValue(gotext.Get("Version"), a.Version)
|
||||||
text.PrintInfoValue(gotext.Get("Description"), a.Description)
|
text.PrintInfoValue(gotext.Get("Description"), a.Description)
|
||||||
text.PrintInfoValue(gotext.Get("URL"), a.URL)
|
text.PrintInfoValue(gotext.Get("URL"), a.URL)
|
||||||
text.PrintInfoValue(gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
|
text.PrintInfoValue(gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
|
||||||
text.PrintInfoValue(gotext.Get("Groups"), strings.Join(a.Groups, " "))
|
text.PrintInfoValue(gotext.Get("Groups"), a.Groups...)
|
||||||
text.PrintInfoValue(gotext.Get("Licenses"), strings.Join(a.License, " "))
|
text.PrintInfoValue(gotext.Get("Licenses"), a.License...)
|
||||||
text.PrintInfoValue(gotext.Get("Provides"), strings.Join(a.Provides, " "))
|
text.PrintInfoValue(gotext.Get("Provides"), a.Provides...)
|
||||||
text.PrintInfoValue(gotext.Get("Depends On"), strings.Join(a.Depends, " "))
|
text.PrintInfoValue(gotext.Get("Depends On"), a.Depends...)
|
||||||
text.PrintInfoValue(gotext.Get("Make Deps"), strings.Join(a.MakeDepends, " "))
|
text.PrintInfoValue(gotext.Get("Make Deps"), a.MakeDepends...)
|
||||||
text.PrintInfoValue(gotext.Get("Check Deps"), strings.Join(a.CheckDepends, " "))
|
text.PrintInfoValue(gotext.Get("Check Deps"), a.CheckDepends...)
|
||||||
text.PrintInfoValue(gotext.Get("Optional Deps"), strings.Join(a.OptDepends, " "))
|
text.PrintInfoValue(gotext.Get("Optional Deps"), a.OptDepends...)
|
||||||
text.PrintInfoValue(gotext.Get("Conflicts With"), strings.Join(a.Conflicts, " "))
|
text.PrintInfoValue(gotext.Get("Conflicts With"), a.Conflicts...)
|
||||||
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
|
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
|
||||||
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
|
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
|
||||||
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
|
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
|
||||||
|
|
Loading…
Reference in a new issue