- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
166 lines
5.1 KiB
Go
166 lines
5.1 KiB
Go
package app
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
"github.com/egoist/mygo/ui/editor"
|
|
)
|
|
|
|
// 语法配色两套,与界面主题配套。
|
|
//
|
|
// 深色 One Dark Vivid 浅色 One Light
|
|
// 关键字 紫 #D55FDE 紫 #A626A4
|
|
// 函数 蓝 #61AFEF 蓝 #4078F2
|
|
// 类型 黄 #E5C07B 黄 #C18401
|
|
// 变量 红 #EF596F 红 #E45649
|
|
// 数字 橙 #D19A66 橙 #986801
|
|
// 字符串 绿 #89CA78 绿 #50A14F
|
|
// 注释 灰 #7F848E 灰 #A0A1A7
|
|
//
|
|
// 浅色用的就是 Atom One Light——它是 One Dark 的官方同源浅色,
|
|
// 语义逐项对应,不是把深色配色硬调亮度(那样紫和青在浅底上会糊成一片)。
|
|
var (
|
|
darkCode = oneDarkVivid()
|
|
lightCode = oneLight()
|
|
)
|
|
|
|
// codeTheme 返回当前明暗下的语法配色。
|
|
func codeTheme(light bool) *editor.Theme {
|
|
if light {
|
|
return lightCode
|
|
}
|
|
return darkCode
|
|
}
|
|
|
|
func oneDarkVivid() *editor.Theme {
|
|
ct := &editor.Theme{
|
|
// 透明:编辑器不再自己铺底色,露出下面卡片带圆角的表面。
|
|
// 直接铺满会把卡片四角盖成直角,视觉上和别的浮岛不一致。
|
|
Background: ui.Hex(darkPalette.island).Alpha(0),
|
|
Text: ui.Hex(darkPalette.text),
|
|
|
|
LineNumber: ui.Hex("#4B5263"),
|
|
ActiveLineNumber: ui.Hex("#ABB2BF"),
|
|
ActiveLine: ui.RGBA(255, 255, 255, 0.045),
|
|
|
|
Selection: ui.RGBA(97, 175, 239, 0.26),
|
|
InactiveSelection: ui.RGBA(97, 175, 239, 0.15),
|
|
Cursor: ui.Hex("#528BFF"),
|
|
|
|
MatchingBracket: ui.RGBA(97, 175, 239, 0.55),
|
|
Match: ui.RGBA(229, 192, 123, 0.26),
|
|
CurrentMatch: ui.RGBA(229, 192, 123, 0.55),
|
|
Occurrence: ui.RGBA(97, 175, 239, 0.13),
|
|
|
|
IndentGuide: ui.RGBA(255, 255, 255, 0.08),
|
|
ActiveIndentGuide: ui.RGBA(255, 255, 255, 0.20),
|
|
WrapGuide: ui.RGBA(255, 255, 255, 0.07),
|
|
Whitespace: ui.RGBA(255, 255, 255, 0.14),
|
|
|
|
Error: ui.Hex("#EF596F"),
|
|
Warning: ui.Hex("#E5C07B"),
|
|
Info: ui.Hex("#61AFEF"),
|
|
Hint: ui.Hex("#7F848E"),
|
|
|
|
Added: ui.Hex("#89CA78"),
|
|
Deleted: ui.Hex("#EF596F"),
|
|
Modified: ui.Hex("#61AFEF"),
|
|
}
|
|
|
|
tok := func(k editor.TokenKind, hex string) { ct.Tokens[k].Color = ui.Hex(hex) }
|
|
|
|
tok(editor.TokenKeyword, "#D55FDE")
|
|
tok(editor.TokenOperator, "#2BBAC5")
|
|
tok(editor.TokenPunctuation, "#ABB2BF")
|
|
tok(editor.TokenType, "#E5C07B")
|
|
tok(editor.TokenFunction, "#61AFEF")
|
|
tok(editor.TokenVariable, "#EF596F")
|
|
tok(editor.TokenProperty, "#EF596F")
|
|
tok(editor.TokenConstant, "#D19A66")
|
|
tok(editor.TokenNumber, "#D19A66")
|
|
tok(editor.TokenString, "#89CA78")
|
|
tok(editor.TokenEscape, "#2BBAC5")
|
|
tok(editor.TokenRegexp, "#89CA78")
|
|
tok(editor.TokenComment, "#7F848E")
|
|
tok(editor.TokenMeta, "#D55FDE")
|
|
tok(editor.TokenTag, "#EF596F")
|
|
tok(editor.TokenAttribute, "#D19A66")
|
|
tok(editor.TokenHeading, "#EF596F")
|
|
tok(editor.TokenLink, "#61AFEF")
|
|
tok(editor.TokenCode, "#89CA78")
|
|
tok(editor.TokenInserted, "#89CA78")
|
|
tok(editor.TokenDeleted, "#EF596F")
|
|
tok(editor.TokenInvalid, "#EF596F")
|
|
|
|
// 注释不设斜体:中文没有真正的斜体字形,伪斜体渲染出来整段歪扭。
|
|
ct.Tokens[editor.TokenHeading].Bold = true
|
|
ct.Tokens[editor.TokenStrong].Bold = true
|
|
ct.Tokens[editor.TokenEmphasis].Italic = true
|
|
|
|
return ct
|
|
}
|
|
|
|
func oneLight() *editor.Theme {
|
|
ct := &editor.Theme{
|
|
Background: ui.Hex(lightPalette.island).Alpha(0),
|
|
Text: ui.Hex("#383A42"),
|
|
|
|
LineNumber: ui.Hex("#9D9D9F"),
|
|
ActiveLineNumber: ui.Hex("#383A42"),
|
|
ActiveLine: ui.RGBA(0, 0, 0, 0.04),
|
|
|
|
Selection: ui.RGBA(9, 105, 218, 0.16),
|
|
InactiveSelection: ui.RGBA(9, 105, 218, 0.09),
|
|
Cursor: ui.Hex("#526FFF"),
|
|
|
|
MatchingBracket: ui.RGBA(9, 105, 218, 0.45),
|
|
Match: ui.RGBA(193, 132, 1, 0.22),
|
|
CurrentMatch: ui.RGBA(193, 132, 1, 0.45),
|
|
Occurrence: ui.RGBA(9, 105, 218, 0.10),
|
|
|
|
IndentGuide: ui.RGBA(0, 0, 0, 0.08),
|
|
ActiveIndentGuide: ui.RGBA(0, 0, 0, 0.18),
|
|
WrapGuide: ui.RGBA(0, 0, 0, 0.06),
|
|
Whitespace: ui.RGBA(0, 0, 0, 0.12),
|
|
|
|
Error: ui.Hex("#E45649"),
|
|
Warning: ui.Hex("#C18401"),
|
|
Info: ui.Hex("#4078F2"),
|
|
Hint: ui.Hex("#A0A1A7"),
|
|
|
|
Added: ui.Hex("#50A14F"),
|
|
Deleted: ui.Hex("#E45649"),
|
|
Modified: ui.Hex("#4078F2"),
|
|
}
|
|
|
|
tok := func(k editor.TokenKind, hex string) { ct.Tokens[k].Color = ui.Hex(hex) }
|
|
|
|
tok(editor.TokenKeyword, "#A626A4")
|
|
tok(editor.TokenOperator, "#0184BC")
|
|
tok(editor.TokenPunctuation, "#383A42")
|
|
tok(editor.TokenType, "#C18401")
|
|
tok(editor.TokenFunction, "#4078F2")
|
|
tok(editor.TokenVariable, "#E45649")
|
|
tok(editor.TokenProperty, "#E45649")
|
|
tok(editor.TokenConstant, "#986801")
|
|
tok(editor.TokenNumber, "#986801")
|
|
tok(editor.TokenString, "#50A14F")
|
|
tok(editor.TokenEscape, "#0184BC")
|
|
tok(editor.TokenRegexp, "#50A14F")
|
|
tok(editor.TokenComment, "#A0A1A7")
|
|
tok(editor.TokenMeta, "#A626A4")
|
|
tok(editor.TokenTag, "#E45649")
|
|
tok(editor.TokenAttribute, "#986801")
|
|
tok(editor.TokenHeading, "#E45649")
|
|
tok(editor.TokenLink, "#4078F2")
|
|
tok(editor.TokenCode, "#50A14F")
|
|
tok(editor.TokenInserted, "#50A14F")
|
|
tok(editor.TokenDeleted, "#E45649")
|
|
tok(editor.TokenInvalid, "#E45649")
|
|
|
|
ct.Tokens[editor.TokenHeading].Bold = true
|
|
ct.Tokens[editor.TokenStrong].Bold = true
|
|
ct.Tokens[editor.TokenEmphasis].Italic = true
|
|
|
|
return ct
|
|
}
|