2017-08-02 19:24:03 +02:00
|
|
|
package main
|
2017-05-06 18:34:40 +02:00
|
|
|
|
|
|
|
import (
|
2018-04-04 22:26:07 +02:00
|
|
|
"bufio"
|
2017-05-06 18:34:40 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2018-04-09 21:50:18 +02:00
|
|
|
"strings"
|
2017-05-06 18:34:40 +02:00
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2020-07-05 02:01:08 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/settings"
|
2020-06-13 19:29:50 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2017-05-06 18:34:40 +02:00
|
|
|
)
|
|
|
|
|
2017-05-07 03:43:49 +02:00
|
|
|
// Verbosity settings for search
|
|
|
|
const (
|
2018-09-14 21:18:59 +02:00
|
|
|
numberMenu = iota
|
|
|
|
detailed
|
|
|
|
minimal
|
2018-11-29 21:42:06 +01:00
|
|
|
)
|
2017-05-07 03:43:49 +02:00
|
|
|
|
2021-03-16 19:26:23 +01:00
|
|
|
var yayVersion = "10.2.0"
|
2017-05-06 18:34:40 +02:00
|
|
|
|
2020-05-30 00:43:18 +02:00
|
|
|
var localePath = "/usr/share/locale"
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
// YayConf holds the current config values for yay.
|
2020-07-05 02:01:08 +02:00
|
|
|
var config *settings.Configuration
|
2017-05-06 18:34:40 +02:00
|
|
|
|
|
|
|
// Editor returns the preferred system editor.
|
2020-05-02 16:17:20 +02:00
|
|
|
func editor() (editor string, args []string) {
|
2017-05-06 18:34:40 +02:00
|
|
|
switch {
|
2017-08-04 11:26:53 +02:00
|
|
|
case config.Editor != "":
|
|
|
|
editor, err := exec.LookPath(config.Editor)
|
2017-05-06 18:34:40 +02:00
|
|
|
if err != nil {
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2017-05-06 18:34:40 +02:00
|
|
|
} else {
|
2018-04-09 21:50:18 +02:00
|
|
|
return editor, strings.Fields(config.EditorFlags)
|
2017-05-06 18:34:40 +02:00
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case os.Getenv("EDITOR") != "":
|
2020-04-12 15:38:44 +02:00
|
|
|
if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
|
|
|
|
editor, err := exec.LookPath(editorArgs[0])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
} else {
|
|
|
|
return editor, editorArgs[1:]
|
|
|
|
}
|
2017-05-06 18:34:40 +02:00
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case os.Getenv("VISUAL") != "":
|
2020-04-12 15:38:44 +02:00
|
|
|
if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
|
|
|
|
editor, err := exec.LookPath(editorArgs[0])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
} else {
|
|
|
|
return editor, editorArgs[1:]
|
|
|
|
}
|
2017-05-06 18:34:40 +02:00
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
default:
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr)
|
2020-08-17 00:09:43 +02:00
|
|
|
text.Errorln(gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
|
|
|
|
text.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
|
2018-04-09 22:02:44 +02:00
|
|
|
|
|
|
|
for {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Edit PKGBUILD with?"))
|
2018-04-09 22:02:44 +02:00
|
|
|
editorInput, err := getInput("")
|
|
|
|
if err != nil {
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-04-09 22:02:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
editorArgs := strings.Fields(editorInput)
|
2019-10-13 01:48:12 +02:00
|
|
|
if len(editorArgs) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2018-04-09 22:02:44 +02:00
|
|
|
|
|
|
|
editor, err := exec.LookPath(editorArgs[0])
|
|
|
|
if err != nil {
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-04-09 22:02:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return editor, editorArgs[1:]
|
2017-05-06 18:34:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 22:26:07 +02:00
|
|
|
func getInput(defaultValue string) (string, error) {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Info()
|
2020-08-19 00:17:35 +02:00
|
|
|
if defaultValue != "" || settings.NoConfirm {
|
2018-04-04 22:26:07 +02:00
|
|
|
fmt.Println(defaultValue)
|
|
|
|
return defaultValue, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
|
|
|
|
buf, overflow, err := reader.ReadLine()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if overflow {
|
2020-05-04 09:24:32 +02:00
|
|
|
return "", fmt.Errorf(gotext.Get("input too long"))
|
2018-04-04 22:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return string(buf), nil
|
|
|
|
}
|