Skip to content

Commit

Permalink
Add render_beautiful_msg method, remove sty package (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihweiLHBird committed May 12, 2021
1 parent 99f8411 commit d54ad9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 9 additions & 8 deletions sciunit/scores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import numpy as np
from quantities import Quantity
from sty import bg, fg

from sciunit.base import SciUnit, config, ipy, log
from sciunit.errors import InvalidScoreError
Expand Down Expand Up @@ -359,6 +358,14 @@ def __le__(self, other: Union["Score", float]) -> bool:
result = self.score <= other
return result

def render_beautiful_msg(self, color: tuple, bg_brightness: int, msg: str):
result = ""
result += f"\x1b[38;2;{color[0]};{color[1]};{color[2]}m"
result += f"\x1b[48;2;{bg_brightness};{bg_brightness};{bg_brightness}m"
result += msg
result += "\x1b[0m"
return result

def log(self, **kwargs):
if self.norm_score is not None:
level = 100 - math.floor(self.norm_score * 99)
Expand All @@ -372,13 +379,7 @@ def log(self, **kwargs):
msg = "Score: %s for %s on %s" % (self, self.model, self.test)
color = self.color()
bg_brightness = config.get("score_bg_brightness", 50)
msg = (
fg(*color)
+ bg(bg_brightness, bg_brightness, bg_brightness)
+ msg
+ bg.rs
+ fg.rs
)
msg = self.render_beautiful_msg(color, bg_brightness, msg)
score_logger.log(level, msg, **kwargs)

@property
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ install_requires =
nbformat
pandas>=0.18
quantities>=0.12.1
sty


[options.entry_points]
Expand Down

0 comments on commit d54ad9a

Please sign in to comment.