11import re
2+ from functools import partial
3+ from typing import Any , Callable , Dict , Tuple
24
35from curtsies .formatstring import fmtstr , FmtStr
46from curtsies .termformatconstants import (
57 FG_COLORS ,
68 BG_COLORS ,
79 colors as CURTSIES_COLORS ,
810)
9- from functools import partial
1011
1112from ..config import COLOR_LETTERS
1213from ..lazyre import LazyReCompile
2425INVERSE_COLORS ["default" ] = INVERSE_COLORS [CURTSIES_COLORS [0 ]]
2526
2627
27- def func_for_letter (letter_color_code : str , default : str = "k" ):
28+ def func_for_letter (
29+ letter_color_code : str , default : str = "k"
30+ ) -> Callable [..., FmtStr ]:
2831 """Returns FmtStr constructor for a bpython-style color code"""
2932 if letter_color_code == "d" :
3033 letter_color_code = default
@@ -37,13 +40,13 @@ def func_for_letter(letter_color_code: str, default: str = "k"):
3740 )
3841
3942
40- def color_for_letter (letter_color_code : str , default : str = "k" ):
43+ def color_for_letter (letter_color_code : str , default : str = "k" ) -> str :
4144 if letter_color_code == "d" :
4245 letter_color_code = default
4346 return CNAMES [letter_color_code .lower ()]
4447
4548
46- def parse (s ) :
49+ def parse (s : str ) -> FmtStr :
4750 """Returns a FmtStr object from a bpython-formatted colored string"""
4851 rest = s
4952 stuff = []
@@ -59,7 +62,7 @@ def parse(s):
5962 )
6063
6164
62- def fs_from_match (d ) :
65+ def fs_from_match (d : Dict [ str , Any ]) -> FmtStr :
6366 atts = {}
6467 if d ["fg" ]:
6568 # this isn't according to spec as I understand it
@@ -97,7 +100,7 @@ def fs_from_match(d):
97100)
98101
99102
100- def peel_off_string (s ) :
103+ def peel_off_string (s : str ) -> Tuple [ Dict [ str , Any ], str ] :
101104 m = peel_off_string_re .match (s )
102105 assert m , repr (s )
103106 d = m .groupdict ()
0 commit comments