Skip to content

Commit 2e7438b

Browse files
committed
Customize phantom colors
1 parent fccc47e commit 2e7438b

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

cs_conn_socket_repl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def read_loop(self):
4747
self.send("(repl)\n")
4848
started = False
4949
for line in lines(self.socket):
50+
cs_common.debug('RCV {}', line)
5051
if started:
5152
msg = cs_parser.parse_as_dict(line)
5253
self.handle_msg(msg)

cs_eval.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,25 @@ def __init__(self, view, region, batch_id = None):
5151
def value_key(self):
5252
return f"{cs_common.ns}.eval-{self.id}"
5353

54-
def scope_color(self):
54+
def scope_color(self, scope = None):
5555
if not Eval.colors:
5656
default = self.view.style_for_scope("source")
57-
def try_scopes(*scopes):
57+
def try_scopes(*scopes, key = "foreground"):
5858
for scope in scopes:
5959
colors = self.view.style_for_scope(scope)
6060
if colors != default:
61-
return (scope, colors["foreground"])
61+
return (scope, colors.get(key))
6262
Eval.colors["pending"] = try_scopes("region.eval.pending", "region.bluish")
6363
Eval.colors["interrupt"] = try_scopes("region.eval.interrupt", "region.eval.pending", "region.bluish")
6464
Eval.colors["success"] = try_scopes("region.eval.success", "region.greenish")
6565
Eval.colors["exception"] = try_scopes("region.eval.exception", "region.redish")
6666
Eval.colors["lookup"] = try_scopes("region.eval.lookup", "region.eval.pending", "region.bluish")
67-
return Eval.colors[self.status]
67+
Eval.colors["phantom_success_fg"] = try_scopes("region.phantom.success")
68+
Eval.colors["phantom_success_bg"] = try_scopes("region.phantom.success", key = "background")
69+
Eval.colors["phantom_exception_fg"] = try_scopes("region.phantom.exception")
70+
Eval.colors["phantom_exception_bg"] = try_scopes("region.phantom.exception", key = "background")
71+
scope = scope or self.status
72+
return Eval.colors[scope]
6873

6974
def region(self):
7075
regions = self.view.get_regions(self.value_key())
@@ -109,19 +114,36 @@ def toggle_phantom(self, text, styles):
109114
point = self.view.line(region.end()).begin()
110115
self.phantom_id = self.view.add_phantom(self.value_key(), sublime.Region(point, point), body, sublime.LAYOUT_BLOCK)
111116

117+
def phantom_styles(self, scope):
118+
styles = []
119+
_, fg = self.scope_color(f"{scope}_fg")
120+
if fg:
121+
styles.append(f"color: {fg};")
122+
_, bg = self.scope_color(f"{scope}_bg")
123+
if bg:
124+
styles.append(f"background-color: {bg};")
125+
if styles:
126+
return " ".join(styles)
127+
112128
def toggle_pprint(self):
113129
node = cs_parser.parse(self.value)
114130
string = cs_printer.format(self.value, node, limit = cs_common.wrap_width(self.view))
115-
self.toggle_phantom(string, """
131+
styles = """
116132
.light body { background-color: hsl(100, 100%, 90%); }
117133
.dark body { background-color: hsl(100, 100%, 10%); }
118-
""")
134+
"""
135+
if phantom_styles := self.phantom_styles("phantom_success"):
136+
styles += f".light body, .dark body {{ {phantom_styles}; border: 4px solid #CC3333; }}"
137+
self.toggle_phantom(string, styles)
119138

120139
def toggle_trace(self):
121-
self.toggle_phantom(self.trace, """
140+
styles = """
122141
.light body { background-color: hsl(0, 100%, 90%); }
123142
.dark body { background-color: hsl(0, 100%, 10%); }
124-
""")
143+
"""
144+
if phantom_styles := self.phantom_styles("phantom_exception"):
145+
styles += f".light body, .dark body {{ {phantom_styles}; border: 4px solid #CC3333; }}"
146+
self.toggle_phantom(self.trace, styles)
125147

126148
def erase(self, interrupt = True):
127149
self.view.erase_regions(self.value_key())

test_repl/forms.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
2+
(/ 1 0)
3+
4+
15
; simple expr
26
(+ 1 2)
37
(+ 1 2)
48

9+
*warn-on-reflection*
10+
511
(str 1 '\newline 2)
612

713
"xxx\nyyy\"zzz\\aaa\t"

0 commit comments

Comments
 (0)