-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support disable rich console (#38)
feat: support disable rich console Signed-off-by: Keming <kemingyang@tensorchord.ai>
- Loading branch information
Showing
4 changed files
with
38 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import re | ||
|
||
from rich.console import Console | ||
|
||
from modelz.env import EnvConfig | ||
|
||
config = EnvConfig() | ||
|
||
|
||
class ModelzConsole: | ||
class Status: | ||
def __init__(self, msg) -> None: | ||
self.msg = msg | ||
|
||
def __enter__(self): | ||
print(self.msg) | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
pass | ||
|
||
def __init__(self) -> None: | ||
self._remove_style = re.compile(r"\[.*?\]") | ||
self.formatter = lambda msg: self._remove_style.sub("", msg) | ||
|
||
def status(self, msg: str): | ||
return self.Status(self.formatter(msg)) | ||
|
||
def print(self, msg: str): | ||
print(self.formatter(msg)) | ||
|
||
|
||
console = ModelzConsole() if config.disable_rich else Console() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters