termstr: Coding style
- Add rgb color properties to char styles.
This commit is contained in:
parent
21a9ec2826
commit
960cc57559
2 changed files with 13 additions and 11 deletions
|
|
@ -147,14 +147,20 @@ class CharStyle:
|
|||
return "".join([ESC, NORMAL, fg_termcode, bg_termcode, bold_code,
|
||||
italic_code, underline_code])
|
||||
|
||||
@functools.cached_property
|
||||
def fg_rgb_color(self):
|
||||
return self.fg_color if type(self.fg_color) == tuple else XTERM_COLORS[self.fg_color]
|
||||
|
||||
@functools.cached_property
|
||||
def bg_rgb_color(self):
|
||||
return self.bg_color if type(self.bg_color) == tuple else XTERM_COLORS[self.bg_color]
|
||||
|
||||
def as_html(self):
|
||||
bold_code = "font-weight:bold; " if self.is_bold else ""
|
||||
italic_code = "font-style:italic; " if self.is_italic else ""
|
||||
underline_code = "text-decoration:underline; " if self.is_underlined else ""
|
||||
fg_color = self.fg_color if type(self.fg_color) == tuple else XTERM_COLORS[self.fg_color]
|
||||
bg_color = self.bg_color if type(self.bg_color) == tuple else XTERM_COLORS[self.bg_color]
|
||||
return (f"<style>.S{id(self)} {{font-size:80%%; color:rgb{fg_color!r};"
|
||||
f" background-color:rgb{bg_color!r}; "
|
||||
return (f"<style>.S{id(self)} {{font-size:80%%; color:rgb{self.fg_rgb_color!r};"
|
||||
f" background-color:rgb{self.bg_rgb_color!r}; "
|
||||
f"{bold_code}{italic_code}{underline_code}}}</style>")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue