14a804ad43acc7f18efba1483767ec28039004fa

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(ssh): honor SOFT_SERVE_NO_COLOR env var in blob command

Diff

 1diff --git a/pkg/ssh/cmd/blob.go b/pkg/ssh/cmd/blob.go
 2index 45e0affb2ad7c0cc9b9a82efecf0fc8e177e63d7..1aa8fbbe16ffc50c116c4e267f986d20663dcc8f 100644
 3--- a/pkg/ssh/cmd/blob.go
 4+++ b/pkg/ssh/cmd/blob.go
 5@@ -2,6 +2,7 @@ package cmd
 6 
 7 import (
 8 	"fmt"
 9+	"os"
10 
11 	"github.com/charmbracelet/soft-serve/git"
12 	"github.com/charmbracelet/soft-serve/pkg/backend"
13@@ -15,6 +16,10 @@ func blobCommand() *cobra.Command {
14 	var linenumber bool
15 	var color bool
16 	var raw bool
17+	var noColor bool
18+	if testrun, ok := os.LookupEnv("SOFT_SERVE_NO_COLOR"); ok && testrun == "1" {
19+		noColor = true
20+	}
21 
22 	styles := styles.DefaultStyles()
23 	cmd := &cobra.Command{
24@@ -83,7 +88,7 @@ func blobCommand() *cobra.Command {
25 					return fmt.Errorf("binary file: use --raw to print")
26 				}
27 			} else {
28-				if color {
29+				if color && !noColor {
30 					c, err = common.FormatHighlight(fp, c)
31 					if err != nil {
32 						return err
33@@ -91,7 +96,7 @@ func blobCommand() *cobra.Command {
34 				}
35 
36 				if linenumber {
37-					c, _ = common.FormatLineNumber(styles, c, color)
38+					c, _ = common.FormatLineNumber(styles, c, color && !noColor)
39 				}
40 
41 				cmd.Println(c)
42diff --git a/pkg/ssh/session.go b/pkg/ssh/session.go
43index 067acb4286c9eb1526d6245192abe4b1f9c981ed..892da8bba0de8330c6761e0e30a76adbd80afe12 100644
44--- a/pkg/ssh/session.go
45+++ b/pkg/ssh/session.go
46@@ -1,11 +1,9 @@
47 package ssh
48 
49 import (
50-	"os"
51 	"time"
52 
53 	tea "github.com/charmbracelet/bubbletea/v2"
54-	"github.com/charmbracelet/colorprofile"
55 	"github.com/charmbracelet/soft-serve/pkg/access"
56 	"github.com/charmbracelet/soft-serve/pkg/backend"
57 	"github.com/charmbracelet/soft-serve/pkg/config"
58@@ -60,13 +58,9 @@ func SessionHandler(s ssh.Session) *tea.Program {
59 		tea.WithoutCatchPanics(),
60 		tea.WithMouseCellMotion(),
61 		tea.WithContext(ctx),
62+		tea.WithColorProfile(common.DefaultColorProfile),
63 	)
64 
65-	if testrun, ok := os.LookupEnv("SOFT_SERVE_NO_COLOR"); ok && testrun == "1" {
66-		// Disable colors when running tests.
67-		opts = append(opts, tea.WithColorProfile(colorprofile.NoTTY))
68-	}
69-
70 	c := common.NewCommon(ctx, pty.Window.Width, pty.Window.Height)
71 	c.SetValue(common.ConfigKey, cfg)
72 	m := NewUI(c, initialRepo)