Skip to content

Histories

rafageist edited this page Dec 3, 2026 · 5 revisions

Histories

Use it for an input line that remembers what was typed in it
Import from turboframe.ui.history import HistoryInput; from turboframe.ui import history
Needs nothing beyond TurboFrame
Extend your own history_ids; offer= for values of your own; any store (load(), save(dict))

Turbo Vision's THistory: an input line remembers what was accepted in it. HistoryInput(line, history_id) (turboframe.ui.history) wraps an InputLine with a ▐↓▌ at its right. Down, or a click on it, opens the earlier entries, newest first. Type to filter them, Enter takes one, Esc closes.

The Find line's history

Each kind of line has its own history: history_id names it ("find", "replace", "file", "line"...). TurboFrame's dialogs use these ids; yours choose their own. A dialog adds what its lines hold to their histories when it ends with anything but Cancel; outside a dialog, call history_input.remember().

Where they live

Histories live in a store, under its "history" key: any object with load() -> dict and save(dict). Give it once, when your application starts:

from turboframe.config import JsonStore
from turboframe.ui import history

history.set_store(JsonStore("myapp"))   # or any object with load() and save()

Until then they live in memory (MemoryStore) for the session. Each history keeps its last 20 entries (MAX_ENTRIES). A store that cannot be written (a read-only or full disk: OSError) keeps nothing, and the dialog goes on (since v0.2.1; v0.2.0 raised the error).

entries(history_id) and add(history_id, text) read and write a history directly. The command palette keeps the commands run from it this way, under "commands" (see Command Palette).

In a dialog of your own, wrap each InputLine (see Dialogs):

from textual.app import ComposeResult
from textual_vision.input_line import InputLine
from textual_vision.label import Label

from turboframe.ui.dialogs import TVDialog
from turboframe.ui.history import HistoryInput


class TableDialog(TVDialog):
    def __init__(self) -> None:
        super().__init__(title="Open table")
        self.line = InputLine(max_len=80)

    def compose_content(self) -> ComposeResult:
        yield Label("~T~able", link=self.line)
        yield HistoryInput(self.line, "table-name")      # its own history
        ...                                              # the buttons

HistoryInput(self.line, "table-name", offer=list_tables) would offer what list_tables() returns instead.

HistoryInput(line, history_id, offer=callable) offers what the callable returns instead of the history, such as values from a file. What is offered is not remembered.

API: turboframe.ui.history.

A store for your settings

turboframe.config.JsonStore("myapp") is ~/.config/myapp/config.json (%APPDATA% on Windows), and the store every component takes: history.set_store(store), DesktopApp.colors_store = store, DiffView.store = store. It is described, with the keys each component keeps and the recent files, in Settings and Recent Files.

API: turboframe.config.

Clone this wiki locally