1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00

Added light theme option to the settings

This commit is contained in:
mjarkk 2019-10-18 09:48:37 +02:00 committed by Jesse Duffield
parent 8fe0e00cd9
commit 02fef3136f
10 changed files with 103 additions and 25 deletions

View File

@ -8,6 +8,7 @@
scrollHeight: 2 # how many lines you scroll by
scrollPastBottom: true # enable scrolling past the bottom
theme:
lightTheme: false # For terminals with a light background
activeBorderColor:
- white
- bold

View File

@ -4,6 +4,8 @@ import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -38,7 +40,7 @@ func (b *Branch) GetColor() color.Attribute {
case "hotfix":
return color.FgRed
default:
return color.FgWhite
return theme.DefaultTextColor
}
}

View File

@ -2,6 +2,7 @@ package commands
import (
"github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -22,7 +23,7 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
green := color.New(color.FgGreen)
blue := color.New(color.FgBlue)
cyan := color.New(color.FgCyan)
white := color.New(color.FgWhite)
defaultColor := color.New(theme.DefaultTextColor)
magenta := color.New(color.FgMagenta)
// for some reason, setting the background to blue pads out the other commits
@ -43,7 +44,7 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
case "selected":
shaColor = magenta
default:
shaColor = white
shaColor = defaultColor
}
if c.Copied {
@ -55,5 +56,5 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
}
return []string{shaColor.Sprint(c.Sha), actionString + white.Sprint(c.Name)}
return []string{shaColor.Sprint(c.Sha), actionString + defaultColor.Sprint(c.Name)}
}

View File

@ -244,6 +244,7 @@ func GetDefaultConfig() []byte {
scrollPastBottom: true
mouseEvents: false # will default to true when the feature is complete
theme:
lightTheme: false
activeBorderColor:
- white
- bold

View File

@ -12,6 +12,7 @@ import (
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/theme"
)
func (gui *Gui) wrappedConfirmationFunction(function func(*gocui.Gui, *gocui.View) error) func(*gocui.Gui, *gocui.View) error {
@ -81,7 +82,7 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt
confirmationView.HasLoader = hasLoader
confirmationView.Title = title
confirmationView.Wrap = true
confirmationView.FgColor = gocui.ColorWhite
confirmationView.FgColor = theme.GocuiDefaultTextColor
}
gui.g.Update(func(g *gocui.Gui) error {
return gui.switchFocus(gui.g, currentView, confirmationView)

View File

@ -24,6 +24,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/updates"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
@ -374,6 +375,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
_, _ = g.SetViewOnBottom("limit")
g.DeleteView("limit")
textColor := theme.GocuiDefaultTextColor
v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, height-2, gocui.LEFT)
if err != nil {
if err.Error() != "unknown view" {
@ -381,7 +383,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
v.Title = gui.Tr.SLocalize("DiffTitle")
v.Wrap = true
v.FgColor = gocui.ColorWhite
v.FgColor = textColor
}
if v, err := g.SetView("status", 0, 0, leftSideWidth, vHeights["status"]-1, gocui.BOTTOM|gocui.RIGHT); err != nil {
@ -389,7 +391,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
v.Title = gui.Tr.SLocalize("StatusTitle")
v.FgColor = gocui.ColorWhite
v.FgColor = textColor
}
filesView, err := g.SetViewBeneath("files", "status", vHeights["files"])
@ -399,7 +401,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
filesView.Highlight = true
filesView.Title = gui.Tr.SLocalize("FilesTitle")
v.FgColor = gocui.ColorWhite
v.FgColor = textColor
}
branchesView, err := g.SetViewBeneath("branches", "files", vHeights["branches"])
@ -408,7 +410,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
branchesView.FgColor = gocui.ColorWhite
branchesView.FgColor = textColor
}
if v, err := g.SetViewBeneath("commitFiles", "branches", vHeights["commits"]); err != nil {
@ -416,7 +418,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
v.Title = gui.Tr.SLocalize("CommitFiles")
v.FgColor = gocui.ColorWhite
v.FgColor = textColor
}
commitsView, err := g.SetViewBeneath("commits", "branches", vHeights["commits"])
@ -425,7 +427,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
commitsView.FgColor = gocui.ColorWhite
commitsView.FgColor = textColor
}
stashView, err := g.SetViewBeneath("stash", "commits", vHeights["stash"])
@ -434,7 +436,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
stashView.Title = gui.Tr.SLocalize("StashTitle")
stashView.FgColor = gocui.ColorWhite
stashView.FgColor = textColor
}
if v, err := g.SetView("options", appStatusOptionsBoundary-1, height-2, optionsVersionBoundary-1, height, 0); err != nil {
@ -442,9 +444,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
v.Frame = false
if v.FgColor, err = gui.GetOptionsPanelTextColor(); err != nil {
return err
}
v.FgColor = gui.GetOptionsPanelTextColor()
}
if gui.getCommitMessageView() == nil {
@ -455,7 +455,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
g.SetViewOnBottom("commitMessage")
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
commitMessageView.FgColor = gocui.ColorWhite
commitMessageView.FgColor = textColor
commitMessageView.Editable = true
}
}
@ -471,7 +471,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
credentialsView.Title = gui.Tr.SLocalize("CredentialsUsername")
credentialsView.FgColor = gocui.ColorWhite
credentialsView.FgColor = textColor
credentialsView.Editable = true
}
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -62,7 +63,7 @@ func (gui *Gui) createMenu(title string, items interface{}, itemCount int, handl
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, false, list)
menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0)
menuView.Title = title
menuView.FgColor = gocui.ColorWhite
menuView.FgColor = theme.GocuiDefaultTextColor
menuView.Clear()
fmt.Fprint(menuView, list)
gui.State.Panels.Menu.SelectedLine = 0

