fix: removed chroma from project
This commit is contained in:
parent
16d1318c22
commit
7c15f41ab1
6
go.mod
6
go.mod
@ -3,12 +3,11 @@ module git.gophernest.net/azpect/TextEditor
|
|||||||
go 1.25.5
|
go 1.25.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/chroma/v2 v2.23.1
|
|
||||||
github.com/charmbracelet/bubbletea v1.3.10
|
github.com/charmbracelet/bubbletea v1.3.10
|
||||||
github.com/charmbracelet/lipgloss v1.1.0
|
github.com/charmbracelet/lipgloss v1.1.0
|
||||||
github.com/charmbracelet/x/exp/teatest v0.0.0-20260209132835-6b065b8ba62c
|
github.com/charmbracelet/x/exp/teatest v0.0.0-20260209132835-6b065b8ba62c
|
||||||
github.com/tree-sitter/go-tree-sitter v0.25.0
|
github.com/tree-sitter/go-tree-sitter v0.25.0
|
||||||
github.com/tree-sitter/tree-sitter-javascript v0.25.0
|
github.com/tree-sitter/tree-sitter-go v0.25.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -22,7 +21,6 @@ require (
|
|||||||
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||||
github.com/clipperhouse/stringish v0.1.1 // indirect
|
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||||
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
||||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
@ -33,7 +31,7 @@ require (
|
|||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
github.com/muesli/termenv v0.16.0 // indirect
|
github.com/muesli/termenv v0.16.0 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/tree-sitter/tree-sitter-go v0.25.0 // indirect
|
github.com/tree-sitter/tree-sitter-javascript v0.25.0 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
golang.org/x/sys v0.38.0 // indirect
|
golang.org/x/sys v0.38.0 // indirect
|
||||||
golang.org/x/text v0.28.0 // indirect
|
golang.org/x/text v0.28.0 // indirect
|
||||||
|
|||||||
10
go.sum
10
go.sum
@ -1,9 +1,3 @@
|
|||||||
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
|
|
||||||
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
|
||||||
github.com/alecthomas/chroma/v2 v2.23.1 h1:nv2AVZdTyClGbVQkIzlDm/rnhk1E9bU9nXwmZ/Vk/iY=
|
|
||||||
github.com/alecthomas/chroma/v2 v2.23.1/go.mod h1:NqVhfBR0lte5Ouh3DcthuUCTUpDC9cxBOfyMbMQPs3o=
|
|
||||||
github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
|
|
||||||
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
|
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
|
||||||
@ -32,12 +26,8 @@ github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w
|
|||||||
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
|
||||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
|
||||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
|
||||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import (
|
|||||||
"git.gophernest.net/azpect/TextEditor/internal/action"
|
"git.gophernest.net/azpect/TextEditor/internal/action"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/core"
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/style"
|
"git.gophernest.net/azpect/TextEditor/internal/style"
|
||||||
"github.com/alecthomas/chroma/v2/styles"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -883,29 +882,31 @@ func parseSetOption(m action.Model, opt string) error {
|
|||||||
// Colorscheme Commands
|
// Colorscheme Commands
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
|
// TODO: Implement this using the new colorschemes
|
||||||
func cmdColorscheme(m action.Model, args []string, force bool) tea.Cmd {
|
func cmdColorscheme(m action.Model, args []string, force bool) tea.Cmd {
|
||||||
_ = force
|
_ = force
|
||||||
|
|
||||||
// No args, just print the current scheme
|
// No args, just print the current scheme
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
s := m.Styles().ChromaStyle
|
|
||||||
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
m.SetCommandOutput(&core.CommandOutput{
|
m.SetCommandOutput(&core.CommandOutput{
|
||||||
Lines: []string{s.Name},
|
Lines: []string{"default"},
|
||||||
Inline: true,
|
Inline: true,
|
||||||
IsError: false,
|
IsError: false,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args given, set the scheme
|
// Theme switching is disabled while migrating away from Chroma.
|
||||||
name := strings.Join(args, " ")
|
name := strings.TrimSpace(strings.Join(args, " "))
|
||||||
|
if name == "" {
|
||||||
chromaStyle := styles.Registry[name]
|
m.SetCommandOutput(&core.CommandOutput{
|
||||||
if chromaStyle == nil {
|
Lines: []string{"colorscheme not found: "},
|
||||||
|
Inline: true,
|
||||||
|
IsError: true,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if name != "" && strings.ToLower(name) != "default" {
|
||||||
m.SetCommandOutput(&core.CommandOutput{
|
m.SetCommandOutput(&core.CommandOutput{
|
||||||
Lines: []string{fmt.Sprintf("colorscheme not found: %s", name)},
|
Lines: []string{fmt.Sprintf("colorscheme not found: %s", name)},
|
||||||
Inline: true,
|
Inline: true,
|
||||||
@ -914,14 +915,14 @@ func cmdColorscheme(m action.Model, args []string, force bool) tea.Cmd {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetStyles(style.ChromaStyles(chromaStyle))
|
m.SetStyles(style.DefaultStyles())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdListColorschemes(m action.Model, args []string, force bool) tea.Cmd {
|
func cmdListColorschemes(m action.Model, args []string, force bool) tea.Cmd {
|
||||||
_, _ = args, force
|
_, _ = args, force
|
||||||
|
|
||||||
colors := styles.Names()
|
colors := []string{"default"}
|
||||||
|
|
||||||
m.SetMode(core.CommandOutputMode)
|
m.SetMode(core.CommandOutputMode)
|
||||||
m.SetCommandOutput(&core.CommandOutput{
|
m.SetCommandOutput(&core.CommandOutput{
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"git.gophernest.net/azpect/TextEditor/internal/action"
|
"git.gophernest.net/azpect/TextEditor/internal/action"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/core"
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/style"
|
"git.gophernest.net/azpect/TextEditor/internal/style"
|
||||||
cStyles "github.com/alecthomas/chroma/v2/styles"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -5515,22 +5514,24 @@ func TestCmdColorscheme(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("valid name updates styles on model", func(t *testing.T) {
|
t.Run("valid name updates styles on model", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
m.SetStyles(style.DefaultStyles())
|
||||||
|
before := m.StylesVal.BackgroundStyle.Render(" ")
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"onedark"}, false)
|
cmdColorscheme(m, []string{"default"}, false)
|
||||||
|
|
||||||
name := m.Styles().ChromaStyle.Name
|
after := m.StylesVal.BackgroundStyle.Render(" ")
|
||||||
if name != "onedark" {
|
if after != before {
|
||||||
t.Error("expected styles to change after setting a valid colorscheme")
|
t.Error("expected default styles to remain stable after applying default")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("same valid name applied twice produces same styles", func(t *testing.T) {
|
t.Run("same valid name applied twice produces same styles", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"monokai"}, false)
|
cmdColorscheme(m, []string{"default"}, false)
|
||||||
first := m.StylesVal.BackgroundStyle.Render(" ")
|
first := m.StylesVal.BackgroundStyle.Render(" ")
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"monokai"}, false)
|
cmdColorscheme(m, []string{"default"}, false)
|
||||||
second := m.StylesVal.BackgroundStyle.Render(" ")
|
second := m.StylesVal.BackgroundStyle.Render(" ")
|
||||||
|
|
||||||
if first != second {
|
if first != second {
|
||||||
@ -5541,7 +5542,7 @@ func TestCmdColorscheme(t *testing.T) {
|
|||||||
t.Run("valid name sets no error output", func(t *testing.T) {
|
t.Run("valid name sets no error output", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"monokai"}, false)
|
cmdColorscheme(m, []string{"default"}, false)
|
||||||
|
|
||||||
if m.CommandOutputVal != nil && m.CommandOutputVal.IsError {
|
if m.CommandOutputVal != nil && m.CommandOutputVal.IsError {
|
||||||
t.Error("expected no error output for a valid colorscheme name")
|
t.Error("expected no error output for a valid colorscheme name")
|
||||||
@ -5551,7 +5552,7 @@ func TestCmdColorscheme(t *testing.T) {
|
|||||||
t.Run("valid name returns nil tea.Cmd", func(t *testing.T) {
|
t.Run("valid name returns nil tea.Cmd", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
|
||||||
cmd := cmdColorscheme(m, []string{"monokai"}, false)
|
cmd := cmdColorscheme(m, []string{"default"}, false)
|
||||||
|
|
||||||
if cmd != nil {
|
if cmd != nil {
|
||||||
t.Error("expected nil tea.Cmd for colorscheme command")
|
t.Error("expected nil tea.Cmd for colorscheme command")
|
||||||
@ -5651,7 +5652,7 @@ func TestCmdColorscheme(t *testing.T) {
|
|||||||
t.Run("extra args beyond name do not panic", func(t *testing.T) {
|
t.Run("extra args beyond name do not panic", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"monokai", "extra", "args"}, false)
|
cmdColorscheme(m, []string{"default", "extra", "args"}, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
@ -5661,10 +5662,9 @@ func TestCmdColorscheme(t *testing.T) {
|
|||||||
t.Run("force flag with valid name still sets styles", func(t *testing.T) {
|
t.Run("force flag with valid name still sets styles", func(t *testing.T) {
|
||||||
m := action.NewMockModel()
|
m := action.NewMockModel()
|
||||||
|
|
||||||
cmdColorscheme(m, []string{"monokai"}, true)
|
cmdColorscheme(m, []string{"default"}, true)
|
||||||
|
|
||||||
name := m.Styles().ChromaStyle.Name
|
if m.CommandOutputVal != nil && m.CommandOutputVal.IsError {
|
||||||
if name != "monokai" {
|
|
||||||
t.Error("expected styles to change with force=true and valid name")
|
t.Error("expected styles to change with force=true and valid name")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -5742,7 +5742,7 @@ func TestCmdListColorschemes(t *testing.T) {
|
|||||||
cmdListColorschemes(m, []string{}, false)
|
cmdListColorschemes(m, []string{}, false)
|
||||||
|
|
||||||
lines := m.CommandOutputVal.Lines
|
lines := m.CommandOutputVal.Lines
|
||||||
known := []string{"monokai", "github-dark", "dracula"}
|
known := []string{"default"}
|
||||||
for _, name := range known {
|
for _, name := range known {
|
||||||
found := false
|
found := false
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
@ -5762,7 +5762,7 @@ func TestCmdListColorschemes(t *testing.T) {
|
|||||||
|
|
||||||
cmdListColorschemes(m, []string{}, false)
|
cmdListColorschemes(m, []string{}, false)
|
||||||
|
|
||||||
expected := cStyles.Names()
|
expected := []string{"default"}
|
||||||
if len(m.CommandOutputVal.Lines) != len(expected) {
|
if len(m.CommandOutputVal.Lines) != len(expected) {
|
||||||
t.Errorf("expected %d colorschemes, got %d", len(expected), len(m.CommandOutputVal.Lines))
|
t.Errorf("expected %d colorschemes, got %d", len(expected), len(m.CommandOutputVal.Lines))
|
||||||
}
|
}
|
||||||
@ -5785,7 +5785,7 @@ func TestCmdListColorschemes(t *testing.T) {
|
|||||||
m2 := action.NewMockModel()
|
m2 := action.NewMockModel()
|
||||||
|
|
||||||
cmdListColorschemes(m1, []string{}, false)
|
cmdListColorschemes(m1, []string{}, false)
|
||||||
cmdListColorschemes(m2, []string{"monokai", "extra"}, true)
|
cmdListColorschemes(m2, []string{"default", "extra"}, true)
|
||||||
|
|
||||||
if len(m1.CommandOutputVal.Lines) != len(m2.CommandOutputVal.Lines) {
|
if len(m1.CommandOutputVal.Lines) != len(m2.CommandOutputVal.Lines) {
|
||||||
t.Error("expected args and force to have no effect on list output")
|
t.Error("expected args and force to have no effect on list output")
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"git.gophernest.net/azpect/TextEditor/internal/input"
|
"git.gophernest.net/azpect/TextEditor/internal/input"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/style"
|
"git.gophernest.net/azpect/TextEditor/internal/style"
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/syntax"
|
"git.gophernest.net/azpect/TextEditor/internal/syntax"
|
||||||
"github.com/alecthomas/chroma/v2/styles"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelBuilder struct {
|
type ModelBuilder struct {
|
||||||
@ -14,8 +13,7 @@ type ModelBuilder struct {
|
|||||||
|
|
||||||
// NewModelBuilder: Builds and returns a new model, using the default color scheme (kanagawa-wave).
|
// NewModelBuilder: Builds and returns a new model, using the default color scheme (kanagawa-wave).
|
||||||
func NewModelBuilder() *ModelBuilder {
|
func NewModelBuilder() *ModelBuilder {
|
||||||
chromaStyle := styles.Get("kanagawa-wave")
|
editorStyles := style.DefaultStyles()
|
||||||
editorStyles := style.ChromaStyles(chromaStyle)
|
|
||||||
|
|
||||||
return &ModelBuilder{
|
return &ModelBuilder{
|
||||||
model: Model{
|
model: Model{
|
||||||
|
|||||||
223
internal/style/style.go
Executable file → Normal file
223
internal/style/style.go
Executable file → Normal file
@ -1,11 +1,7 @@
|
|||||||
package style
|
package style
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.gophernest.net/azpect/TextEditor/internal/core"
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
||||||
"github.com/alecthomas/chroma/v2"
|
|
||||||
"github.com/alecthomas/chroma/v2/lexers"
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +19,7 @@ type Styles struct {
|
|||||||
|
|
||||||
// Visual mode
|
// Visual mode
|
||||||
VisualHighlight lipgloss.Style
|
VisualHighlight lipgloss.Style
|
||||||
VisualAnchor lipgloss.Style // debugging
|
VisualAnchor lipgloss.Style
|
||||||
|
|
||||||
// Status bar
|
// Status bar
|
||||||
StatusBar lipgloss.Style
|
StatusBar lipgloss.Style
|
||||||
@ -34,132 +30,72 @@ type Styles struct {
|
|||||||
CommandOutputBorder lipgloss.Style
|
CommandOutputBorder lipgloss.Style
|
||||||
CommandContinueMessage lipgloss.Style
|
CommandContinueMessage lipgloss.Style
|
||||||
|
|
||||||
// General Styles
|
// General styles
|
||||||
LineStyle lipgloss.Style // This is a simple background with no text coloring
|
LineStyle lipgloss.Style
|
||||||
BackgroundStyle lipgloss.Style // This is just the background
|
BackgroundStyle lipgloss.Style
|
||||||
|
|
||||||
// Chroma data
|
|
||||||
ChromaStyle *chroma.Style
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultStyles: Returns the default editor color scheme.
|
// DefaultStyles: Returns the default editor color scheme.
|
||||||
func DefaultStyles() Styles {
|
func DefaultStyles() Styles {
|
||||||
return Styles{
|
bg := lipgloss.Color("#1f2335")
|
||||||
CursorNormal: lipgloss.NewStyle().Reverse(true),
|
fg := lipgloss.Color("#dcd7ba")
|
||||||
CursorInsert: lipgloss.NewStyle().Underline(true),
|
|
||||||
CursorCommand: lipgloss.NewStyle().Reverse(true),
|
|
||||||
CursorReplace: lipgloss.NewStyle().Underline(true),
|
|
||||||
|
|
||||||
Gutter: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("236")).
|
|
||||||
Foreground(lipgloss.Color("243")),
|
|
||||||
|
|
||||||
GutterCurrentLine: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("236")).
|
|
||||||
Foreground(lipgloss.Color("#d69d00")),
|
|
||||||
|
|
||||||
VisualHighlight: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("#7a6a00")),
|
|
||||||
|
|
||||||
VisualAnchor: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("#a89020")),
|
|
||||||
|
|
||||||
StatusBar: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("236")).
|
|
||||||
Foreground(lipgloss.Color("243")),
|
|
||||||
|
|
||||||
StatusBarActive: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("62")).
|
|
||||||
Foreground(lipgloss.Color("230")),
|
|
||||||
|
|
||||||
CommandError: lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#e3203a")),
|
|
||||||
|
|
||||||
CommandOutputBorder: lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color("#000000")),
|
|
||||||
|
|
||||||
CommandContinueMessage: lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#546fba")),
|
|
||||||
|
|
||||||
ChromaStyle: nil,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ChromaStyles(chromaStyle *chroma.Style) Styles {
|
|
||||||
bgString := chromaStyle.Get(chroma.Background).Background.String()
|
|
||||||
lineNumbers := chromaStyle.Get(chroma.LineTableTD)
|
|
||||||
lineHighlight := chromaStyle.Get(chroma.LineHighlight)
|
|
||||||
|
|
||||||
return Styles{
|
return Styles{
|
||||||
CursorNormal: lipgloss.NewStyle().
|
CursorNormal: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(fg).
|
||||||
Reverse(true),
|
Foreground(bg),
|
||||||
|
|
||||||
CursorInsert: lipgloss.NewStyle().
|
CursorInsert: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(bg).
|
||||||
Bold(true).
|
Foreground(fg).
|
||||||
Underline(true),
|
Underline(true),
|
||||||
|
|
||||||
CursorCommand: lipgloss.NewStyle().
|
CursorCommand: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(fg).
|
||||||
Reverse(true),
|
Foreground(bg),
|
||||||
|
|
||||||
CursorReplace: lipgloss.NewStyle().
|
CursorReplace: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(bg).
|
||||||
|
Foreground(fg).
|
||||||
Underline(true),
|
Underline(true),
|
||||||
|
|
||||||
Gutter: lipgloss.NewStyle().
|
Gutter: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(
|
Background(lipgloss.Color("#181b2a")).
|
||||||
darkenColor(lineNumbers.Background, 0.9).String()),
|
Foreground(lipgloss.Color("#7e8399")),
|
||||||
).
|
|
||||||
Foreground(lipgloss.Color(lineNumbers.Colour.String())),
|
|
||||||
|
|
||||||
GutterCurrentLine: lipgloss.NewStyle().
|
GutterCurrentLine: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(
|
Background(lipgloss.Color("#181b2a")).
|
||||||
darkenColor(lineNumbers.Background, 0.9).String()),
|
Foreground(lipgloss.Color("#e6c384")),
|
||||||
).
|
|
||||||
Foreground(lipgloss.Color(lineNumbers.Colour.String())),
|
|
||||||
|
|
||||||
VisualHighlight: lipgloss.NewStyle().
|
VisualHighlight: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(lineHighlight.Background.String())).
|
Background(lipgloss.Color("#2f334d")),
|
||||||
Foreground(lipgloss.Color(lineHighlight.Colour.String())),
|
|
||||||
|
|
||||||
VisualAnchor: lipgloss.NewStyle().
|
VisualAnchor: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(lineHighlight.Background.String())).
|
Background(lipgloss.Color("#3a3f5f")),
|
||||||
Foreground(lipgloss.Color(lineHighlight.Colour.String())),
|
|
||||||
|
|
||||||
StatusBar: lipgloss.NewStyle().
|
StatusBar: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(lipgloss.Color("#181b2a")).
|
||||||
Foreground(lipgloss.Color("243")),
|
Foreground(lipgloss.Color("#8ea4a2")),
|
||||||
|
|
||||||
StatusBarActive: lipgloss.NewStyle().
|
StatusBarActive: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Background(lipgloss.Color("#223249")).
|
||||||
Foreground(lipgloss.Color("230")),
|
Foreground(lipgloss.Color("#9ec1cf")),
|
||||||
|
|
||||||
CommandError: lipgloss.NewStyle().
|
CommandError: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Foreground(lipgloss.Color("#e82424")),
|
||||||
Foreground(lipgloss.Color("#e3203a")),
|
|
||||||
|
|
||||||
CommandOutputBorder: lipgloss.NewStyle().
|
CommandOutputBorder: lipgloss.NewStyle().
|
||||||
Background(
|
Background(lipgloss.Color("#11131d")),
|
||||||
lipgloss.Color(
|
|
||||||
darkenColor(
|
|
||||||
chromaStyle.Get(chroma.Background).Background, 0.5).
|
|
||||||
String(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
CommandContinueMessage: lipgloss.NewStyle().
|
CommandContinueMessage: lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color(bgString)).
|
Foreground(lipgloss.Color("#7aa2f7")),
|
||||||
Foreground(lipgloss.Color("#546fba")),
|
|
||||||
|
|
||||||
LineStyle: lipgloss.NewStyle().
|
LineStyle: lipgloss.NewStyle().
|
||||||
Foreground(lipgloss.Color(chromaStyle.Get(chroma.Line).Colour.String())).
|
Foreground(fg).
|
||||||
Background(lipgloss.Color(bgString)),
|
Background(bg),
|
||||||
|
|
||||||
BackgroundStyle: lipgloss.NewStyle().Background(lipgloss.Color(bgString)),
|
BackgroundStyle: lipgloss.NewStyle().
|
||||||
|
Background(bg),
|
||||||
ChromaStyle: chromaStyle,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,106 +113,29 @@ func (s Styles) DefaultCursorStyle(mode core.Mode) lipgloss.Style {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Styles.CursorStyle: Returns a cursor style derived from a chroma style. This function should preferred
|
// Styles.CursorStyle: Returns a cursor style derived from the text style.
|
||||||
// over the DefaultCursorStyle, but in cases where there is no style to apply, the DefaultCursorStyle
|
func (s Styles) CursorStyle(mode core.Mode, textStyle lipgloss.Style) lipgloss.Style {
|
||||||
// will always work.
|
|
||||||
func (s Styles) CursorStyle(mode core.Mode, style lipgloss.Style) lipgloss.Style {
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case core.NormalMode, core.VisualLineMode, core.VisualBlockMode, core.VisualMode:
|
case core.NormalMode, core.VisualLineMode, core.VisualBlockMode, core.VisualMode:
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
Background(style.GetForeground()).
|
Background(textStyle.GetForeground()).
|
||||||
Foreground(style.GetBackground())
|
Foreground(textStyle.GetBackground())
|
||||||
case core.ReplaceMode, core.WaitingMode:
|
case core.ReplaceMode, core.WaitingMode:
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
Background(style.GetBackground()).
|
Background(textStyle.GetBackground()).
|
||||||
Foreground(style.GetForeground()).
|
Foreground(textStyle.GetForeground()).
|
||||||
Underline(true)
|
Underline(true)
|
||||||
default:
|
default:
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
Background(s.BackgroundStyle.GetBackground()).
|
Background(s.BackgroundStyle.GetBackground()).
|
||||||
Foreground(style.GetForeground()).
|
Foreground(textStyle.GetForeground()).
|
||||||
Underline(true)
|
Underline(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Styles.VisualHighlightWithTextColor: Works analogously to CursorStyle vs DefaultCursorStyle. When a
|
// Styles.VisualHighlightWithTextColor: Applies visual background while preserving text color.
|
||||||
// style is available, this function should be used, so the text color will be rendered in front
|
func (s Styles) VisualHighlightWithTextColor(textStyle lipgloss.Style) lipgloss.Style {
|
||||||
// of the background. Otherwise, the VisualHighlight property will always work.
|
|
||||||
func (s Styles) VisualHighlightWithTextColor(style lipgloss.Style) lipgloss.Style {
|
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
Background(s.VisualHighlight.GetBackground()).
|
Background(s.VisualHighlight.GetBackground()).
|
||||||
Foreground(style.GetForeground())
|
Foreground(textStyle.GetForeground())
|
||||||
}
|
|
||||||
|
|
||||||
// Styles.MakeStyleMap: Generates a style map for a single line. A style map is a mapping from
|
|
||||||
// column a lipgloss style. Cursor styles are not handled by this map, but they can be derived
|
|
||||||
// by inverting the background and foreground (and rolling back to the default).
|
|
||||||
func (s Styles) MakeStyleMap(lexer chroma.Lexer, line string) []lipgloss.Style {
|
|
||||||
m := make([]lipgloss.Style, len(line))
|
|
||||||
|
|
||||||
if s.ChromaStyle == nil {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
iter, err := lexer.Tokenise(nil, line)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
col := 0
|
|
||||||
for _, token := range iter.Tokens() {
|
|
||||||
entry := s.ChromaStyle.Get(token.Type)
|
|
||||||
s := lipgloss.NewStyle().
|
|
||||||
Background(lipgloss.Color(entry.Background.String())).
|
|
||||||
Foreground(lipgloss.Color(entry.Colour.String()))
|
|
||||||
for _, char := range token.Value {
|
|
||||||
if char == '\n' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if col < len(m) {
|
|
||||||
m[col] = s
|
|
||||||
}
|
|
||||||
col++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
// darkenColor: Uses a factor (0.0 to 1.0) to darken a color using its opacity.
|
|
||||||
func darkenColor(c chroma.Colour, factor float64) chroma.Colour {
|
|
||||||
r := uint8(float64(c.Red()) * factor)
|
|
||||||
g := uint8(float64(c.Green()) * factor)
|
|
||||||
b := uint8(float64(c.Blue()) * factor)
|
|
||||||
return chroma.NewColour(r, g, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLexer: Uses buffer meta data or content to pick a lexer for use in applying
|
|
||||||
// highlights.
|
|
||||||
func GetLexer(buf *core.Buffer) chroma.Lexer {
|
|
||||||
var lexer chroma.Lexer
|
|
||||||
|
|
||||||
if buf.Filetype != "" {
|
|
||||||
lexer = lexers.Get(strings.TrimPrefix(buf.Filetype, "."))
|
|
||||||
}
|
|
||||||
|
|
||||||
if lexer == nil && buf.Filename != "" {
|
|
||||||
lexer = lexers.Match(buf.Filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
if lexer == nil && len(buf.Lines) > 0 {
|
|
||||||
// Get first few lines for content analysis
|
|
||||||
var content strings.Builder
|
|
||||||
for i := 0; i < min(len(buf.Lines), 10); i++ {
|
|
||||||
content.WriteString(buf.Lines[i].String() + "\n")
|
|
||||||
}
|
|
||||||
lexer = lexers.Analyse(content.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
if lexer == nil {
|
|
||||||
lexer = lexers.Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
lexer = chroma.Coalesce(lexer) // Merge tokens together
|
|
||||||
return lexer
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +1,7 @@
|
|||||||
package theme
|
package theme
|
||||||
|
|
||||||
import (
|
// RegisterAll is retained as a no-op for compatibility while Chroma-based
|
||||||
"embed"
|
// theme loading is removed.
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
|
||||||
"github.com/alecthomas/chroma/v2/styles"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed themes/*
|
|
||||||
var themeFS embed.FS
|
|
||||||
|
|
||||||
// RegisterAll: Registers all XML theme files embedded in the themes/ directory
|
|
||||||
// with chroma's style registry. After calling this, styles.Get() will recognize
|
|
||||||
// any theme defined in those files.
|
|
||||||
func RegisterAll() error {
|
func RegisterAll() error {
|
||||||
entries, err := themeFS.ReadDir("themes")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to read embedded themes directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, entry := range entries {
|
|
||||||
if entry.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := themeFS.Open("themes/" + entry.Name())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to open theme %s: %w", entry.Name(), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
style, err := chroma.NewXMLStyle(f)
|
|
||||||
f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to parse theme %s: %w", entry.Name(), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
styles.Register(style)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user