clabe.ui ¶
How clabe talks to the user: requests that describe and validate themselves, a session API to ask them
(ui.ask, ui.confirm, ui.group, ...), and clients (console, TUI) that render and collect answers.
Client ¶
Bases: Protocol
A user interface that renders messages and collects raw answers (it never validates).
ask ¶
Shows request and blocks until the user answers; returns the raw answer.
Raises:
| Type | Description |
|---|---|
PromptCancelledError
|
|
cancel ¶
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
ClientSession ¶
ClientSession(client: Client)
Uses a Client as the Session outside a run.
Resolves FieldRequest s, validates answers with the request's own rules and asks again
(showing the reason) until an answer is accepted, as a run does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
The client that asks and renders. |
required |
Source code in src/clabe/ui/_client.py
ask ¶
Asks request until it gets a valid answer and returns that answer, validated and coerced.
Raises:
| Type | Description |
|---|---|
PromptCancelledError
|
The client's prompt was cancelled. |
Source code in src/clabe/ui/_client.py
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
Shows message on the client (and records it in the log file, at debug level).
HeadlessClient ¶
A client with no screen: prompts wait until answered elsewhere (e.g. the web UI), messages go to the log.
For runs started without a terminal (by the daemon, a scheduler or a service) and served over HTTP.
Source code in src/clabe/ui/_client.py
ConsoleClient ¶
A Client using rich for styled, line-based prompts.
Renders messages and prompts with colour and structure on an interactive terminal while degrading gracefully:
rich strips styling automatically and falls back to plain input when output is not a terminal (e.g. piped to
a file or running in CI), so this also serves as the non-interactive fallback.
Like every client it never validates: ask returns the raw answer and whoever drives the client (a run,
or a ClientSession) validates it and asks again if needed.
On an interactive terminal every prompt reads the keyboard key by key, so cancel can abort it from
another thread. When stdin or stdout is not a terminal, prompts fall back to input() and cannot be cancelled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console | None
|
The rich console to render on. Defaults to the shared |
None
|
Source code in src/clabe/ui/_console.py
ask ¶
Shows request and returns the raw answer.
Raises:
| Type | Description |
|---|---|
PromptCancelledError
|
|
ValueError
|
|
Source code in src/clabe/ui/_console.py
cancel ¶
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
Prints a message with level-appropriate styling.
MessageLevel ¶
Bases: Enum
Severity/intent of a message surfaced to the user by a frontend.
This is intentionally separate from logging levels: it describes how
a message should be presented to the user, not how it should be recorded.
The frontend maps each level to an appropriate logging level when writing
the message to the persistent transcript.
AcknowledgeRequest
dataclass
¶
AcknowledgeRequest(
message: str,
title: str = "Notice",
button_label: str = "OK",
field: str | None = None,
)
Bases: Request
A declarative acknowledgement gate.
Displays a message (optionally with a title) in a modal overlay and blocks until the user dismisses it. No answer is collected — the sole purpose is to ensure the user has read the message before execution continues.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
The body text the user must read before continuing. |
title |
str
|
Optional bold heading shown above the message. |
button_label |
str
|
Label on the dismiss button. Defaults to |
field |
str | None
|
Logical field name used in the persisted transcript. |
AnswerRejected ¶
Bases: ValueError
An answer does not satisfy its request; the message is shown to whoever answered.
AutoCompleteRequest
dataclass
¶
AutoCompleteRequest(
label: str,
options: Sequence[str] | OptionsFunction,
default: str | None = None,
strict: bool = False,
validators: list[Validator] = list(),
field: str | None = None,
help: str | None = None,
)
Bases: Request
A declarative request for text with autocompletion against a list.
As the user types, frontends narrow the offered options; the user may keep
typing a free-form value to the end, or pick a suggestion with the arrow
keys. Unlike PickRequest, the answer is not constrained to the
provided options unless strict is set.
options may be a function of the text typed so far returning the options (e.g. a database search): clients
call it as the user types (the run server through GET /api/prompts/{id}/options?q=) and its spec says
dynamic_options: true, with options holding its result for "".
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The prompt shown to the user. |
options |
Sequence[str] | OptionsFunction
|
The suggestions to complete against, or a function |
default |
str | None
|
Value returned when the user submits an empty answer. |
strict |
bool
|
When set, only a value present in |
validators |
list[Validator]
|
Validators applied to the answer; the frontend re-prompts and surfaces the returned error until they all pass. |
field |
str | None
|
Logical field name used in the persisted transcript. |
help |
str | None
|
Optional supplementary help text. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
suggestions ¶
The options as strings: a function's result for typed; a list as it is (clients filter it).
Raises:
| Type | Description |
|---|---|
Exception
|
Whatever the options function raised. |
Source code in src/clabe/ui/_requests.py
answer_schema ¶
A string; one of the suggestions when the request is strict (and its options are a list).
Source code in src/clabe/ui/_requests.py
accepts ¶
Whether value is one of the options (for a function: one it returns for value).
Source code in src/clabe/ui/_requests.py
validate_answer ¶
Like a text answer, but a strict request only accepts one of its suggestions (checked first).
Source code in src/clabe/ui/_requests.py
Choice
dataclass
¶
ConfirmRequest
dataclass
¶
Bases: Request
A declarative yes/no question.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The question shown to the user. |
default |
bool
|
The value used when the user accepts the default. |
field |
str | None
|
Logical field name used in the persisted transcript. |
FieldRequest
dataclass
¶
Bases: Request
A declarative request to enter a single field from a Pydantic model.
The asker resolves it (resolve) into the most appropriate primitive
request from the field's type annotation: strict autocomplete for
Literal / Enum fields, yes/no for bool, a path for Path and
a validated text prompt for everything else. Clients never see it.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
type
|
The Pydantic model class that owns the field. |
field_name |
str
|
The name of the field to prompt for. |
initial |
object | None
|
Optional value to use as the pre-filled default (overrides the field's declared default). |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
The field's JSON Schema; {} (anything) when pydantic cannot describe it.
Source code in src/clabe/ui/_requests.py
validate_answer ¶
Validates a field value answered directly (as answer_schema describes it).
An empty answer falls back to the default, else None if the field is optional. Askers do not open field
prompts: they ask the request resolve returns, whose answers are validated by that request.
Source code in src/clabe/ui/_requests.py
resolve ¶
Returns the primitive request to ask for this field, and how to turn its answer into the field value.
Routing rules:
bool→ yes/no confirm.Literal[...]→ strict autocomplete on the literal values (as text); converts back to the literal.Enum→ strict autocomplete on the member names; converts to the member.Path→ any path, which need not exist (a plainPathfield does not imply it does).- Anything else → text validated by the field's type and constraints; converts to the typed value. An
empty answer (or the default's text) gives the default value itself, else
Nonefor an optional field.
Returns:
| Type | Description |
|---|---|
tuple[Request, Callable[[Any], Any]]
|
The primitive request, and a function mapping its validated answer to the typed field value. |
Source code in src/clabe/ui/_requests.py
FormRequest
dataclass
¶
FormRequest(
model: type,
title: str | None = None,
initial: object | None = None,
field: str | None = None,
)
Bases: Request
A declarative request to fill in a Pydantic model as a form.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
type
|
The Pydantic model class to render. |
title |
str | None
|
Optional title override. Defaults to the humanized class name. |
initial |
object | None
|
Optional pre-populated model instance to seed field defaults. |
field |
str | None
|
Logical field name used in the persisted transcript. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
The model's JSON Schema, or null (cancelled); {} (anything) when pydantic cannot describe it.
Source code in src/clabe/ui/_requests.py
validate_answer ¶
Accepts None (cancelled), a model instance, or data that validates as the model.
Source code in src/clabe/ui/_requests.py
GroupRequest
dataclass
¶
Bases: Request
Several prompts asked together as one: e.g. a text input and a slider shown side by side.
The run opens a single prompt; the answer maps each item name to its validated value. Items may be text, number, confirm, pick, autocomplete, path and field requests (not groups, forms, tables or acknowledgements).
Example
Attributes:
| Name | Type | Description |
|---|---|---|
items |
Mapping[str, Request]
|
The prompts, by name (each name must be a Python identifier). |
title |
str | None
|
Optional title shown above the group. |
field |
str | None
|
Logical field name used in the persisted transcript. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
model ¶
model() -> type[BaseModel]
The pydantic model the group compiles to (one field per item); clients render it as a form.
Source code in src/clabe/ui/_requests.py
answer_schema ¶
The compiled model's JSON Schema; {} (anything) when pydantic cannot describe it.
Source code in src/clabe/ui/_requests.py
validate_answer ¶
Accepts a mapping (or an instance of the compiled model) and returns each item's typed value.
Source code in src/clabe/ui/_requests.py
MarkdownRequest
dataclass
¶
MarkdownRequest(
markdown: str,
title: str | None = None,
button_label: str = "Continue",
field: str | None = None,
)
Bases: Request
Shows a Markdown document and blocks until the user continues (no answer is collected).
The web UI and the TUI render the Markdown; the console prints it with Rich. Raw HTML in the document is not
rendered (use MediaRequest with media="html" for HTML).
Attributes:
| Name | Type | Description |
|---|---|---|
markdown |
str
|
The document (CommonMark, plus tables and strikethrough). |
title |
str | None
|
Optional heading shown above it. |
button_label |
str
|
Label of the button that continues. |
field |
str | None
|
Logical field name used in the persisted transcript. |
MediaRequest
dataclass
¶
MediaRequest(
source: str | Path,
media: MediaKind = "image",
title: str | None = None,
caption: str | None = None,
button_label: str = "Continue",
field: str | None = None,
)
Bases: Request
Shows an image, an HTML page or a web page, and blocks until the user continues (no answer is collected).
The web UI shows all three: local files are served by the run server (only the file of this prompt), URLs are loaded by the browser and inline HTML is shown in a sandboxed frame. Clients that cannot show the media (the console, the TUI) log a warning naming the file or URL instead, and still wait for the user to continue.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str | Path
|
A local file (image or HTML page), an |
media |
MediaKind
|
|
title |
str | None
|
Optional heading shown above it. |
caption |
str | None
|
Optional text shown below it. |
button_label |
str
|
Label of the button that continues. |
field |
str | None
|
Logical field name used in the persisted transcript. |
location
property
¶
location: Literal['url', 'file', 'inline']
Where the media is: a URL, a local file, or (HTML only) the source itself.
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
local_file ¶
local_file() -> Path | None
The local file to show, when the media is one and it exists.
NumberRequest
dataclass
¶
NumberRequest(
label: str,
default: float | None = None,
field: str | None = None,
minimum: float | None = None,
maximum: float | None = None,
step: float | None = None,
widget: Literal["input", "slider"] = "input",
)
Bases: Request
A declarative request for a floating-point number, optionally bounded.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The prompt shown to the user. |
default |
float | None
|
Value returned when the user submits an empty answer. |
field |
str | None
|
Logical field name used in the persisted transcript. |
minimum |
float | None
|
Smallest accepted value (inclusive), if any. |
maximum |
float | None
|
Largest accepted value (inclusive), if any. |
step |
float | None
|
The value must be a multiple of |
widget |
Literal['input', 'slider']
|
Rendering hint: |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
A number, with its bounds, step and widget hint.
Source code in src/clabe/ui/_requests.py
validate_answer ¶
Accepts a number or numeric text within the bounds; an empty answer falls back to the default.
Source code in src/clabe/ui/_requests.py
PathRequest
dataclass
¶
PathRequest(
label: str,
start: str | PathLike | None = None,
default: str | None = None,
must_exist: bool = True,
kind: Literal["file", "dir", "any"] = "file",
extensions: Sequence[str] | None = None,
field: str | None = None,
help: str | None = None,
)
Bases: Request
A declarative request to choose a filesystem path.
Frontends render this as whatever browsing UI is appropriate (a live, filesystem-aware browser on a console; a modal file-browser dialog on a TUI/GUI). Application code only describes what it needs — a file or a directory, which extensions are acceptable, whether the target must already exist — never how to browse for it.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The prompt shown to the user. |
start |
str | PathLike | None
|
Directory (or partial path) to open the browser in. Defaults to the current working directory. |
default |
str | None
|
Value returned when the user submits an empty answer. |
must_exist |
bool
|
Whether the chosen path must already exist on disk. For
|
kind |
Literal['file', 'dir', 'any']
|
Restricts the selectable target: |
extensions |
Sequence[str] | None
|
When set, only files with one of these suffixes (e.g.
|
field |
str | None
|
Logical field name used in the persisted transcript. |
help |
str | None
|
Optional supplementary help text. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
normalized_extensions ¶
Returns extensions as lowercase, dot-prefixed suffixes, or None if unset.
See normalize_extensions — every frontend must compare against
this (or the free function directly) rather than re-deriving its own
normalized set, so a file offered by a picker is never subsequently
rejected by validation over a case or leading-dot mismatch.
Source code in src/clabe/ui/_requests.py
answer_schema ¶
validate_answer ¶
Accepts None (cancelled) or a path satisfying the request; an empty answer falls back to the default.
Source code in src/clabe/ui/_requests.py
PickRequest
dataclass
¶
PickRequest(
label: str,
options: Sequence[str | Choice],
default: str | None = None,
allow_none: bool = True,
none_label: str = "None",
field: str | None = None,
help: str | None = None,
)
Bases: Request
A declarative request to pick one option from a list.
Frontends render this however is appropriate (a numbered list on a console,
a dropdown/option-list in a TUI/GUI, a <select> on the web). Application
code only describes what it needs, never how to ask.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The prompt shown to the user. |
options |
Sequence[str | Choice]
|
The available options (plain strings or |
default |
str | None
|
Value selected by default when the frontend supports it. |
allow_none |
bool
|
Whether a "none" sentinel option is offered. |
none_label |
str
|
Label for the "none" option when |
field |
str | None
|
Logical field name used in the persisted transcript. |
help |
str | None
|
Optional supplementary help text. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
choices ¶
answer_schema ¶
One of the option values, or null when the request allows it.
validate_answer ¶
Accepts one of the option values, or None when the request allows it.
Source code in src/clabe/ui/_requests.py
ReadOnlyTable
dataclass
¶
ReadOnlyTable(
columns: Sequence[str],
rows: Sequence[Sequence[Any]],
title: str | None = None,
prompt: str | None = None,
confirm_label: str = "OK",
cancel_label: str = "Cancel",
field: str | None = None,
)
Bases: Request
A declarative request to display tabular data read-only and collect a yes/no.
The table is never editable; it exists to show the user a set of values and
gather a single confirmation. The affirmative button returns True and the
negative button returns False (as does dismissing the dialog).
Prefer the constructors over populating columns and rows by hand:
from_records— a sequence of mappings, one row each; columns are inferred from the keys (first-seen order) unless given explicitly.from_object— a Pydantic model instance or a plain mapping rendered as a two-columnParameter | Valuetable, one row per field/key.
Attributes:
| Name | Type | Description |
|---|---|---|
columns |
Sequence[str]
|
Column headers, left to right. |
rows |
Sequence[Sequence[Any]]
|
Row values; each inner sequence aligns positionally to |
title |
str | None
|
Optional title shown above the table. |
prompt |
str | None
|
Optional question shown near the buttons (e.g. "Is this correct?"). |
confirm_label |
str
|
Label on the affirmative button. Defaults to |
cancel_label |
str
|
Label on the negative button. Defaults to |
field |
str | None
|
Logical field name used in the persisted transcript. |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
validate_answer ¶
from_records
classmethod
¶
from_records(
records: Sequence[Mapping[str, Any]],
*,
columns: Sequence[str] | None = None,
**kwargs: Any,
) -> ReadOnlyTable
Build a table from a sequence of mappings (one row per mapping).
When columns is omitted it is inferred from the union of the record
keys, preserving first-seen order. Keys absent from a given record render
as empty cells.
Source code in src/clabe/ui/_requests.py
from_object
classmethod
¶
from_object(
obj: Mapping[str, Any] | BaseModel,
*,
key_header: str = "Parameter",
value_header: str = "Value",
**kwargs: Any,
) -> ReadOnlyTable
Build a two-column Parameter | Value table from a model or mapping.
Accepts a Pydantic model instance or a plain mapping; each field/key becomes one row.
Source code in src/clabe/ui/_requests.py
Request
dataclass
¶
Base of every declarative prompt request.
A request describes what to ask; it never asks. It knows its prompt kind, how to describe itself to any
client as JSON (spec), the JSON Schema of a valid answer (answer_schema) and how to check and
coerce an answer (validate_answer), so every client and the run apply the same rules.
Attributes:
| Name | Type | Description |
|---|---|---|
prompt_kind |
str
|
The prompt kind ( |
spec ¶
Returns a JSON-safe description of what to show (callables dropped, models named).
answer_schema ¶
validate_answer ¶
Validates value and returns it coerced to the type the asker expects.
Raises:
| Type | Description |
|---|---|
AnswerRejected
|
The answer is not acceptable; the prompt should stay open. |
Source code in src/clabe/ui/_requests.py
TextRequest
dataclass
¶
TextRequest(
label: str,
default: str | None = None,
multiline: bool = False,
validators: list[Validator] = list(),
field: str | None = None,
)
Bases: Request
A declarative request for free-form text.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The prompt shown to the user. |
default |
str | None
|
Value returned when the user submits an empty answer. |
multiline |
bool
|
Hint that a multi-line editor is appropriate. |
validators |
list[Validator]
|
Validators applied to the answer; the frontend re-prompts and surfaces the returned error until they all pass. |
field |
str | None
|
Logical field name used in the persisted transcript. |
NavigationRequested ¶
NavigationRequested(action: Literal['back', 'forward'])
Bases: Exception
Raised by a client's ask when the user asks to navigate instead of answering (e.g. Alt+← in the TUI).
Whoever drives the client handles it: during a run, LocalClient goes back
("back") or forward ("forward") and asks again if the run refuses; outside a run it is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Literal['back', 'forward']
|
|
required |
NoSessionError ¶
Bases: RuntimeError
Raised by ask when nothing can ask the user.
PromptCancelledError ¶
Bases: Exception
Raised by a prompt that was cancelled before it was answered (e.g. the run went back or aborted).
Session ¶
Bases: Protocol
Something that can ask the user and tell them things: a run, or a local client outside a run.
ask ¶
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
TextualClient ¶
A Client backed by a single persistent Textual app.
The app is started lazily on first use and runs on a background thread for the remainder of the session. Messages, answered prompts, and live activity all render inside the one app; console logging is muted for the app's lifetime so nothing corrupts the display.
Like every client it never validates: ask returns the raw answer and whoever drives the client (a run,
or a ClientSession) validates it and asks again if needed.
Source code in src/clabe/ui/_textual.py
set_context ¶
set_context(context: Any) -> None
Shows what the run is about (a RunContext) in the bar under the header.
set_reporter ¶
Lets the user report an issue (F3): reporter files a report with the user's comment and returns its
id. None turns reporting off.
Source code in src/clabe/ui/_textual.py
close ¶
Tear down the TUI and restore console logging.
Source code in src/clabe/ui/_textual.py
ask ¶
Shows request in the TUI and returns the raw answer, echoing it in the Session pane.
Raises:
| Type | Description |
|---|---|
PromptCancelledError
|
|
ValueError
|
|
Source code in src/clabe/ui/_textual.py
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
Writes a timestamped, level-styled message to the Session pane.
Source code in src/clabe/ui/_textual.py
cancel ¶
Abort the waiting prompt from any thread; it raises PromptCancelledError.
Source code in src/clabe/ui/_textual.py
make_client ¶
Builds a client for the requested backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
|
'auto'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ImportError
|
|
Source code in src/clabe/ui/_client.py
acknowledge ¶
acknowledge(
message: str,
*,
title: str = "Notice",
button_label: str = "OK",
field: str | None = None,
) -> None
Shows message and blocks until the user dismisses it (see AcknowledgeRequest).
Source code in src/clabe/ui/_session.py
activity ¶
activity(description: str) -> AbstractContextManager[None]
Shows live work (e.g. a running app) for the duration of a block; a run records it as activity events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
What the work is, as shown to the user. |
required |
Source code in src/clabe/ui/_session.py
ask ¶
Asks request through the bound session and returns its validated answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
What to ask (e.g. a |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The answer, validated and coerced by the request (a |
Any
|
value). |
Raises:
| Type | Description |
|---|---|
NoSessionError
|
Nothing is bound that can ask the user. |
PromptCancelledError
|
The prompt was cancelled before it was answered. |
Source code in src/clabe/ui/_session.py
autocomplete ¶
autocomplete(
label: str,
options: Sequence[str] | OptionsFunction,
*,
default: str | None = None,
strict: bool = False,
validators: Sequence[Validator] = (),
field: str | None = None,
help: str | None = None,
) -> str
Asks for text completed against options, a list or a function of the typed text returning the options (see
AutoCompleteRequest).
Source code in src/clabe/ui/_session.py
bind ¶
Binds session as the process' session for the block, then removes that binding.
Process-wide: every thread sees the binding. Bindings form an ordered list and the latest one is current, so blocks may end in any order (e.g. on different threads): ending a block removes its own binding wherever it is, and never brings back a binding whose block has already ended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session | None
|
The session to bind, or |
required |
Source code in src/clabe/ui/_session.py
confirm ¶
Asks a yes/no question (see ConfirmRequest).
current_session ¶
current_session() -> Session | None
Returns the session of the latest binding, or None if nothing is bound.
field ¶
Asks for one field of model and returns the typed value (see FieldRequest).
The session resolves the field to the prompt its type calls for (e.g. yes/no for a bool).
Source code in src/clabe/ui/_session.py
form ¶
form(
model: type,
*,
title: str | None = None,
initial: object | None = None,
field: str | None = None,
) -> Any
Asks to fill in model as a form; the model instance, or None when cancelled (see
FormRequest).
Source code in src/clabe/ui/_session.py
group ¶
Asks several prompts together as one (e.g. a text input and a slider) and returns their answers by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Optional title shown above the group. |
None
|
**items
|
Request
|
The prompts, by name: text, number, confirm, pick, autocomplete, path or field requests. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Each item's validated value, by name. |
Source code in src/clabe/ui/_session.py
header ¶
header(text: str) -> None
Shows the user a header through the bound session; logs it when nothing can show it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The header text. |
required |
Source code in src/clabe/ui/_session.py
html ¶
html(
source: str | Path,
*,
title: str | None = None,
caption: str | None = None,
button_label: str = "Continue",
field: str | None = None,
) -> None
Shows an HTML page (a local file, a URL, or the HTML itself) and blocks until the user continues.
The page is sandboxed. Clients that cannot show HTML log a warning instead (see MediaRequest).
Source code in src/clabe/ui/_session.py
image ¶
image(
source: str | Path,
*,
title: str | None = None,
caption: str | None = None,
button_label: str = "Continue",
field: str | None = None,
) -> None
Shows an image (a local file or a URL) and blocks until the user continues.
Clients that cannot show images log a warning with the file instead (see MediaRequest).
Source code in src/clabe/ui/_session.py
markdown ¶
markdown(
text: str,
*,
title: str | None = None,
button_label: str = "Continue",
field: str | None = None,
) -> None
Shows a Markdown document and blocks until the user continues (see MarkdownRequest).
Source code in src/clabe/ui/_session.py
notify ¶
notify(message: str, level: MessageLevel = INFO) -> None
Tells the user something through the bound session; logs it (at level) when nothing can show it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The text to show. |
required |
level
|
MessageLevel
|
How prominently to show it. |
INFO
|
Source code in src/clabe/ui/_session.py
number ¶
number(
label: str,
*,
default: float | None = None,
field: str | None = None,
minimum: float | None = None,
maximum: float | None = None,
step: float | None = None,
widget: Literal["input", "slider"] = "input",
) -> float
Asks for a number, optionally bounded (see NumberRequest).
Source code in src/clabe/ui/_session.py
path ¶
path(
label: str,
*,
start: str | PathLike | None = None,
default: str | None = None,
must_exist: bool = True,
kind: Literal["file", "dir", "any"] = "file",
extensions: Sequence[str] | None = None,
field: str | None = None,
help: str | None = None,
) -> Path | None
Asks for a filesystem path; None when cancelled (see PathRequest).
Source code in src/clabe/ui/_session.py
pick ¶
pick(
label: str,
options: Sequence[str | Choice],
*,
default: str | None = None,
allow_none: bool = True,
none_label: str = "None",
field: str | None = None,
help: str | None = None,
) -> str | None
Asks to pick one option; None when the "none" option is picked (see PickRequest).
Source code in src/clabe/ui/_session.py
table ¶
table(
columns: Sequence[str],
rows: Sequence[Sequence[Any]],
*,
title: str | None = None,
prompt: str | None = None,
confirm_label: str = "OK",
cancel_label: str = "Cancel",
field: str | None = None,
) -> bool
Shows a read-only table and asks yes/no (see ReadOnlyTable).
Source code in src/clabe/ui/_session.py
text ¶
text(
label: str,
*,
default: str | None = None,
multiline: bool = False,
validators: Sequence[Validator] = (),
field: str | None = None,
) -> str
Asks for free-form text (see TextRequest).
Source code in src/clabe/ui/_session.py
url ¶
url(
address: str,
*,
title: str | None = None,
caption: str | None = None,
button_label: str = "Continue",
field: str | None = None,
) -> None
Shows a web page and blocks until the user continues.
Sites that refuse to be framed still get a link to open them. Clients that cannot show web pages log a warning
with the URL instead (see MediaRequest).