Skip to content

Commit deaee03

Browse files
committed
fix: Enable color when terminal is a tty
1 parent 4d3ab86 commit deaee03

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cli/configssh.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ func configSSH() *cobra.Command {
246246
}
247247
}
248248

249+
color := isTTY(cmd)
249250
for _, diffFn := range []func() ([]byte, error){
250-
func() ([]byte, error) { return diffBytes(sshConfigFile, configRaw, configModified) },
251-
func() ([]byte, error) { return diffBytes(coderConfigFile, coderConfigRaw, buf.Bytes()) },
251+
func() ([]byte, error) { return diffBytes(sshConfigFile, configRaw, configModified, color) },
252+
func() ([]byte, error) { return diffBytes(coderConfigFile, coderConfigRaw, buf.Bytes(), color) },
252253
} {
253254
diff, err := diffFn()
254255
if err != nil {
@@ -389,11 +390,11 @@ func currentBinPath(cmd *cobra.Command) (string, error) {
389390

390391
// diffBytes takes two byte slices and diffs them as if they were in a
391392
// file named name.
392-
func diffBytes(name string, b1, b2 []byte) ([]byte, error) {
393+
//nolint: revive // Color is an option, not a control coupling.
394+
func diffBytes(name string, b1, b2 []byte, color bool) ([]byte, error) {
393395
var buf bytes.Buffer
394396
var opts []write.Option
395-
// TODO(mafredri): Toggle color on/off
396-
if false {
397+
if color {
397398
opts = append(opts, write.TerminalColor())
398399
}
399400
err := diff.Text(name, name+".new", b1, b2, &buf, opts...)

0 commit comments

Comments
 (0)