Skip to content

Commit e564d4d

Browse files
authored
[209_16] Fixes dark mode syntax highlighting for python (#2961)
1 parent 4b2faee commit e564d4d

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

TeXmacs/packages/themes/dark/dark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
<assign|pre-edit|<macro|body|<with|ornament-color|#707070|ornament-sunny-color|#808080|ornament-shadow-color|#606060|ornament-border|1px|ornament-hpadding|2px|ornament-vpadding|2px|<smash|<ornament|<with|color|white|<arg|body>>>>>>>
7676

77-
<assign|focus-color|#3A86FF>
77+
<assign|focus-color|#3A86FF33>
7878

7979
<assign|selection-color|#3A86FF33>
8080

TeXmacs/plugins/python/progs/code/python-lang.scm

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,20 @@
114114

115115
;; 定义语法高亮颜色偏好设置
116116
(define-preferences
117-
("syntax:python:none" "red" notify-python-syntax) ;; 无类型语法元素颜色
118-
("syntax:python:comment" "brown" notify-python-syntax) ;; 注释颜色
119-
("syntax:python:error" "dark red" notify-python-syntax) ;; 错误颜色
120-
("syntax:python:constant" "#4040c0" notify-python-syntax) ;; 常量颜色
121-
("syntax:python:constant_number" "#4040c0" notify-python-syntax) ;; 数字常量颜色
122-
("syntax:python:constant_string" "dark grey" notify-python-syntax) ;; 字符串常量颜色
123-
("syntax:python:constant_char" "#333333" notify-python-syntax) ;; 字符常量颜色
124-
("syntax:python:declare_function" "#0000c0" notify-python-syntax) ;; 函数声明颜色
125-
("syntax:python:declare_type" "#0000c0" notify-python-syntax) ;; 类型声明颜色
126-
("syntax:python:operator" "#8b008b" notify-python-syntax) ;; 运算符颜色
127-
("syntax:python:operator_openclose" "#B02020" notify-python-syntax) ;; 开闭运算符颜色
128-
("syntax:python:operator_field" "#88888" notify-python-syntax) ;; 字段运算符颜色
129-
("syntax:python:operator_special" "orange" notify-python-syntax) ;; 特殊运算符颜色
130-
("syntax:python:keyword" "#309090" notify-python-syntax) ;; 关键字颜色
131-
("syntax:python:keyword_conditional" "#309090" notify-python-syntax) ;; 条件关键字颜色
132-
("syntax:python:keyword_control" "#309090" notify-python-syntax)) ;; 控制关键字颜色
117+
("syntax:python:none" "#ff6b6b" notify-python-syntax) ;; 浅红色 (light red)
118+
("syntax:python:comment" "#d4a373" notify-python-syntax) ;; 浅棕色 (light brown)
119+
("syntax:python:error" "#ff4d4d" notify-python-syntax) ;; 亮红色 (bright red)
120+
("syntax:python:constant" "#6a8cff" notify-python-syntax) ;; 浅蓝色 (light blue)
121+
("syntax:python:constant_number" "#6a8cff" notify-python-syntax) ;; 浅蓝色 (light blue)
122+
("syntax:python:constant_string" "#a9a9a9" notify-python-syntax) ;; 浅灰色 (light grey)
123+
("syntax:python:constant_char" "#b0b0b0" notify-python-syntax) ;; 浅灰色 (light grey)
124+
("syntax:python:declare_function" "#4d7eff" notify-python-syntax) ;; 浅蓝色 (light blue)
125+
("syntax:python:declare_type" "#4d7eff" notify-python-syntax) ;; 浅蓝色 (light blue)
126+
("syntax:python:declare_module" "#4d7eff" notify-python-syntax) ;; 浅蓝色 (light blue)
127+
("syntax:python:operator" "#e066ff" notify-python-syntax) ;; 浅洋红色 (light magenta)
128+
("syntax:python:operator_openclose" "#ff6666" notify-python-syntax) ;; 浅红色 (light red)
129+
("syntax:python:operator_field" "#d1d1d1" notify-python-syntax) ;; 浅灰色 (light grey)
130+
("syntax:python:operator_special" "#ffb347" notify-python-syntax) ;; 浅橙色 (light orange)
131+
("syntax:python:keyword" "#4db8b8" notify-python-syntax) ;; 浅青色 (light teal/cyan)
132+
("syntax:python:keyword_conditional" "#4db8b8" notify-python-syntax) ;; 浅青色 (light teal/cyan)
133+
("syntax:python:keyword_control" "#4db8b8" notify-python-syntax))

devel/209_16.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [209_16] Fix Python syntax highlighting and active line opacity in dark mode
2+
3+
### What
4+
1. Adjusted the syntax highlighting colors for the Python plugin (`python-lang.scm`) to use lighter color variants that are clearly legible on both light and dark backgrounds.
5+
2. Explicitly mapped the `syntax:python:declare_module` override to lighter blue (for `import` and `from`) since it previously fell back to the dark blue default.
6+
4. Modified opacity of `focus-color` in (`dark.ts`) from (`#3A86FF`) to (`#3A86FF33`) so that the active line marker no longer completely blocks text when a dark theme is active.
7+
8+
### Why
9+
With the dark theme enabled, several syntax colors mapped in the Python language definition were illegible or had contrast issues against the dark gray background. Furthermore, the active line of code feature generated an opaque background because its hexadecimal color was missing transparency, rendering the text on the active line invisible.
10+
11+
### How
12+
In `TeXmacs/plugins/python/progs/code/python-lang.scm`:
13+
- Updated `define-preferences` hex values and named color mappings to use bright, pastel versions of the original colors.
14+
15+
In `TeXmacs/packages/themes/dark/dark.ts`:
16+
- Replaced the opaque `focus-color` assignment with an 8-character hex code specifying ~20% opacity.
17+
18+
```diff
19+
- <assign|focus-color|##3A86FF>
20+
+ <assign|focus-color|##3A86FF33>
21+
```
22+
23+
## How to test
24+
1. Open Mogan and enable the dark GUI theme(`Document -> Theme -> Dark`).
25+
2. Start a Python session (`Insert -> Session -> Python`) or write Python code block.
26+
3. Verify that the new syntax highlighting is easily readable.
27+
4. Move the cursor across different lines to see that the active line highlight (`focus-color`) acts as a translucent overlay rather than an opaque block.
28+
5. Disable the dark theme and verify that the syntax highlighting colors still provide sufficient contrast on the default light background.

0 commit comments

Comments
 (0)