A deque, or double-ended queue, supports insertion and removal at both ends. A bounded deque is useful when an application must retain only its newest items. section 8.4.1
A deque solves practical buffering problems by:
- Keeping messages in display order while discarding older items automatically when its maximum size is reached. section 8.4.1
- Buffering user input one character at a time and removing the most recent character when Backspace is pressed. section 8.4.1
- Triggering a redraw after each appended message so the visible output stays synchronized with the buffer. section 8.4.1
A bounded message store
A MessageStore can wrap deque(maxlen=max_size). Each append adds a message and invokes a redraw callback. Once the deque is full, adding another message removes the oldest item, producing terminal scrolling without retaining the entire output history. section 8.4.1


