Skip to content

Commit

Permalink
hide underscores on VSCode integrated terminal while they're glitchy
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Nov 15, 2022
1 parent 642abae commit 0ecbea2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
32 changes: 1 addition & 31 deletions pkg/gui/gocui.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
package gui

import (
"github.com/gookit/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazydocker/pkg/utils"
)

var gocuiColorMap = map[string]gocui.Attribute{
"default": gocui.ColorDefault,
"black": gocui.ColorBlack,
"red": gocui.ColorRed,
"green": gocui.ColorGreen,
"yellow": gocui.ColorYellow,
"blue": gocui.ColorBlue,
"magenta": gocui.ColorMagenta,
"cyan": gocui.ColorCyan,
"white": gocui.ColorWhite,
"bold": gocui.AttrBold,
"reverse": gocui.AttrReverse,
"underline": gocui.AttrUnderline,
}

// GetAttribute gets the gocui color attribute from the string
func GetGocuiAttribute(key string) gocui.Attribute {
if utils.IsValidHexValue(key) {
values := color.HEX(key).Values()
return gocui.NewRGBColor(int32(values[0]), int32(values[1]), int32(values[2]))
}

value, present := gocuiColorMap[key]
if present {
return value
}
return gocui.ColorDefault
}

// GetGocuiStyle bitwise OR's a list of attributes obtained via the given keys
func GetGocuiStyle(keys []string) gocui.Attribute {
var attribute gocui.Attribute
for _, key := range keys {
attribute |= GetGocuiAttribute(key)
attribute |= utils.GetGocuiAttribute(key)
}
return attribute
}
26 changes: 25 additions & 1 deletion pkg/gui/views.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package gui

import (
"os"

"github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/samber/lo"
)

// See https://github.com/xtermjs/xterm.js/issues/4238
// VSCode is soon to fix this in an upcoming update.
// Once that's done, we can scrap the HIDE_UNDERSCORES variable
var (
underscoreEnvChecked bool
hideUnderscores bool
)

func hideUnderScores() bool {
if !underscoreEnvChecked {
hideUnderscores = os.Getenv("TERM_PROGRAM") == "vscode"
underscoreEnvChecked = true
}

return hideUnderscores
}

type Views struct {
// side panels
Project *gocui.View
Expand Down Expand Up @@ -155,7 +174,12 @@ func (gui *Gui) getInformationContent() string {
return informationStr
}

donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.Donate)
attrs := []color.Attribute{color.FgMagenta}
if !hideUnderScores() {
attrs = append(attrs, color.Underline)
}

donate := color.New(attrs...).Sprint(gui.Tr.Donate)
return donate + " " + informationStr
}

Expand Down

0 comments on commit 0ecbea2

Please sign in to comment.