1- from functools import partial
1+ import curtsies . termformatconstants
22import re
33
4- from bpython .lazyre import LazyReCompile
5-
6- import curtsies .termformatconstants
7- from curtsies .termformatconstants import FG_COLORS , BG_COLORS
84from curtsies .formatstring import fmtstr , FmtStr
5+ from curtsies .termformatconstants import FG_COLORS , BG_COLORS
6+ from functools import partial
97
8+ from bpython .lazyre import LazyReCompile
109
11- colors = curtsies .termformatconstants .colors + ("default" , )
12- cnames = dict (zip ("krgybmcwd" , colors ))
10+
11+ COLORS = curtsies .termformatconstants .colors + ("default" ,)
12+ CNAMES = dict (zip ("krgybmcwd" , COLORS ))
1313
1414
1515def func_for_letter (l , default = "k" ):
@@ -18,13 +18,13 @@ def func_for_letter(l, default="k"):
1818 l = default
1919 elif l == "D" :
2020 l = default .upper ()
21- return partial (fmtstr , fg = cnames [l .lower ()], bold = l .isupper ())
21+ return partial (fmtstr , fg = CNAMES [l .lower ()], bold = l .isupper ())
2222
2323
2424def color_for_letter (l , default = "k" ):
2525 if l == "d" :
2626 l = default
27- return cnames [l .lower ()]
27+ return CNAMES [l .lower ()]
2828
2929
3030def parse (s ):
@@ -46,23 +46,22 @@ def parse(s):
4646def fs_from_match (d ):
4747 atts = {}
4848 if d ["fg" ]:
49-
5049 # this isn't according to spec as I understand it
5150 if d ["fg" ].isupper ():
5251 d ["bold" ] = True
5352 # TODO figure out why boldness isn't based on presence of \x02
5453
55- color = cnames [d ["fg" ].lower ()]
54+ color = CNAMES [d ["fg" ].lower ()]
5655 if color != "default" :
5756 atts ["fg" ] = FG_COLORS [color ]
5857 if d ["bg" ]:
5958 if d ["bg" ] == "I" :
6059 # hack for finding the "inverse"
61- color = colors [
62- (colors .index (color ) + (len (colors ) // 2 )) % len (colors )
60+ color = COLORS [
61+ (COLORS .index (color ) + (len (COLORS ) // 2 )) % len (COLORS )
6362 ]
6463 else :
65- color = cnames [d ["bg" ].lower ()]
64+ color = CNAMES [d ["bg" ].lower ()]
6665 if color != "default" :
6766 atts ["bg" ] = BG_COLORS [color ]
6867 if d ["bold" ]:
0 commit comments