diff --git a/openbb_terminal/core/models/preferences_model.py b/openbb_terminal/core/models/preferences_model.py index c0869dde193..d5364e311f6 100644 --- a/openbb_terminal/core/models/preferences_model.py +++ b/openbb_terminal/core/models/preferences_model.py @@ -84,7 +84,8 @@ class PreferencesModel(BaseModel): MPL_STYLE: str = "dark" PMF_STYLE: str = "dark" RICH_STYLE: str = "dark" - THEME: Literal["dark", "light"] = "dark" + CHART_STYLE: Literal["dark", "light"] = "dark" + TABLE_STYLE: Literal["dark", "light"] = "dark" # PATHS GUESS_EASTER_EGG_FILE: str = os.getcwd() + os.path.sep + "guess_game.json" diff --git a/openbb_terminal/core/plots/plotly_helper.py b/openbb_terminal/core/plots/plotly_helper.py index 0fdaa11eb6f..f0dbbaafd00 100644 --- a/openbb_terminal/core/plots/plotly_helper.py +++ b/openbb_terminal/core/plots/plotly_helper.py @@ -109,7 +109,7 @@ class TerminalStyle: def apply_style(self, style: Optional[str] = "") -> None: """Apply the style to the libraries.""" if not style: - style = get_current_user().preferences.THEME + style = get_current_user().preferences.CHART_STYLE if style != self.plt_style: self.load_style(style) @@ -244,7 +244,8 @@ class TerminalStyle: theme = TerminalStyle( - get_current_user().preferences.THEME, get_current_user().preferences.RICH_STYLE + get_current_user().preferences.CHART_STYLE, + get_current_user().preferences.RICH_STYLE, ) theme.apply_style() diff --git a/openbb_terminal/core/session/local_model.py b/openbb_terminal/core/session/local_model.py index 8a497560791..98382e7211e 100644 --- a/openbb_terminal/core/session/local_model.py +++ b/openbb_terminal/core/session/local_model.py @@ -108,11 +108,13 @@ def apply_configs(configs: dict): configs : dict The configurations. """ - # Saving the RICH_STYLE state allows user to change from hub rich style to local + # Saving the RICH_STYLE state allows user to change the default from 'hub' style to + # some custom .richstyle.json file set_credentials_from_hub(configs) set_preferences_from_hub(configs, fields=["RICH_STYLE"]) set_rich_style_from_hub(configs) - set_chart_table_style_from_hub(configs) + set_chart_style_from_hub(configs) + set_table_style_from_hub(configs) set_sources_from_hub(configs) @@ -182,8 +184,8 @@ def set_rich_style_from_hub(configs: dict): console.print("[red]Failed to set rich style.[/red]") -def set_chart_table_style_from_hub(configs: dict): - """Set chart and table style from hub. +def set_chart_style_from_hub(configs: dict): + """Set chart style from hub. Parameters ---------- @@ -193,9 +195,25 @@ def set_chart_table_style_from_hub(configs: dict): if configs: terminal_style = configs.get("features_terminal_style", {}) or {} if terminal_style: - chart_table = terminal_style.get("chart_table", None) - if chart_table: - set_preference("THEME", chart_table) + chart_style = terminal_style.get("chart", None) + if chart_style: + set_preference("CHART_STYLE", chart_style) + + +def set_table_style_from_hub(configs: dict): + """Set table style from hub. + + Parameters + ---------- + configs : dict + The configurations. + """ + if configs: + terminal_style = configs.get("features_terminal_style", {}) or {} + if terminal_style: + table_style = terminal_style.get("table", None) + if table_style: + set_preference("TABLE_STYLE", table_style) def set_sources_from_hub(configs: dict): diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index 26c3676a48a..b7304f0cd62 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -352,14 +352,11 @@ def print_rich_table( if col == "": df_outgoing = df_outgoing.rename(columns={col: " "}) - theme = current_user.preferences.THEME - table_theme = "white" if theme == "light" else theme - plots_backend().send_table( df_table=df_outgoing, title=title, source=source, # type: ignore - theme=table_theme, + theme=current_user.preferences.TABLE_STYLE, ) return diff --git a/openbb_terminal/miscellaneous/i18n/en.yml b/openbb_terminal/miscellaneous/i18n/en.yml index a050d259167..8557e1889cd 100644 --- a/openbb_terminal/miscellaneous/i18n/en.yml +++ b/openbb_terminal/miscellaneous/i18n/en.yml @@ -69,8 +69,10 @@ en: settings/_cmds_: Change settings settings/colors: set your own terminal colors settings/_colors: Colors - settings/theme: set plots and tables theme - settings/_theme: Theme + settings/chart: set charts style + settings/_chart: Charts style + settings/table: set tables style + settings/_table: Tables style settings/autoscaling: plot autoscaling settings/dt: add or remove datetime from flair settings/flair: set the flair emoji to be used diff --git a/openbb_terminal/settings_controller.py b/openbb_terminal/settings_controller.py index 575124d68b7..4f35dd44550 100644 --- a/openbb_terminal/settings_controller.py +++ b/openbb_terminal/settings_controller.py @@ -51,13 +51,14 @@ class SettingsController(BaseController): """Settings Controller class""" CHOICES_COMMANDS: List[str] = [ + "chart", "colors", "dt", "flair", "height", "lang", + "table", "tbnews", - "theme", "tweetnews", "tz", "userdata", @@ -134,9 +135,13 @@ class SettingsController(BaseController): mt.add_raw("\n") mt.add_setting("dt", current_user.preferences.USE_DATETIME) mt.add_raw("\n") - mt.add_cmd("theme") + mt.add_cmd("chart") mt.add_raw("\n") - mt.add_param("_theme", current_user.preferences.THEME) + mt.add_param("_chart", current_user.preferences.CHART_STYLE) + mt.add_raw("\n") + mt.add_cmd("table") + mt.add_raw("\n") + mt.add_param("_table", current_user.preferences.TABLE_STYLE) mt.add_raw("\n") mt.add_cmd("colors") mt.add_raw("\n") @@ -266,13 +271,13 @@ class SettingsController(BaseController): console.print("Colors updated.") @log_start_end(log=logger) - def call_theme(self, other_args: List[str]): - """Process theme command""" + def call_chart(self, other_args: List[str]): + """Process chart command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="theme", - description="Choose theme style.", + description="Choose chart style.", ) parser.add_argument( "-s", @@ -280,7 +285,7 @@ class SettingsController(BaseController): type=str, dest="style", choices=["dark", "light"], - help="Choose theme style. If you have a hub account you can change theme " + help="Choose chart style. If you have a hub account you can change theme " f"here {CHARTS_TABLES_URL}.", required="-h" not in other_args and "--help" not in other_args, ) @@ -289,17 +294,53 @@ class SettingsController(BaseController): ns_parser = self.parse_simple_args(parser, other_args) if ns_parser and ns_parser.style: if is_local(): - self.set_and_save_preference("THEME", ns_parser.style) + self.set_and_save_preference("CHART_STYLE", ns_parser.style) else: - set_preference("THEME", ns_parser.style) + set_preference("CHART_STYLE", ns_parser.style) Hub.upload_config( - key="chart_table", + key="chart", value=ns_parser.style, type_="terminal_style", auth_header=get_current_user().profile.get_auth_header(), ) console.print("") - console.print("Theme updated.\n") + console.print("Chart theme updated.\n") + + @log_start_end(log=logger) + def call_table(self, other_args: List[str]): + """Process theme command""" + parser = argparse.ArgumentParser( + add_help=False, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + prog="theme", + description="Choose table style.", + ) + parser.add_argument( + "-s", + "--style", + type=str, + dest="style", + choices=["dark", "light"], + help="Choose table style. If you have a hub account you can change theme " + f"here {CHARTS_TABLES_URL}.", + required="-h" not in other_args and "--help" not in other_args, + ) + if other_args and "-" not in other_args[0][0]: + other_args.insert(0, "-s") + ns_parser = self.parse_simple_args(parser, other_args) + if ns_parser and ns_parser.style: + if is_local(): + self.set_and_save_preference("TABLE_STYLE", ns_parser.style) + else: + set_preference("TABLE_STYLE", ns_parser.style) + Hub.upload_config( + key="table", + value=ns_parser.style, + type_="terminal_style", + auth_header=get_current_user().profile.get_auth_header(), + ) + console.print("") + console.print("Table theme updated.\n") @log_start_end(log=logger) def call_source(self, other_args: List[str]):