diff --git a/pkg/text/text.go b/pkg/text/text.go index b6e7691f..d2f93566 100644 --- a/pkg/text/text.go +++ b/pkg/text/text.go @@ -66,6 +66,10 @@ func CreateOSC8Link(url, text string) string { } func CreateRepoLink(repo, arch, pkgName, text string) string { + if !UseColor { + return text + } + urlBase, ok := RepoUrls[repo] if !ok { return text diff --git a/pkg/text/text_test.go b/pkg/text/text_test.go index aa3b3e83..98af7a4f 100644 --- a/pkg/text/text_test.go +++ b/pkg/text/text_test.go @@ -177,3 +177,63 @@ msgstr "ja" } gotext.SetLanguage("") } + +func TestCreateRepoLink(t *testing.T) { + tests := []struct { + name string + useColor bool + repo string + arch string + pkgName string + text string + want string + }{ + { + name: "color disabled returns text", + useColor: false, + repo: "core", + arch: "x86_64", + pkgName: "linux", + text: "core/linux", + want: "core/linux", + }, + { + name: "unknown repo returns text", + useColor: true, + repo: "unknown", + arch: "x86_64", + pkgName: "linux", + text: "core/linux", + want: "core/linux", + }, + { + name: "aur repo uses package url", + useColor: true, + repo: "aur", + arch: "any", + pkgName: "yay", + text: "aur/yay", + want: "\033]8;;https://aur.archlinux.org/packages/yay\033\\aur/yay\033]8;;\033\\", + }, + { + name: "core repo uses arch in url", + useColor: true, + repo: "core", + arch: "x86_64", + pkgName: "linux", + text: "core/linux", + want: "\033]8;;https://archlinux.org/packages/core/x86_64/linux\033\\core/linux\033]8;;\033\\", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + original := UseColor + UseColor = tt.useColor + t.Cleanup(func() { UseColor = original }) + + got := CreateRepoLink(tt.repo, tt.arch, tt.pkgName, tt.text) + assert.Equal(t, tt.want, got) + }) + } +}