mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Added light theme option to the settings
This commit is contained in:
parent
8fe0e00cd9
commit
02fef3136f
10 changed files with 103 additions and 25 deletions
|
@ -8,6 +8,7 @@
|
||||||
scrollHeight: 2 # how many lines you scroll by
|
scrollHeight: 2 # how many lines you scroll by
|
||||||
scrollPastBottom: true # enable scrolling past the bottom
|
scrollPastBottom: true # enable scrolling past the bottom
|
||||||
theme:
|
theme:
|
||||||
|
lightTheme: false # For terminals with a light background
|
||||||
activeBorderColor:
|
activeBorderColor:
|
||||||
- white
|
- white
|
||||||
- bold
|
- bold
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
@ -38,7 +40,7 @@ func (b *Branch) GetColor() color.Attribute {
|
||||||
case "hotfix":
|
case "hotfix":
|
||||||
return color.FgRed
|
return color.FgRed
|
||||||
default:
|
default:
|
||||||
return color.FgWhite
|
return theme.DefaultTextColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
|
||||||
green := color.New(color.FgGreen)
|
green := color.New(color.FgGreen)
|
||||||
blue := color.New(color.FgBlue)
|
blue := color.New(color.FgBlue)
|
||||||
cyan := color.New(color.FgCyan)
|
cyan := color.New(color.FgCyan)
|
||||||
white := color.New(color.FgWhite)
|
defaultColor := color.New(theme.DefaultTextColor)
|
||||||
magenta := color.New(color.FgMagenta)
|
magenta := color.New(color.FgMagenta)
|
||||||
|
|
||||||
// for some reason, setting the background to blue pads out the other commits
|
// 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":
|
case "selected":
|
||||||
shaColor = magenta
|
shaColor = magenta
|
||||||
default:
|
default:
|
||||||
shaColor = white
|
shaColor = defaultColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Copied {
|
if c.Copied {
|
||||||
|
@ -55,5 +56,5 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
|
||||||
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
|
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)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,6 +244,7 @@ func GetDefaultConfig() []byte {
|
||||||
scrollPastBottom: true
|
scrollPastBottom: true
|
||||||
mouseEvents: false # will default to true when the feature is complete
|
mouseEvents: false # will default to true when the feature is complete
|
||||||
theme:
|
theme:
|
||||||
|
lightTheme: false
|
||||||
activeBorderColor:
|
activeBorderColor:
|
||||||
- white
|
- white
|
||||||
- bold
|
- bold
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/gocui"
|
"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 {
|
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.HasLoader = hasLoader
|
||||||
confirmationView.Title = title
|
confirmationView.Title = title
|
||||||
confirmationView.Wrap = true
|
confirmationView.Wrap = true
|
||||||
confirmationView.FgColor = gocui.ColorWhite
|
confirmationView.FgColor = theme.GocuiDefaultTextColor
|
||||||
}
|
}
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
return gui.switchFocus(gui.g, currentView, confirmationView)
|
return gui.switchFocus(gui.g, currentView, confirmationView)
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/updates"
|
"github.com/jesseduffield/lazygit/pkg/updates"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -374,6 +375,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
_, _ = g.SetViewOnBottom("limit")
|
_, _ = g.SetViewOnBottom("limit")
|
||||||
g.DeleteView("limit")
|
g.DeleteView("limit")
|
||||||
|
|
||||||
|
textColor := theme.GocuiDefaultTextColor
|
||||||
v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, height-2, gocui.LEFT)
|
v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, height-2, gocui.LEFT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() != "unknown view" {
|
if err.Error() != "unknown view" {
|
||||||
|
@ -381,7 +383,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
v.Title = gui.Tr.SLocalize("DiffTitle")
|
v.Title = gui.Tr.SLocalize("DiffTitle")
|
||||||
v.Wrap = true
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
v.Title = gui.Tr.SLocalize("StatusTitle")
|
v.Title = gui.Tr.SLocalize("StatusTitle")
|
||||||
v.FgColor = gocui.ColorWhite
|
v.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
filesView, err := g.SetViewBeneath("files", "status", vHeights["files"])
|
filesView, err := g.SetViewBeneath("files", "status", vHeights["files"])
|
||||||
|
@ -399,7 +401,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
filesView.Highlight = true
|
filesView.Highlight = true
|
||||||
filesView.Title = gui.Tr.SLocalize("FilesTitle")
|
filesView.Title = gui.Tr.SLocalize("FilesTitle")
|
||||||
v.FgColor = gocui.ColorWhite
|
v.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
branchesView, err := g.SetViewBeneath("branches", "files", vHeights["branches"])
|
branchesView, err := g.SetViewBeneath("branches", "files", vHeights["branches"])
|
||||||
|
@ -408,7 +410,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
||||||
branchesView.FgColor = gocui.ColorWhite
|
branchesView.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := g.SetViewBeneath("commitFiles", "branches", vHeights["commits"]); err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
v.Title = gui.Tr.SLocalize("CommitFiles")
|
v.Title = gui.Tr.SLocalize("CommitFiles")
|
||||||
v.FgColor = gocui.ColorWhite
|
v.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
commitsView, err := g.SetViewBeneath("commits", "branches", vHeights["commits"])
|
commitsView, err := g.SetViewBeneath("commits", "branches", vHeights["commits"])
|
||||||
|
@ -425,7 +427,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||||
commitsView.FgColor = gocui.ColorWhite
|
commitsView.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
stashView, err := g.SetViewBeneath("stash", "commits", vHeights["stash"])
|
stashView, err := g.SetViewBeneath("stash", "commits", vHeights["stash"])
|
||||||
|
@ -434,7 +436,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stashView.Title = gui.Tr.SLocalize("StashTitle")
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
v.Frame = false
|
v.Frame = false
|
||||||
if v.FgColor, err = gui.GetOptionsPanelTextColor(); err != nil {
|
v.FgColor = gui.GetOptionsPanelTextColor()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.getCommitMessageView() == nil {
|
if gui.getCommitMessageView() == nil {
|
||||||
|
@ -455,7 +455,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
g.SetViewOnBottom("commitMessage")
|
g.SetViewOnBottom("commitMessage")
|
||||||
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
|
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
|
||||||
commitMessageView.FgColor = gocui.ColorWhite
|
commitMessageView.FgColor = textColor
|
||||||
commitMessageView.Editable = true
|
commitMessageView.Editable = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,7 +471,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
credentialsView.Title = gui.Tr.SLocalize("CredentialsUsername")
|
credentialsView.Title = gui.Tr.SLocalize("CredentialsUsername")
|
||||||
credentialsView.FgColor = gocui.ColorWhite
|
credentialsView.FgColor = textColor
|
||||||
credentialsView.Editable = true
|
credentialsView.Editable = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"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)
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, false, list)
|
||||||
menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0)
|
menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0)
|
||||||
menuView.Title = title
|
menuView.Title = title
|
||||||
menuView.FgColor = gocui.ColorWhite
|
menuView.FgColor = theme.GocuiDefaultTextColor
|
||||||
menuView.Clear()
|
menuView.Clear()
|
||||||
fmt.Fprint(menuView, list)
|
fmt.Fprint(menuView, list)
|
||||||
gui.State.Panels.Menu.SelectedLine = 0
|
gui.State.Panels.Menu.SelectedLine = 0
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/golang-collections/collections/stack"
|
"github.com/golang-collections/collections/stack"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ func (gui *Gui) coloredConflictFile(content string, conflicts []commands.Conflic
|
||||||
conflict, remainingConflicts := gui.shiftConflict(conflicts)
|
conflict, remainingConflicts := gui.shiftConflict(conflicts)
|
||||||
var outputBuffer bytes.Buffer
|
var outputBuffer bytes.Buffer
|
||||||
for i, line := range utils.SplitLines(content) {
|
for i, line := range utils.SplitLines(content) {
|
||||||
colourAttr := color.FgWhite
|
colourAttr := theme.DefaultTextColor
|
||||||
if i == conflict.Start || i == conflict.Middle || i == conflict.End {
|
if i == conflict.Start || i == conflict.Middle || i == conflict.End {
|
||||||
colourAttr = color.FgRed
|
colourAttr = color.FgRed
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAttribute gets the gocui color attribute from the string
|
// 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
|
// 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()
|
userConfig := gui.Config.GetUserConfig()
|
||||||
optionsColor := userConfig.GetStringSlice("gui.theme.optionsTextColor")
|
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
|
// SetColorScheme sets the color scheme for the app based on the user config
|
||||||
func (gui *Gui) SetColorScheme() error {
|
func (gui *Gui) SetColorScheme() error {
|
||||||
userConfig := gui.Config.GetUserConfig()
|
userConfig := gui.Config.GetUserConfig()
|
||||||
activeBorderColor := userConfig.GetStringSlice("gui.theme.activeBorderColor")
|
theme.UpdateTheme(userConfig)
|
||||||
inactiveBorderColor := userConfig.GetStringSlice("gui.theme.inactiveBorderColor")
|
|
||||||
gui.g.FgColor = gui.GetColor(inactiveBorderColor)
|
gui.g.FgColor = theme.InactiveBorderColor
|
||||||
gui.g.SelFgColor = gui.GetColor(activeBorderColor)
|
gui.g.SelFgColor = theme.ActiveBorderColor
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
68
pkg/theme/theme.go
Normal file
68
pkg/theme/theme.go
Normal 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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue