Skip to content

Commit 12e9ce1

Browse files
committed
Fix calculation of inverse color after cf98ab5
1 parent 285aa97 commit 12e9ce1

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

bpython/curtsiesfrontend/parse.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import curtsies.termformatconstants
21
import re
32

43
from curtsies.formatstring import fmtstr, FmtStr
5-
from curtsies.termformatconstants import FG_COLORS, BG_COLORS
4+
from curtsies.termformatconstants import (
5+
FG_COLORS,
6+
BG_COLORS,
7+
colors as CURTSIES_COLORS,
8+
)
69
from functools import partial
710

811
from bpython.lazyre import LazyReCompile
912

1013

11-
COLORS = curtsies.termformatconstants.colors + ("default",)
14+
COLORS = CURTSIES_COLORS + ("default",)
1215
CNAMES = dict(zip("krgybmcwd", COLORS))
16+
# hack for finding the "inverse"
17+
INVERSE_COLORS = {
18+
CURTSIES_COLORS[idx]: CURTSIES_COLORS[
19+
(idx + (len(CURTSIES_COLORS) // 2)) % len(CURTSIES_COLORS)
20+
]
21+
for idx in range(len(CURTSIES_COLORS))
22+
}
23+
INVERSE_COLORS["default"] = INVERSE_COLORS[CURTSIES_COLORS[0]]
1324

1425

1526
def func_for_letter(l, default="k"):
@@ -57,9 +68,7 @@ def fs_from_match(d):
5768
if d["bg"]:
5869
if d["bg"] == "I":
5970
# hack for finding the "inverse"
60-
color = COLORS[
61-
(COLORS.index(color) + (len(COLORS) // 2)) % len(COLORS)
62-
]
71+
color = INVERSE_COLORS[color]
6372
else:
6473
color = CNAMES[d["bg"].lower()]
6574
if color != "default":

0 commit comments

Comments
 (0)