2018-03-16 00:18:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-03-16 19:30:14 +00:00
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2018-04-16 12:26:15 +00:00
|
|
|
|
2019-04-23 15:53:20 +00:00
|
|
|
alpm "github.com/Jguer/go-alpm"
|
2020-05-04 07:24:32 +00:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
"github.com/Jguer/yay/v10/pkg/settings"
|
2020-06-13 17:29:50 +00:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2018-03-16 00:18:13 +00:00
|
|
|
)
|
|
|
|
|
2018-03-19 15:30:44 +00:00
|
|
|
func questionCallback(question alpm.QuestionAny) {
|
2018-07-31 08:42:17 +00:00
|
|
|
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
|
2018-03-16 19:30:14 +00:00
|
|
|
qi.SetInstall(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
qp, err := question.QuestionSelectProvider()
|
2018-07-31 08:42:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
if settings.HideMenus {
|
2018-09-25 13:05:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-31 08:42:17 +00:00
|
|
|
size := 0
|
|
|
|
|
2020-07-05 14:58:35 +00:00
|
|
|
_ = qp.Providers(config.Runtime.AlpmHandle).ForEach(func(pkg alpm.Package) error {
|
2018-07-31 08:42:17 +00:00
|
|
|
size++
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
str := gotext.Get("There are %d providers available for %s:", size, qp.Dep())
|
2018-07-31 08:42:17 +00:00
|
|
|
|
|
|
|
size = 1
|
|
|
|
var db string
|
|
|
|
|
2020-07-05 14:58:35 +00:00
|
|
|
_ = qp.Providers(config.Runtime.AlpmHandle).ForEach(func(pkg alpm.Package) error {
|
2019-02-04 16:56:02 +00:00
|
|
|
thisDB := pkg.DB().Name()
|
2018-07-31 08:42:17 +00:00
|
|
|
|
2019-02-04 16:56:02 +00:00
|
|
|
if db != thisDB {
|
|
|
|
db = thisDB
|
2020-05-04 07:24:32 +00:00
|
|
|
str += bold(cyan("\n:: ")) + bold(gotext.Get("Repository ")+db+"\n ")
|
2018-07-31 08:42:17 +00:00
|
|
|
}
|
|
|
|
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
|
|
|
|
size++
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
text.OperationInfoln(str)
|
2018-07-31 08:42:17 +00:00
|
|
|
|
|
|
|
for {
|
2020-05-04 07:24:32 +00:00
|
|
|
fmt.Print(gotext.Get("\nEnter a number (default=1): "))
|
2018-07-31 08:42:17 +00:00
|
|
|
|
|
|
|
if config.NoConfirm {
|
|
|
|
fmt.Println()
|
2018-03-16 19:30:14 +00:00
|
|
|
break
|
|
|
|
}
|
2018-07-31 08:42:17 +00:00
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
numberBuf, overflow, err := reader.ReadLine()
|
|
|
|
if err != nil {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(err)
|
2018-07-31 08:42:17 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if overflow {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get(" Input too long"))
|
2018-07-31 08:42:17 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(numberBuf) == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
num, err := strconv.Atoi(string(numberBuf))
|
|
|
|
if err != nil {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("invalid number: %s", string(numberBuf)))
|
2018-07-31 08:42:17 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if num < 1 || num > size {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("invalid value: %d is not between %d and %d", num, 1, size))
|
2018-07-31 08:42:17 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
qp.SetUseIndex(num - 1)
|
|
|
|
break
|
2018-03-16 00:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 12:35:19 +00:00
|
|
|
|
|
|
|
func logCallback(level alpm.LogLevel, str string) {
|
|
|
|
switch level {
|
|
|
|
case alpm.LogWarning:
|
2020-06-15 06:59:36 +00:00
|
|
|
text.Warn(str)
|
2018-07-26 12:35:19 +00:00
|
|
|
case alpm.LogError:
|
2020-06-15 06:59:36 +00:00
|
|
|
text.Error(str)
|
2018-07-26 12:35:19 +00:00
|
|
|
}
|
|
|
|
}
|