This means we can finally create some themes! But the treesitter mapping is not complete.
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package theme
|
|
|
|
import (
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
type EditorTheme struct {
|
|
Cursors CursorTheme
|
|
Gutter GutterTheme
|
|
VisualHightlight lipgloss.Style
|
|
StatusBar StatusBarTheme
|
|
CommandLine CommandLineTheme
|
|
Line lipgloss.Style
|
|
Background lipgloss.Style
|
|
}
|
|
|
|
type CursorTheme struct {
|
|
Normal lipgloss.Style
|
|
Insert lipgloss.Style
|
|
Command lipgloss.Style
|
|
Replace lipgloss.Style
|
|
}
|
|
|
|
type GutterTheme struct {
|
|
Default lipgloss.Style
|
|
CurrentLine lipgloss.Style
|
|
}
|
|
|
|
type StatusBarTheme struct {
|
|
Default lipgloss.Style
|
|
}
|
|
|
|
type CommandLineTheme struct {
|
|
Error lipgloss.Style
|
|
OutputBorder lipgloss.Style
|
|
ContinueMessage lipgloss.Style
|
|
}
|
|
|
|
func (t EditorTheme) Cursor(mode core.Mode, textStyle lipgloss.Style) lipgloss.Style {
|
|
bg := textStyle.GetBackground()
|
|
fg := textStyle.GetForeground()
|
|
|
|
switch mode {
|
|
case core.NormalMode, core.VisualLineMode, core.VisualBlockMode, core.VisualMode:
|
|
return lipgloss.NewStyle().
|
|
Background(fg).
|
|
Foreground(bg)
|
|
case core.ReplaceMode, core.WaitingMode:
|
|
return textStyle.
|
|
Underline(true)
|
|
default:
|
|
return t.Background.
|
|
Foreground(fg).
|
|
Underline(true)
|
|
}
|
|
}
|
|
|
|
func (t EditorTheme) DefaultCursor(mode core.Mode) lipgloss.Style {
|
|
switch mode {
|
|
case core.InsertMode:
|
|
return t.Cursors.Insert
|
|
case core.CommandMode:
|
|
return t.Cursors.Command
|
|
case core.ReplaceMode:
|
|
return t.Cursors.Replace
|
|
default:
|
|
return t.Cursors.Normal
|
|
}
|
|
}
|
|
|
|
// This method is preferred to raw access of EditorTheme.VisualHightlight since
|
|
// is has the proper foreground color applied
|
|
func (t EditorTheme) VisualHighlightWithTextColor(textStyle lipgloss.Style) lipgloss.Style {
|
|
return t.VisualHightlight.
|
|
Foreground(textStyle.GetForeground())
|
|
}
|