From b900c786ebce8d6729cf98554f200a92a7407044 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 17 May 2024 13:29:53 -0700 Subject: [PATCH] client: PR comments; replaced command history list with deque --- kvui.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kvui.py b/kvui.py index 3a09fe10206b..3c035990caca 100644 --- a/kvui.py +++ b/kvui.py @@ -3,6 +3,7 @@ import sys import typing import re +from collections import deque if sys.platform == "win32": import ctypes @@ -396,15 +397,12 @@ class CommandPromptTextInput(TextInput): def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self._command_history_index = -1 - self._command_history: typing.List[str] = [] + self._command_history: typing.Deque[str] = deque(maxlen=CommandPromptTextInput.MAXIMUM_HISTORY_MESSAGES) def update_history(self, new_entry: str) -> None: self._command_history_index = -1 if is_command_input(new_entry): - self._command_history = [ - new_entry, - *self._command_history[:CommandPromptTextInput.MAXIMUM_HISTORY_MESSAGES-1] - ] + self._command_history.appendleft(new_entry) def keyboard_on_key_down( self,