| 62 | |
| 63 | |
| 64 | def fs_from_match(d: dict[str, Any]) -> FmtStr: |
| 65 | atts = {} |
| 66 | color = "default" |
| 67 | if d["fg"]: |
| 68 | # this isn't according to spec as I understand it |
| 69 | if d["fg"].isupper(): |
| 70 | d["bold"] = True |
| 71 | # TODO figure out why boldness isn't based on presence of \x02 |
| 72 | |
| 73 | color = CNAMES[d["fg"].lower()] |
| 74 | if color != "default": |
| 75 | atts["fg"] = FG_COLORS[color] |
| 76 | if d["bg"]: |
| 77 | if d["bg"] == "I": |
| 78 | # hack for finding the "inverse" |
| 79 | color = INVERSE_COLORS[color] |
| 80 | else: |
| 81 | color = CNAMES[d["bg"].lower()] |
| 82 | if color != "default": |
| 83 | atts["bg"] = BG_COLORS[color] |
| 84 | if d["bold"]: |
| 85 | atts["bold"] = True |
| 86 | return fmtstr(d["string"], **atts) |
| 87 | |
| 88 | |
| 89 | peel_off_string_re = LazyReCompile( |