Skip to content

Commit 5fdd37f

Browse files
author
zjl
committed
feat(ui): add custom cursorline color support
- Add Cursorline field to ColorConfig struct - Implement HexToRGB function for color conversion - Update cursorline color setting in UI - Add debug logging for color processing
1 parent 659bec0 commit 5fdd37f

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

pkg/lsp/tests/md/test.md

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
### 22222
44
## b
55
## c
6+
~~~c
7+
#pragma once
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
class class_c {
11+
public:
12+
class_c() {}
13+
void run_class_c();
14+
int run_class_1(int a,int c){
15+
return 0;
16+
}
17+
void call_1(int a,int b) {}
18+
void call_2() {
19+
call_1(1,2);
20+
}
21+
}
22+
23+
~~~
624
~~~go
725
func (t *Tree) load_ts_lang(cb chan<- bool) error {}
826
for i := range tree_sitter_lang_map {

pkg/ui/config.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
type highlight struct {
1515
Search string `yaml:"search"`
1616
}
17-
type color struct {
18-
Highlight highlight `yaml:"highlight"`
17+
type ColorConfig struct {
18+
Highlight *highlight `yaml:"highlight,omitempty"`
19+
Cursorline *string `yaml:"cursorline,omitempty"`
1920
}
2021
type vimmode struct {
2122
Leadkey string `yaml:"leadkey,omitempty"`
@@ -25,7 +26,7 @@ type LspviConfig struct {
2526
Colorscheme string `yaml:"colorscheme"`
2627
Wrap bool `yaml:"wrap"`
2728
Lsp lspcore.LspConfig `yaml:"lsp"`
28-
Color color `yaml:"color"`
29+
Color ColorConfig `yaml:"color"`
2930
Vim *vimmode `yaml:"vim,omitempty"`
3031
enablevim bool
3132
Keyboard lspvi_command_map `yaml:"keyboard"`
@@ -63,7 +64,7 @@ func NewLspviconfig() *LspviConfig {
6364
default_ret := LspviConfig{
6465
Colorscheme: "darcula",
6566
Wrap: false,
66-
Color: color{},
67+
Color: ColorConfig{},
6768
enablevim: false,
6869
}
6970
return &default_ret

pkg/ui/uicolortheme.go

+31-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"path/filepath"
1010
"strconv"
11+
"strings"
1112

1213
rgb "image/color"
1314

@@ -16,6 +17,7 @@ import (
1617
"github.com/pgavlin/femto/runtime"
1718
"github.com/rivo/tview"
1819
"github.com/tectiv3/go-lsp"
20+
"zen108.com/lspvi/pkg/debug"
1921
"zen108.com/lspvi/pkg/treesittertheme"
2022
// lspcore "zen108.com/lspvi/pkg/lsp"
2123
)
@@ -95,16 +97,40 @@ func IntToRGB(colorInt tcell.Color) rgb.RGBA {
9597
r, g, b := colorInt.RGB()
9698
return rgb.RGBA{uint8(r), uint8(g), uint8(b), 255} // 默认Alpha通道为255(完全不透明)
9799
}
100+
func HexToRGB(hexString string) (int, int, int, error) {
101+
// 去掉前缀 #
102+
hexString = strings.TrimPrefix(hexString, "#")
103+
104+
// 将十六进制字符串转换为整数
105+
value, err := strconv.ParseUint(hexString, 16, 32)
106+
if err != nil {
107+
return 0, 0, 0, err
108+
}
109+
110+
// 提取红色、绿色和蓝色的分量
111+
blue := int(value & 255)
112+
green := int((value >> 8) & 255)
113+
red := int((value >> 16) & 255)
114+
115+
return red, green, blue, nil
116+
}
98117
func (mgr *symbol_colortheme) set_currsor_line() {
99118
if ret := mgr.get_color("cursorline"); ret != nil {
100119
_, bg, _ := ret.Decompose()
101-
x := lightenColor(IntToRGB(bg), 0.0)
120+
ss := bg.Hex()
121+
debug.DebugLogf("color", "#%x %s", ss, mgr.name)
122+
x := lightenColor(IntToRGB(bg), 0.2)
102123
v := ColorToCellColor(x)
103124
s := ret.Background(v)
104-
mgr.colorscheme["cursor-line"] = s //*ret
105-
// if _, ok := mgr.colorscheme["selection"]; !ok {
106-
// mgr.colorscheme["selection"] = *ret
107-
// }
125+
_, bg, _ = s.Decompose()
126+
debug.DebugLogf("color", "#%x %s", bg.Hex(), mgr.name)
127+
mgr.colorscheme["cursor-line"] = s
128+
}
129+
if bg := global_config.Color.Cursorline; bg != nil {
130+
if r, g, b, err := hexToRGB(*bg); err == nil {
131+
s := tcell.StyleDefault.Background(tcell.NewRGBColor(r, g, b))
132+
mgr.colorscheme["cursor-line"] = s
133+
}
108134
}
109135
if ret := mgr.get_color("visual"); ret != nil {
110136
mgr.colorscheme["selection"] = *ret

0 commit comments

Comments
 (0)