Skip to content

Commit

Permalink
feat(ui): add custom cursorline color support
Browse files Browse the repository at this point in the history
- Add Cursorline field to ColorConfig struct
- Implement HexToRGB function for color conversion
- Update cursorline color setting in UI
- Add debug logging for color processing
  • Loading branch information
zjl committed Nov 2, 2024
1 parent 659bec0 commit 5fdd37f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
18 changes: 18 additions & 0 deletions pkg/lsp/tests/md/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
### 22222
## b
## c
~~~c
#pragma once
#include <stdio.h>
#include <stdlib.h>
class class_c {
public:
class_c() {}
void run_class_c();
int run_class_1(int a,int c){
return 0;
}
void call_1(int a,int b) {}
void call_2() {
call_1(1,2);
}
}

~~~
~~~go
func (t *Tree) load_ts_lang(cb chan<- bool) error {}
for i := range tree_sitter_lang_map {
Expand Down
9 changes: 5 additions & 4 deletions pkg/ui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
type highlight struct {
Search string `yaml:"search"`
}
type color struct {
Highlight highlight `yaml:"highlight"`
type ColorConfig struct {
Highlight *highlight `yaml:"highlight,omitempty"`
Cursorline *string `yaml:"cursorline,omitempty"`
}
type vimmode struct {
Leadkey string `yaml:"leadkey,omitempty"`
Expand All @@ -25,7 +26,7 @@ type LspviConfig struct {
Colorscheme string `yaml:"colorscheme"`
Wrap bool `yaml:"wrap"`
Lsp lspcore.LspConfig `yaml:"lsp"`
Color color `yaml:"color"`
Color ColorConfig `yaml:"color"`
Vim *vimmode `yaml:"vim,omitempty"`
enablevim bool
Keyboard lspvi_command_map `yaml:"keyboard"`
Expand Down Expand Up @@ -63,7 +64,7 @@ func NewLspviconfig() *LspviConfig {
default_ret := LspviConfig{
Colorscheme: "darcula",
Wrap: false,
Color: color{},
Color: ColorConfig{},
enablevim: false,
}
return &default_ret
Expand Down
36 changes: 31 additions & 5 deletions pkg/ui/uicolortheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"

rgb "image/color"

Expand All @@ -16,6 +17,7 @@ import (
"github.com/pgavlin/femto/runtime"
"github.com/rivo/tview"
"github.com/tectiv3/go-lsp"
"zen108.com/lspvi/pkg/debug"
"zen108.com/lspvi/pkg/treesittertheme"
// lspcore "zen108.com/lspvi/pkg/lsp"
)
Expand Down Expand Up @@ -95,16 +97,40 @@ func IntToRGB(colorInt tcell.Color) rgb.RGBA {
r, g, b := colorInt.RGB()
return rgb.RGBA{uint8(r), uint8(g), uint8(b), 255} // 默认Alpha通道为255(完全不透明)
}
func HexToRGB(hexString string) (int, int, int, error) {
// 去掉前缀 #
hexString = strings.TrimPrefix(hexString, "#")

// 将十六进制字符串转换为整数
value, err := strconv.ParseUint(hexString, 16, 32)
if err != nil {
return 0, 0, 0, err
}

// 提取红色、绿色和蓝色的分量
blue := int(value & 255)
green := int((value >> 8) & 255)
red := int((value >> 16) & 255)

return red, green, blue, nil
}
func (mgr *symbol_colortheme) set_currsor_line() {
if ret := mgr.get_color("cursorline"); ret != nil {
_, bg, _ := ret.Decompose()
x := lightenColor(IntToRGB(bg), 0.0)
ss := bg.Hex()
debug.DebugLogf("color", "#%x %s", ss, mgr.name)
x := lightenColor(IntToRGB(bg), 0.2)
v := ColorToCellColor(x)
s := ret.Background(v)
mgr.colorscheme["cursor-line"] = s //*ret
// if _, ok := mgr.colorscheme["selection"]; !ok {
// mgr.colorscheme["selection"] = *ret
// }
_, bg, _ = s.Decompose()
debug.DebugLogf("color", "#%x %s", bg.Hex(), mgr.name)
mgr.colorscheme["cursor-line"] = s
}
if bg := global_config.Color.Cursorline; bg != nil {
if r, g, b, err := hexToRGB(*bg); err == nil {
s := tcell.StyleDefault.Background(tcell.NewRGBColor(r, g, b))
mgr.colorscheme["cursor-line"] = s
}
}
if ret := mgr.get_color("visual"); ret != nil {
mgr.colorscheme["selection"] = *ret
Expand Down

0 comments on commit 5fdd37f

Please sign in to comment.