From 1fe786b79bb53d87e042c358ea64ab3e3da38587 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Thu, 16 Mar 2023 11:09:12 -0500 Subject: [PATCH] Hotfix/Interactive in `featflags` menu (#4500) * added `USE_INTERACTIVE_DF` to `featflags` menu, `console.print` changed value * Got things working --------- Co-authored-by: colin99d --- .../core/models/preferences_model.py | 2 +- .../core/session/preferences_handler.py | 3 +++ openbb_terminal/featflags_controller.py | 9 +++++++++ openbb_terminal/miscellaneous/i18n/en.yml | 1 + openbb_terminal/stocks/stocks_view.py | 18 +++++++++--------- .../test_call_sync[other_args0-False].txt | 1 + .../test_call_sync[other_args1-True].txt | 1 + .../test_call_sync[other_args2-True].txt | 1 + .../test_call_sync[other_args3-False].txt | 1 + 9 files changed, 27 insertions(+), 10 deletions(-) diff --git a/openbb_terminal/core/models/preferences_model.py b/openbb_terminal/core/models/preferences_model.py index 3635e82dbdf..bc3ef9c427f 100644 --- a/openbb_terminal/core/models/preferences_model.py +++ b/openbb_terminal/core/models/preferences_model.py @@ -40,7 +40,7 @@ class PreferencesModel: RETRY_WITH_LOAD: bool = False USE_TABULATE_DF: bool = True # Use interactive window to display dataframes with options to sort, filter, etc. - USE_INTERACTIVE_DF = True + USE_INTERACTIVE_DF: bool = True USE_CLEAR_AFTER_CMD: bool = False USE_COLOR: bool = True USE_DATETIME: bool = True diff --git a/openbb_terminal/core/session/preferences_handler.py b/openbb_terminal/core/session/preferences_handler.py index 67903b73d43..4e44e93a1c8 100644 --- a/openbb_terminal/core/session/preferences_handler.py +++ b/openbb_terminal/core/session/preferences_handler.py @@ -7,6 +7,7 @@ from typing import Union from dotenv import set_key # IMPORTS INTERNAL +from openbb_terminal.base_helpers import console from openbb_terminal.core.config.paths import SETTINGS_ENV_FILE from openbb_terminal.core.session.current_user import ( get_current_user, @@ -54,3 +55,5 @@ def set_preference( type_="settings", auth_header=current_user.profile.get_auth_header(), ) + + console.print(f"[yellow]{name}[/] [green]has been set to[/] {value}") diff --git a/openbb_terminal/featflags_controller.py b/openbb_terminal/featflags_controller.py index 53a8426808d..64975dc2b04 100644 --- a/openbb_terminal/featflags_controller.py +++ b/openbb_terminal/featflags_controller.py @@ -28,6 +28,7 @@ class FeatureFlagsController(BaseController): CHOICES_COMMANDS: List[str] = [ "retryload", "tab", + "interactive", "cls", "color", "ion", @@ -63,6 +64,7 @@ class FeatureFlagsController(BaseController): mt.add_raw("\n") mt.add_setting("retryload", current_user.preferences.RETRY_WITH_LOAD) mt.add_setting("tab", current_user.preferences.USE_TABULATE_DF) + mt.add_setting("interactive", current_user.preferences.USE_INTERACTIVE_DF) mt.add_setting("cls", current_user.preferences.USE_CLEAR_AFTER_CMD) mt.add_setting("color", current_user.preferences.USE_COLOR) mt.add_setting("promptkit", current_user.preferences.USE_PROMPT_TOOLKIT) @@ -104,6 +106,13 @@ class FeatureFlagsController(BaseController): "USE_TABULATE_DF", not get_current_user().preferences.USE_TABULATE_DF ) + @log_start_end(log=logger) + def call_interactive(self, _): + """Process interactive command""" + set_preference( + "USE_INTERACTIVE_DF", not get_current_user().preferences.USE_INTERACTIVE_DF + ) + @log_start_end(log=logger) def call_cls(self, _): """Process cls command""" diff --git a/openbb_terminal/miscellaneous/i18n/en.yml b/openbb_terminal/miscellaneous/i18n/en.yml index b0b6d1a308e..3e8cb39324a 100644 --- a/openbb_terminal/miscellaneous/i18n/en.yml +++ b/openbb_terminal/miscellaneous/i18n/en.yml @@ -47,6 +47,7 @@ en: featflags/_info_: Feature flags through environment variables featflags/retryload: retry misspelled commands with load first featflags/tab: use tabulate to print dataframes + featflags/interactive: open dataframes in interactive window featflags/cls: clear console after each command featflags/color: use coloring features featflags/promptkit: enable prompt toolkit (autocomplete and history) diff --git a/openbb_terminal/stocks/stocks_view.py b/openbb_terminal/stocks/stocks_view.py index 9719e320d88..5e0e4af3a1f 100644 --- a/openbb_terminal/stocks/stocks_view.py +++ b/openbb_terminal/stocks/stocks_view.py @@ -28,15 +28,15 @@ def display_quote(symbol: str, export: str = "", sheet_name: Optional[str] = Non quote = stocks_model.get_quote(symbol) if quote.empty: console.print("[red]Data not found[/red]\n") - else: - print_rich_table( - quote, - headers=["Value"], - title=f"{symbol.upper()} Quote", - index_name="Info", - show_index=True, - export=bool(export), - ) + return + print_rich_table( + quote, + headers=["Value"], + title=f"{symbol.upper()} Quote", + index_name="Info", + show_index=True, + export=bool(export), + ) export_data( export, diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt index 3992f63030e..f4adc09b114 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt @@ -1,2 +1,3 @@ +SYNC_ENABLED has been set to True [info]sync:[/info] OFF ['--on'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt index e2401bc93e0..9d0fb18be9e 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt @@ -1,2 +1,3 @@ +SYNC_ENABLED has been set to False [info]sync:[/info] ON ['--off'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt index 939d5a1cd39..d162b18b891 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt @@ -1,2 +1,3 @@ +SYNC_ENABLED has been set to True [info]sync:[/info] ON ['--on'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt index 72602083de8..67e38be2b14 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt @@ -1,2 +1,3 @@ +SYNC_ENABLED has been set to False [info]sync:[/info] OFF ['--off']