fix(menu): accept localized selection shortcuts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
github-actions[bot]andCopilot authored and GitHub committed 2026-08-07 04:06:27 +00:00
1 parent 2d52ad4784
commit ab3a76b7b9
2 files changed
+83 -6

No files matched your search

+72 -6
View File
@@ -47,7 +47,10 @@ func selectionMenu(logger *text.Logger, pkgbuildDirs map[string]string, bases []
pkgbuildNumberMenu(logger, pkgbuildDirs, bases, installed)
logger.Infoln(message)
logger.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
menuPrompt := gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)",
text.Cyan(gotext.Get("[N]one")))
logger.Infoln(menuPrompt)
aliases := localizedMenuAliases(menuPrompt)
selectInput, err := logger.GetInput(defaultAnswer, noConfirm)
if err != nil {
@@ -57,11 +60,13 @@ func selectionMenu(logger *text.Logger, pkgbuildDirs map[string]string, bases []
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(selectInput)
eIsInclude := len(eExclude) == 0 && eOtherExclude.Cardinality() == 0
if eOtherInclude.Contains("abort") || eOtherInclude.Contains("ab") {
if menuAliasSelected(eOtherInclude, aliases, "abort") ||
menuAliasSelected(eOtherInclude, aliases, "ab") {
return nil, settings.ErrUserAbort{}
}
if eOtherInclude.Contains("n") || eOtherInclude.Contains("none") {
if menuAliasSelected(eOtherInclude, aliases, "n") ||
menuAliasSelected(eOtherInclude, aliases, "none") {
return selected, nil
}
@@ -76,17 +81,20 @@ func selectionMenu(logger *text.Logger, pkgbuildDirs map[string]string, bases []
continue
}
if anyInstalled && (eOtherInclude.Contains("i") || eOtherInclude.Contains("installed")) {
if anyInstalled && (menuAliasSelected(eOtherInclude, aliases, "i") ||
menuAliasSelected(eOtherInclude, aliases, "installed")) {
selected = append(selected, pkgBase)
continue
}
if !anyInstalled && (eOtherInclude.Contains("no") || eOtherInclude.Contains("notinstalled")) {
if !anyInstalled && (menuAliasSelected(eOtherInclude, aliases, "no") ||
menuAliasSelected(eOtherInclude, aliases, "notinstalled")) {
selected = append(selected, pkgBase)
continue
}
if eOtherInclude.Contains("a") || eOtherInclude.Contains("all") {
if menuAliasSelected(eOtherInclude, aliases, "a") ||
menuAliasSelected(eOtherInclude, aliases, "all") {
selected = append(selected, pkgBase)
continue
}
@@ -102,3 +110,61 @@ func selectionMenu(logger *text.Logger, pkgbuildDirs map[string]string, bases []
return selected, nil
}
func localizedMenuAliases(prompt string) map[string][]string {
aliases := map[string][]string{
"all": {"a"},
"abort": {"ab"},
"installed": {"i"},
"notinstalled": {"no"},
"none": {"n"},
}
canonical := []string{"none", "all", "abort", "installed", "notinstalled"}
for _, alias := range bracketedWords(prompt) {
if len(canonical) == 0 {
break
}
key := canonical[0]
canonical = canonical[1:]
aliases[key] = append(aliases[key], strings.ToLower(alias))
}
return aliases
}
func bracketedWords(s string) []string {
var words []string
for {
start := strings.IndexByte(s, '[')
if start < 0 {
return words
}
s = s[start+1:]
end := strings.IndexByte(s, ']')
if end < 0 {
return words
}
if word := s[:end]; word != "" {
words = append(words, word)
}
s = s[end+1:]
}
}
func menuAliasSelected(input mapset.Set[string], aliases map[string][]string, canonical string) bool {
if input.Contains(canonical) {
return true
}
for _, alias := range aliases[canonical] {
if input.Contains(alias) {
return true
}
}
return false
}
+11
View File
@@ -50,6 +50,17 @@ func TestSelectionMenu(t *testing.T) {
}
}
func TestLocalizedMenuAliases(t *testing.T) {
t.Parallel()
aliases := localizedMenuAliases("[Н]ет [В]се [От]менить [У]становленные [Не]установленные")
input := mapset.NewThreadUnsafeSet[string]()
input.Add("в")
require.True(t, menuAliasSelected(input, aliases, "all"))
require.False(t, menuAliasSelected(input, aliases, "none"))
}
func TestPkgbuildNumberMenu(t *testing.T) {
t.Parallel()