mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-26 11:12:50 +00:00
* quick econ fix * black * keys and feature flags * terminal name 👀 * some more replacements * some more replacements * edit pyproject * gst -> openbb * add example portfolios back to git * Update api from gst * sorry. skipping some tests * another round of names * another round of test edits * Missed some .gst refs and update timezone * water mark stuff * Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS * fix more GST to OpenBB Terminal * Logging : merge conflicts with main * Revert wrong files Co-authored-by: Andrew <andrew.kenreich@gmail.com> Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
"""Rich Module"""
|
|
__docformat__ = "numpy"
|
|
|
|
import os
|
|
from rich import panel
|
|
from rich.console import Console, Theme
|
|
from openbb_terminal import config_terminal as cfg
|
|
from openbb_terminal import feature_flags as obbff
|
|
|
|
|
|
# https://rich.readthedocs.io/en/stable/appendix/colors.html#appendix-colors
|
|
# https://rich.readthedocs.io/en/latest/highlighting.html#custom-highlighters
|
|
|
|
CUSTOM_THEME = Theme(cfg.theme.console_style)
|
|
|
|
RICH_TAGS = [
|
|
"[menu]",
|
|
"[/menu]",
|
|
"[cmds]",
|
|
"[/cmds]",
|
|
"[info]",
|
|
"[/info]",
|
|
"[param]",
|
|
"[/param]",
|
|
"[src]",
|
|
"[/src]",
|
|
"[help]",
|
|
"[/help]",
|
|
]
|
|
|
|
USE_COLOR = True
|
|
|
|
|
|
def no_panel(renderable, *args, **kwargs): # pylint: disable=unused-argument
|
|
return renderable
|
|
|
|
|
|
class ConsoleAndPanel:
|
|
"""Create a rich console to wrap the console print with a Panel"""
|
|
|
|
def __init__(self):
|
|
self.console = Console(theme=CUSTOM_THEME, highlight=False, soft_wrap=True)
|
|
|
|
def capture(self):
|
|
return self.console.capture()
|
|
|
|
@staticmethod
|
|
def filter_rich_tags(text):
|
|
for val in RICH_TAGS:
|
|
text = text.replace(val, "")
|
|
|
|
return text
|
|
|
|
def print(self, *args, **kwargs):
|
|
if kwargs and "text" in list(kwargs) and "menu" in list(kwargs):
|
|
if not os.getenv("TEST_MODE"):
|
|
if obbff.ENABLE_RICH_PANEL:
|
|
self.console.print(
|
|
panel.Panel(
|
|
kwargs["text"],
|
|
title=kwargs["menu"],
|
|
subtitle_align="right",
|
|
subtitle="OpenBB Terminal",
|
|
)
|
|
)
|
|
else:
|
|
self.console.print(kwargs["text"])
|
|
else:
|
|
print(self.filter_rich_tags(kwargs["text"]))
|
|
else:
|
|
if not os.getenv("TEST_MODE"):
|
|
self.console.print(*args, **kwargs)
|
|
else:
|
|
print(*args, **kwargs)
|
|
|
|
|
|
console = ConsoleAndPanel()
|