View File

@ -14,6 +14,7 @@ import (
"github.com/golang-collections/collections/stack"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -50,7 +51,7 @@ func (gui *Gui) coloredConflictFile(content string, conflicts []commands.Conflic
conflict, remainingConflicts := gui.shiftConflict(conflicts)
var outputBuffer bytes.Buffer
for i, line := range utils.SplitLines(content) {
colourAttr := color.FgWhite
colourAttr := theme.DefaultTextColor
if i == conflict.Start || i == conflict.Middle || i == conflict.End {
colourAttr = color.FgRed
}

View File

@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/theme"
)
// GetAttribute gets the gocui color attribute from the string
@ -37,18 +38,19 @@ func (gui *Gui) GetColor(keys []string) gocui.Attribute {
}
// GetOptionsPanelTextColor gets the color of the options panel text
func (gui *Gui) GetOptionsPanelTextColor() (gocui.Attribute, error) {
func (gui *Gui) GetOptionsPanelTextColor() gocui.Attribute {
userConfig := gui.Config.GetUserConfig()
optionsColor := userConfig.GetStringSlice("gui.theme.optionsTextColor")
return gui.GetColor(optionsColor), nil
return gui.GetColor(optionsColor)
}
// SetColorScheme sets the color scheme for the app based on the user config
func (gui *Gui) SetColorScheme() error {
userConfig := gui.Config.GetUserConfig()
activeBorderColor := userConfig.GetStringSlice("gui.theme.activeBorderColor")
inactiveBorderColor := userConfig.GetStringSlice("gui.theme.inactiveBorderColor")
gui.g.FgColor = gui.GetColor(inactiveBorderColor)
gui.g.SelFgColor = gui.GetColor(activeBorderColor)
theme.UpdateTheme(userConfig)
gui.g.FgColor = theme.InactiveBorderColor
gui.g.SelFgColor = theme.ActiveBorderColor
return nil
}

68
pkg/theme/theme.go Normal file
View File

@ -0,0 +1,68 @@
package theme
import (
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/spf13/viper"
)
var (
// DefaultTextColor is the default text color
DefaultTextColor = color.FgWhite
// GocuiDefaultTextColor does the same as DefaultTextColor but this one only colors gocui default text colors
GocuiDefaultTextColor gocui.Attribute
// ActiveBorderColor is the border color of the active frame
ActiveBorderColor gocui.Attribute
// InactiveBorderColor is the border color of the inactive active frames
InactiveBorderColor gocui.Attribute
)
// UpdateTheme updates all theme variables
func UpdateTheme(userConfig *viper.Viper) {
ActiveBorderColor = getColor(userConfig.GetStringSlice("gui.theme.activeBorderColor"))
InactiveBorderColor = getColor(userConfig.GetStringSlice("gui.theme.inactiveBorderColor"))
isLightTheme := userConfig.GetBool("gui.theme.lightTheme")
if isLightTheme {
DefaultTextColor = color.FgBlack
GocuiDefaultTextColor = gocui.ColorBlack
} else {
DefaultTextColor = color.FgWhite
GocuiDefaultTextColor = gocui.ColorWhite
}
}
// getAttribute gets the gocui color attribute from the string
func getAttribute(key string) gocui.Attribute {
colorMap := 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,
}
value, present := colorMap[key]
if present {
return value
}
return gocui.ColorWhite
}
// getColor bitwise OR's a list of attributes obtained via the given keys
func getColor(keys []string) gocui.Attribute {
var attribute gocui.Attribute
for _, key := range keys {
attribute |= getAttribute(key)
}
return attribute
}