Commit d6663a0512
Verified · cmc
Layout: unified · split
cmd/gitbay/ssh.go +7 −3
| @@ -119,8 +119,9 @@ var noColor bool | ||
| 119 | 119 | // output stays the rows stock ssh prints, and when GITBAY_TERM is "off", |
| 120 | 120 | // for an instance older than --term. GITBAY_TERM=basic sends the width |
| 121 | 121 | // and colour only, for an instance older than truecolor and links, which |
| 122 | // turns any other option into plain output. | |
| 123 | func termValue(isTerminal bool, cols int, env func(string) string) string { | |
| 122 | // turns any other option into plain output. here is the repository | |
| 123 | // inferred from the clone, for suggested commands to leave out. | |
| 124 | func termValue(isTerminal bool, cols int, here string, env func(string) string) string { | |
| 124 | 125 | if !isTerminal || cols < 40 || env("GITBAY_TERM") == "off" { |
| 125 | 126 | return "" |
| 126 | 127 | } |
| @@ -138,6 +139,9 @@ func termValue(isTerminal bool, cols int, env func(string) string) string { | ||
| 138 | 139 | if linksWanted(env) { |
| 139 | 140 | v += ",links" |
| 140 | 141 | } |
| 142 | if here != "" { | |
| 143 | v += ",here=" + here | |
| 144 | } | |
| 141 | 145 | return v |
| 142 | 146 | } |
| 143 | 147 | |
| @@ -235,7 +239,7 @@ func runSSHPaged(t target, serverArgv []string, stdin io.Reader, page bool) int | ||
| 235 | 239 | if isTTY { |
| 236 | 240 | cols, _, _ = term.GetSize(fd) |
| 237 | 241 | } |
| 238 | if v := termValue(isTTY, cols, os.Getenv); v != "" && !slices.Contains(serverArgv, "--json") { | |
| 242 | if v := termValue(isTTY, cols, t.repo, os.Getenv); v != "" && !slices.Contains(serverArgv, "--json") { | |
| 239 | 243 | serverArgv = append([]string{"--term=" + v}, serverArgv...) |
| 240 | 244 | } |
| 241 | 245 | |
cmd/gitbay/term_test.go +14 −1
| @@ -37,13 +37,26 @@ func TestTermValue(t *testing.T) { | ||
| 37 | 37 | } |
| 38 | 38 | for _, c := range cases { |
| 39 | 39 | noColor = c.noColor |
| 40 | if got := termValue(c.tty, c.cols, env(c.env)); got != c.want { | |
| 40 | if got := termValue(c.tty, c.cols, "", env(c.env)); got != c.want { | |
| 41 | 41 | t.Errorf("%+v: got %q", c, got) |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | noColor = false |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | func TestTermValueHere(t *testing.T) { | |
| 48 | env := func(string) string { return "" } | |
| 49 | if got, want := termValue(true, 100, "krz/gitbay", env), "100,color,here=krz/gitbay"; got != want { | |
| 50 | t.Errorf("got %q, want %q", got, want) | |
| 51 | } | |
| 52 | if got := termValue(true, 100, "", env); strings.Contains(got, "here=") { | |
| 53 | t.Errorf("here= without a repository: %q", got) | |
| 54 | } | |
| 55 | if got := termValue(false, 100, "krz/gitbay", env); got != "" { | |
| 56 | t.Errorf("piped: %q", got) | |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 47 | 60 | func TestStripNoColor(t *testing.T) { |
| 48 | 61 | args, ok := stripNoColor([]string{"gitbay", "issue", "list", "--no-color", "--state", "all"}) |
| 49 | 62 | if !ok || len(args) != 5 || args[3] != "--state" { |