feat(MessageBox): use a hashed color for summaries
This commit is contained in:
parent
1d440ac7c8
commit
7b80153d15
1 changed files with 22 additions and 7 deletions
|
|
@ -209,6 +209,19 @@ class Message:
|
||||||
|
|
||||||
self.last_color = f"{self.style(key)}"
|
self.last_color = f"{self.style(key)}"
|
||||||
|
|
||||||
|
def auto_fg(self, bg):
|
||||||
|
# Automated black or white foreground.
|
||||||
|
if Color.ansi_lightness(bg) >= 50:
|
||||||
|
return "black"
|
||||||
|
else:
|
||||||
|
return "white"
|
||||||
|
|
||||||
|
def hash_color(self, text, colors = None):
|
||||||
|
if not colors:
|
||||||
|
return hash(text) % 256
|
||||||
|
else:
|
||||||
|
return colors[hash(text) % len(colors)]
|
||||||
|
|
||||||
|
|
||||||
class MessageLine(Message):
|
class MessageLine(Message):
|
||||||
def print_on(self, console = None, end = ""):
|
def print_on(self, console = None, end = ""):
|
||||||
|
|
@ -248,15 +261,17 @@ class MessageBox(Message):
|
||||||
def print_on(self, console = None, end = ""):
|
def print_on(self, console = None, end = ""):
|
||||||
hdate = self.date.strftime("%Y-%m-%d %H:%M")
|
hdate = self.date.strftime("%Y-%m-%d %H:%M")
|
||||||
if console != None:
|
if console != None:
|
||||||
# Automated black or white foreground.
|
# summ_color = f"{self.auto_fg(FIXME)} on color({self.color[self.urgency]})"
|
||||||
if Color.ansi_lightness(self.color[self.urgency]) >= 50:
|
|
||||||
fg = "black"
|
|
||||||
else:
|
|
||||||
fg = "white"
|
|
||||||
summ_color = f"{fg} on color({self.color[self.urgency]})"
|
|
||||||
body_color = f"color({self.color['summary_'+self.urgency]})"
|
body_color = f"color({self.color['summary_'+self.urgency]})"
|
||||||
title = f"{self.icons[self.urgency]} ─[{summ_color}]{self.summary}[/]─ {self.app}"
|
|
||||||
|
bg = self.hash_color(self.summary)
|
||||||
|
sfg = f"{self.auto_fg(bg)} on color({bg})"
|
||||||
|
sfgi = f"color({bg})"
|
||||||
|
summ = f"─[{sfgi}][/][{sfg}]{self.summary}[/][{sfgi}][/]─"
|
||||||
|
|
||||||
|
title = f"{self.icons[self.urgency]} {summ} {self.app}"
|
||||||
# title = f"[{summ_color}]{self.summary}[/]─ {self.app}"
|
# title = f"[{summ_color}]{self.summary}[/]─ {self.app}"
|
||||||
|
|
||||||
box = rich.panel.Panel(
|
box = rich.panel.Panel(
|
||||||
f"[{body_color}]{self.body}[/]",
|
f"[{body_color}]{self.body}[/]",
|
||||||
title=title,
|
title=title,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue