style.go

  1package diffview
  2
  3import (
  4	"github.com/charmbracelet/lipgloss/v2"
  5	"github.com/charmbracelet/x/exp/charmtone"
  6)
  7
  8// LineStyle defines the styles for a given line type in the diff view.
  9type LineStyle struct {
 10	LineNumber lipgloss.Style
 11	Symbol     lipgloss.Style
 12	Code       lipgloss.Style
 13}
 14
 15// Style defines the overall style for the diff view, including styles for
 16// different line types such as divider, missing, equal, insert, and delete
 17// lines.
 18type Style struct {
 19	DividerLine LineStyle
 20	MissingLine LineStyle
 21	EqualLine   LineStyle
 22	InsertLine  LineStyle
 23	DeleteLine  LineStyle
 24}
 25
 26// DefaultLightStyle provides a default light theme style for the diff view.
 27var DefaultLightStyle = Style{
 28	DividerLine: LineStyle{
 29		LineNumber: lipgloss.NewStyle().
 30			Foreground(charmtone.Iron).
 31			Background(charmtone.Thunder),
 32		Code: lipgloss.NewStyle().
 33			Foreground(charmtone.Oyster).
 34			Background(charmtone.Anchovy),
 35	},
 36	MissingLine: LineStyle{
 37		LineNumber: lipgloss.NewStyle().
 38			Background(charmtone.Ash),
 39		Code: lipgloss.NewStyle().
 40			Background(charmtone.Ash),
 41	},
 42	EqualLine: LineStyle{
 43		LineNumber: lipgloss.NewStyle().
 44			Foreground(charmtone.Charcoal).
 45			Background(charmtone.Ash),
 46		Code: lipgloss.NewStyle().
 47			Foreground(charmtone.Pepper).
 48			Background(charmtone.Salt),
 49	},
 50	InsertLine: LineStyle{
 51		LineNumber: lipgloss.NewStyle().
 52			Foreground(charmtone.Turtle).
 53			Background(lipgloss.Color("#c8e6c9")),
 54		Symbol: lipgloss.NewStyle().
 55			Foreground(charmtone.Turtle).
 56			Background(lipgloss.Color("#e8f5e9")),
 57		Code: lipgloss.NewStyle().
 58			Foreground(charmtone.Pepper).
 59			Background(lipgloss.Color("#e8f5e9")),
 60	},
 61	DeleteLine: LineStyle{
 62		LineNumber: lipgloss.NewStyle().
 63			Foreground(charmtone.Cherry).
 64			Background(lipgloss.Color("#ffcdd2")),
 65		Symbol: lipgloss.NewStyle().
 66			Foreground(charmtone.Cherry).
 67			Background(lipgloss.Color("#ffebee")),
 68		Code: lipgloss.NewStyle().
 69			Foreground(charmtone.Pepper).
 70			Background(lipgloss.Color("#ffebee")),
 71	},
 72}
 73
 74// DefaultDarkStyle provides a default dark theme style for the diff view.
 75var DefaultDarkStyle = Style{
 76	DividerLine: LineStyle{
 77		LineNumber: lipgloss.NewStyle().
 78			Foreground(charmtone.Smoke).
 79			Background(charmtone.Sapphire),
 80		Code: lipgloss.NewStyle().
 81			Foreground(charmtone.Smoke).
 82			Background(charmtone.Ox),
 83	},
 84	MissingLine: LineStyle{
 85		LineNumber: lipgloss.NewStyle().
 86			Background(charmtone.Charcoal),
 87		Code: lipgloss.NewStyle().
 88			Background(charmtone.Charcoal),
 89	},
 90	EqualLine: LineStyle{
 91		LineNumber: lipgloss.NewStyle().
 92			Foreground(charmtone.Ash).
 93			Background(charmtone.Charcoal),
 94		Code: lipgloss.NewStyle().
 95			Foreground(charmtone.Salt).
 96			Background(charmtone.Pepper),
 97	},
 98	InsertLine: LineStyle{
 99		LineNumber: lipgloss.NewStyle().
100			Foreground(charmtone.Turtle).
101			Background(lipgloss.Color("#293229")),
102		Symbol: lipgloss.NewStyle().
103			Foreground(charmtone.Turtle).
104			Background(lipgloss.Color("#303a30")),
105		Code: lipgloss.NewStyle().
106			Foreground(charmtone.Salt).
107			Background(lipgloss.Color("#303a30")),
108	},
109	DeleteLine: LineStyle{
110		LineNumber: lipgloss.NewStyle().
111			Foreground(charmtone.Cherry).
112			Background(lipgloss.Color("#332929")),
113		Symbol: lipgloss.NewStyle().
114			Foreground(charmtone.Cherry).
115			Background(lipgloss.Color("#3a3030")),
116		Code: lipgloss.NewStyle().
117			Foreground(charmtone.Salt).
118			Background(lipgloss.Color("#3a3030")),
119	},
120}