diff --git a/cli/openbb_cli/assets/i18n/en.yml b/cli/openbb_cli/assets/i18n/en.yml index 45508b1b6cb..e74a73acb45 100644 --- a/cli/openbb_cli/assets/i18n/en.yml +++ b/cli/openbb_cli/assets/i18n/en.yml @@ -36,3 +36,4 @@ en: settings/n_cols: number of columns to show on non interactive tables settings/obbject_msg: show obbject registry message after a new result is added settings/obbject_res: define the maximum number of obbjects allowed in the registry + settings/obbject_display: define the maximum number of cached results to display on the help menu \ No newline at end of file diff --git a/cli/openbb_cli/controllers/base_platform_controller.py b/cli/openbb_cli/controllers/base_platform_controller.py index 3b793f83fee..58985fc5772 100644 --- a/cli/openbb_cli/controllers/base_platform_controller.py +++ b/cli/openbb_cli/controllers/base_platform_controller.py @@ -323,7 +323,9 @@ class PlatformController(BaseController): if session.obbject_registry.obbjects: mt.add_section("Cached Results:\n", leading_new_line=True) - for key, value in session.obbject_registry.all.items(): + for key, value in list(session.obbject_registry.all.items())[ + : session.settings.N_TO_DISPLAY_OBBJECT_REGISTRY + ]: mt.add_raw(f"\tOBB{key}: {value['command']}\n") session.console.print(text=mt.menu_text, menu=self.PATH) diff --git a/cli/openbb_cli/controllers/cli_controller.py b/cli/openbb_cli/controllers/cli_controller.py index ed96e1c9601..63f2f2b93d0 100644 --- a/cli/openbb_cli/controllers/cli_controller.py +++ b/cli/openbb_cli/controllers/cli_controller.py @@ -287,7 +287,9 @@ class CLIController(BaseController): mt.add_cmd("results") if session.obbject_registry.obbjects: mt.add_section("Cached Results:\n", leading_new_line=True) - for key, value in session.obbject_registry.all.items(): + for key, value in list(session.obbject_registry.all.items())[ + : session.settings.N_TO_DISPLAY_OBBJECT_REGISTRY + ]: mt.add_raw(f"\tOBB{key}: {value['command']}\n") session.console.print(text=mt.menu_text, menu="Home") diff --git a/cli/openbb_cli/controllers/settings_controller.py b/cli/openbb_cli/controllers/settings_controller.py index a042a042b46..9c04cdc6a3c 100644 --- a/cli/openbb_cli/controllers/settings_controller.py +++ b/cli/openbb_cli/controllers/settings_controller.py @@ -41,6 +41,7 @@ class SettingsController(BaseController): "n_cols", "obbject_msg", "obbject_res", + "obbject_display", ] PATH = "/settings/" CHOICES_GENERATION = True @@ -76,6 +77,7 @@ class SettingsController(BaseController): mt.add_cmd("n_rows") mt.add_cmd("n_cols") mt.add_cmd("obbject_res") + mt.add_cmd("obbject_display") session.console.print(text=mt.menu_text, menu="Settings") @@ -323,3 +325,30 @@ class SettingsController(BaseController): f"Current maximum allowed number of results to keep in the OBBject registry:" f" {session.settings.N_TO_KEEP_OBBJECT_REGISTRY}" ) + + def call_obbject_display(self, other_args: List[str]): + """Process obbject_display command.""" + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + prog="obbject_display", + description="Number of results to display from the OBBject Registry.", + add_help=False, + ) + parser.add_argument( + "-n", + "--number", + dest="number", + action="store", + required=False, + type=int, + ) + ns_parser = self.parse_simple_args(parser, other_args) + + if ns_parser and ns_parser.number: + session.settings.set_item("N_TO_DISPLAY_OBBJECT_REGISTRY", ns_parser.number) + + elif not other_args: + session.console.print( + f"Current number of results to display from the OBBject registry:" + f" {session.settings.N_TO_DISPLAY_OBBJECT_REGISTRY}" + ) diff --git a/cli/openbb_cli/models/settings.py b/cli/openbb_cli/models/settings.py index b4380eee1c0..7dbf30ba07d 100644 --- a/cli/openbb_cli/models/settings.py +++ b/cli/openbb_cli/models/settings.py @@ -37,6 +37,7 @@ class Settings(BaseModel): USE_LANGUAGE: str = "en" PREVIOUS_USE: bool = False N_TO_KEEP_OBBJECT_REGISTRY: int = 10 + N_TO_DISPLAY_OBBJECT_REGISTRY: int = 5 # STYLE RICH_STYLE: str = "dark"