python-xli 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,220 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # UV
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
201
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
203
+ # you could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xli contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,397 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-xli
3
+ Version: 0.2.0
4
+ Summary: Build polished, transcript-style terminal interfaces for chat / agent / REPL-ish apps in 20 lines of Python.
5
+ Project-URL: Homepage, https://github.com/vitalops/xli
6
+ Project-URL: Issues, https://github.com/vitalops/xli/issues
7
+ Author-email: Fariz Rahman <farizrahman4u@gmail.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: agent,chat,cli,prompt-toolkit,rich,terminal,transcript,tui
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: User Interfaces
19
+ Classifier: Topic :: Terminals
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: prompt-toolkit>=3.0.40
22
+ Requires-Dist: rich>=13.7
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy>=1.10; extra == 'dev'
25
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.5; extra == 'dev'
28
+ Provides-Extra: images
29
+ Requires-Dist: pillow>=10.0; extra == 'images'
30
+ Provides-Extra: markdown
31
+ Requires-Dist: pygments>=2.17; extra == 'markdown'
32
+ Description-Content-Type: text/markdown
33
+
34
+ <div align="center">
35
+
36
+ # xli
37
+
38
+ **Build polished, transcript-style terminal UIs for chat, agent, and REPL apps — in ~20 lines of Python.** ✨
39
+
40
+ [![PyPI](https://img.shields.io/pypi/v/xli.svg)](https://pypi.org/project/xli/)
41
+ [![Python](https://img.shields.io/pypi/pyversions/xli.svg)](https://pypi.org/project/xli/)
42
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
43
+ [![Built on rich + prompt_toolkit](https://img.shields.io/badge/built%20on-rich%20%2B%20prompt__toolkit-8a2be2.svg)](#-credits)
44
+
45
+ </div>
46
+
47
+ ```python
48
+ import xli
49
+
50
+ ui = xli.UI(title="echo")
51
+
52
+ @ui.on_prompt
53
+ async def reply(prompt: str) -> None:
54
+ with ui.streaming("assistant") as out:
55
+ for token in f"You said: {prompt}".split():
56
+ out.write(token + " ")
57
+
58
+ ui.run()
59
+ ```
60
+
61
+ That little snippet gets you: markdown-rendered **streaming** responses, slash-command
62
+ autocomplete, `@file` mentions, multi-line input (Enter sends, Alt+Enter for newlines),
63
+ persistent history, a themed status bar, arrow-selectable prompts, inline approvals — and a
64
+ terminal that *feels right*. 🪄
65
+
66
+ And the best part: the transcript flows into your terminal's **normal scrollback**, so text stays
67
+ **selectable, scrollable, and searchable** with your terminal's own tools. xli doesn't take over
68
+ the screen.
69
+
70
+ ---
71
+
72
+ ## ✨ Highlights
73
+
74
+ - 📜 **Real scrollback, not a screen takeover.** Finalized output is printed into your terminal's
75
+ native scrollback — select, scroll, and find all work the way they always do.
76
+ - 🌊 **Streaming markdown** that appears token-by-token, then settles into properly-rendered text.
77
+ - 🃏 **Mutable cards.** A tool call flips from `running` → `done` *in place*; a plan's checkboxes
78
+ tick off live — via a handle you hold and update from anywhere.
79
+ - ⌨️ **A real composer.** Multi-line input, slash-command autocomplete, `@file` mentions, history,
80
+ and paste handling out of the box.
81
+ - ✅ **Inline approvals, pickers & wizards** — arrow-selectable, no modal screen-takeover, and they
82
+ block your agent until the user answers.
83
+ - ⏸️ **Type-ahead & ESC-to-interrupt** while the agent is working, with cooperative `asyncio`
84
+ cancellation.
85
+ - 🎨 **Themeable** via plain dataclasses — minimal/glyph-driven by default, boxed if you insist.
86
+ - 🪶 **Tiny surface, two deps.** Wraps [rich](https://github.com/Textualize/rich) for rendering and
87
+ [prompt_toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) for input. No build steps.
88
+
89
+ ## 🤔 What it is
90
+
91
+ A small, opinionated library for **one specific job**: interactive agent / chat-style terminal apps
92
+ where output is a *flowing transcript*, not an app screen.
93
+
94
+ The pattern xli handles:
95
+
96
+ - A scrolling transcript of structured cards — user messages, assistant messages, tool calls,
97
+ diffs, plans, reasoning, images — committed to real scrollback.
98
+ - Streaming markdown that appears as it arrives, then settles into rendered scrollback.
99
+ - A persistent multi-line composer at the bottom with autocomplete, `@file` mentions, and history.
100
+ - **Mutable cards** — a tool card that flips `running` → `done` in place, a plan whose checkboxes
101
+ update — via a handle you hold.
102
+ - Inline, arrow-selectable approvals / pickers / wizards that block until resolved.
103
+ - A subtle status bar, an animated "working" spinner, type-ahead, and ESC-to-interrupt.
104
+
105
+ ## 🚫 What it is NOT
106
+
107
+ | Not… | Because |
108
+ |---|---|
109
+ | A TUI framework | No widget tree, no CSS, no focus model, no mouse panes. Reach for [Textual](https://github.com/Textualize/textual) when you want a full app screen. |
110
+ | A "richer `print`" | xli is interactive — it owns the event loop. For one-shot static rendering, use [rich](https://github.com/Textualize/rich) directly. |
111
+ | A full-screen app | It renders **inline** so your terminal keeps native scroll / select / find. That's the whole point. |
112
+ | Tied to any LLM / agent framework | It knows nothing about providers. It renders the events *you* emit — OpenAI, Anthropic, LangChain, your own loop, whatever. |
113
+ | A REPL builder | It runs *your* code in response to prompts. For a Python REPL, use [ptpython](https://github.com/prompt-toolkit/ptpython). |
114
+
115
+ ## ⚖️ How it compares
116
+
117
+ xli lives in the gap between "low-level rendering toolkit" and "full-screen app framework." If your
118
+ output is a **conversation that scrolls**, that gap is exactly where you want to be.
119
+
120
+ | | xli | [Textual](https://github.com/Textualize/textual) | [rich](https://github.com/Textualize/rich) | [prompt_toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) | [questionary](https://github.com/tmbo/questionary) |
121
+ |---|---|---|---|---|---|
122
+ | **Shape** | Flowing transcript | Full-screen app | Print / render | Input / REPL | Prompts only |
123
+ | **Native scrollback** | ✅ keeps it | ❌ takes over screen | ✅ (it just prints) | ⚠️ partial | ✅ |
124
+ | **Streaming + mutable cards** | ✅ built-in | ✅ (you wire widgets) | ❌ DIY | ❌ DIY | ❌ |
125
+ | **Composer (multiline, history, `@`, `/`)** | ✅ built-in | 🔧 build from widgets | ❌ | 🔧 primitives | ❌ |
126
+ | **Inline approvals / pickers / wizards** | ✅ built-in | 🔧 build from widgets | ❌ | 🔧 primitives | ✅ (pickers) |
127
+ | **Best for** | Chat / agent transcripts | Dashboards, IDEs, full apps | Static output | Custom REPLs & input | One-off questionnaires |
128
+
129
+ **In short:** Textual gives you a canvas to build *any* app and asks you to design the whole screen.
130
+ xli gives you *one* app shape — the agent/chat transcript — already assembled, and hands the
131
+ scrollback back to your terminal. If you've been gluing rich + prompt_toolkit together to make a
132
+ chat loop, xli *is* that glue, done well. 🙂
133
+
134
+ ## 📦 Install
135
+
136
+ ```sh
137
+ pip install xli
138
+ ```
139
+
140
+ Optional extras:
141
+
142
+ - `xli[markdown]` — `pygments` for code-block syntax highlighting in messages (recommended).
143
+ - `xli[images]` — `pillow`, for inline images (`ui.image(...)`).
144
+
145
+ Two core dependencies (rich, prompt_toolkit). No build steps. Requires Python **3.11+**.
146
+
147
+ ## 🚀 Quickstart
148
+
149
+ A fuller echo agent — streaming, a status field, a tool card that updates in place, and a slash
150
+ command:
151
+
152
+ ```python
153
+ import asyncio
154
+ import xli
155
+
156
+ ui = xli.UI(title="echo", status_fields=["turn"], pet="cat")
157
+ turn = 0
158
+
159
+ @ui.command("clear", description="clear the screen")
160
+ async def clear(ui, args):
161
+ ui.clear_transcript()
162
+
163
+ @ui.on_prompt
164
+ async def handle(prompt: str) -> None:
165
+ global turn
166
+ turn += 1
167
+ ui.status.set(turn=turn)
168
+
169
+ card = ui.tool("think", status="running") # live, mutable card
170
+ with ui.working("thinking"):
171
+ await asyncio.sleep(0.5)
172
+ card.update(status="done", output="ok") # commits to scrollback
173
+
174
+ with ui.streaming("assistant") as out:
175
+ for token in f"You said: **{prompt}**".split():
176
+ out.write(token + " ")
177
+ await asyncio.sleep(0.04)
178
+
179
+ ui.run()
180
+ ```
181
+
182
+ > 💡 Want to see everything at once? `examples/demo.py` exercises every feature in one file.
183
+
184
+ ## 📖 The vocabulary
185
+
186
+ `xli.UI` exposes a small set of methods you call from any handler. Transcript methods return a
187
+ **cell handle** you can mutate.
188
+
189
+ ```python
190
+ # --- streaming + cards (return a Cell handle) ---
191
+ with ui.streaming(role) as out: # streamed text; out.write(chunk); out.text
192
+ ...
193
+ card = ui.tool(name, args=, output=, status="running") # status="running" -> live + mutable
194
+ card.update(status="done", output=...) # mutate in place; commits when final
195
+ card.remove() # drop a live cell
196
+
197
+ ui.message(role, text) # one-shot message
198
+ ui.diff(diff, path=) # syntax-colored unified diff
199
+ ui.plan([("step", "status"), …]) # checklist
200
+ ui.reasoning(summary) # muted thought rail
201
+ ui.image("plot.png") # inline image (kitty / iTerm2 / half-block fallback)
202
+ ui.link("label", "https://…") # OSC 8 hyperlink
203
+ ui.note("…") / ui.header("…") # muted status lines
204
+ ui.print(any_rich_renderable) # escape hatch for custom rendering
205
+
206
+ # --- a spinner while you work ---
207
+ with ui.working("running tests"): ... # animated, with an elapsed timer
208
+
209
+ # --- blocking prompts (await) ---
210
+ decision = await ui.approve(title=, body=, reason=) # arrow-select Yes / Always / No
211
+ choice = await ui.pick("Model", ["gpt-5", "claude-opus"]) # ↑/↓ · 1-9 · enter
212
+ yes = await ui.confirm("Delete?")
213
+ name = await ui.input("Name?", default="")
214
+ answers = await ui.wizard([ # multi-step flow -> dict
215
+ ui.step.pick("Model", ["opus", "sonnet"]),
216
+ ui.step.confirm("Stream responses?"),
217
+ ui.step.text("Project name", default="app"),
218
+ ])
219
+
220
+ # --- chrome + lifecycle ---
221
+ ui.status.set(model="gpt-5", tokens="3.2k/400k") # bottom bar (declare fields up front)
222
+ ui.notify("response ready") # desktop notification (OSC 9)
223
+ ui.clear_transcript()
224
+ ui.exit()
225
+ ```
226
+
227
+ ## 🧠 The one design decision
228
+
229
+ xli renders **inline**, not full-screen. Finalized cells are *printed into your terminal's normal
230
+ scrollback* — so selection, scrolling, and find all come from the terminal itself. Only a small
231
+ **live region** at the bottom (the composer, status bar, an in-progress stream, a running tool
232
+ card, a spinner, a picker) is redrawn.
233
+
234
+ A cell is **mutable while it's live** at the bottom; once it finalizes it **commits to scrollback**
235
+ and becomes immutable (but selectable). That two-tier model is what lets xli have both editable,
236
+ animated cards *and* native, selectable scrollback — the thing full-screen TUIs give up.
237
+
238
+ ## 🃏 Mutable cards
239
+
240
+ The transcript methods return a handle. Hold it, mutate it from anywhere (including across `await`s
241
+ and from other tasks) — it re-renders in place while live, then commits to scrollback once it's
242
+ finalized:
243
+
244
+ ```python
245
+ card = ui.tool("shell", status="running", args={"command": ["pytest", "-q"]})
246
+ result = await run_shell(...)
247
+ card.update(status="done", output=result) # ✓ shell … and the output, committed
248
+ ```
249
+
250
+ A `ui.tool(...)` **without** a `status` is a one-shot card (committed immediately). With
251
+ `status="running"` it stays live and mutable until you update it to `done` / `error` / `cancelled`.
252
+
253
+ ## ⌨️ Slash commands & @file mentions
254
+
255
+ ```python
256
+ @ui.command("model", description="switch model")
257
+ async def cmd_model(ui, args):
258
+ sel = await ui.pick("Model", ["gpt-5", "claude-opus"])
259
+ if sel is not None:
260
+ ui.status.set(model=sel)
261
+
262
+ @ui.command("quit", aliases=["q", "exit"])
263
+ async def cmd_quit(ui, args):
264
+ ui.exit()
265
+ ```
266
+
267
+ Typing `/` opens a command list **below** the composer (arrow to navigate, Tab to fill, Enter to
268
+ run). `/help`, `/quit`, and `/clear` are built in (override freely). Typing `@` opens a **file
269
+ picker** from the working directory; Tab/Enter inserts the path — handy for letting users reference
270
+ files for your agent.
271
+
272
+ ## ✅ Approvals, pickers, wizards
273
+
274
+ All are inline and arrow-selectable (no modal screen-takeover). The request commits to scrollback so
275
+ it scrolls into view and persists; the choices appear in the live region; the outcome is recorded
276
+ below.
277
+
278
+ ```python
279
+ decision = await ui.approve(
280
+ title="apply patch to README.md",
281
+ body="add a one-liner about xli",
282
+ reason="writes outside the workspace root",
283
+ ) # -> "approved" | "approved_for_session" | "denied" | "aborted"
284
+ ```
285
+
286
+ `↑/↓` move the highlight, `1`-`9` quick-select, `Enter` confirms, `Esc` cancels.
287
+
288
+ ## ⏸️ Interrupts
289
+
290
+ The composer stays live while your handler runs — users can **type ahead** (queued prompts show as
291
+ muted `⋯` lines) and press **ESC to interrupt** the current turn. Interrupt is cooperative `asyncio`
292
+ cancellation; register cleanup with `@ui.on_interrupt`:
293
+
294
+ ```python
295
+ @ui.on_interrupt
296
+ async def cleanup():
297
+ await release_resources() # don't write to the transcript here
298
+ ```
299
+
300
+ A running tool card left behind by an interrupted turn is automatically marked `cancelled`.
301
+
302
+ ## 🎨 Themes
303
+
304
+ ```python
305
+ ui = xli.UI(theme="codex") # default — minimal, glyph-driven, no borders, no solid bg
306
+ ui = xli.UI(theme="minimal") # even more austere
307
+ ui = xli.UI(theme="boxed") # rounded borders if you really want them
308
+ ui = xli.UI(theme=xli.Theme( # custom — it's a dataclass; override fields
309
+ user_color="cyan",
310
+ tool_glyph="→",
311
+ code_theme="monokai",
312
+ ))
313
+ ```
314
+
315
+ Themes are dataclasses — override fields, don't subclass. The default leans "light": chrome is font
316
+ color + thin rules, never solid background blocks. See [`docs/theme.md`](docs/theme.md) for the
317
+ design guide you can hand to a coding agent.
318
+
319
+ ## 🔌 Plugging into an agent
320
+
321
+ xli renders the event types you give it. It doesn't care if those come from OpenAI, Anthropic,
322
+ LangChain, or your own framework:
323
+
324
+ ```python
325
+ @ui.on_prompt
326
+ async def handle(prompt: str) -> None:
327
+ cards = {} # tool-call id -> live card handle
328
+ async for event in my_agent.stream(prompt):
329
+ if event.kind == "message":
330
+ ui.message("assistant", event.text)
331
+ elif event.kind == "tool_call":
332
+ cards[event.id] = ui.tool(event.name, args=event.args, status="running")
333
+ elif event.kind == "tool_result":
334
+ cards[event.id].update(status="done", output=event.output) # flips in place
335
+ elif event.kind == "approval_request":
336
+ decision = await ui.approve(title=event.title, body=event.body)
337
+ my_agent.respond(event.id, decision)
338
+ ```
339
+
340
+ For token-by-token output, wrap a `with ui.streaming("assistant") as out:` block and call
341
+ `out.write(delta)` as deltas arrive. Have your own event stream? Register a custom renderer:
342
+
343
+ ```python
344
+ @ui.renderer("benchmark")
345
+ def render_benchmark(ui, event):
346
+ ui.print(make_bar_chart(event["data"]))
347
+
348
+ ui.dispatch({"type": "benchmark", "data": [...]})
349
+ ```
350
+
351
+ ## ⌨️ Keys
352
+
353
+ ```
354
+ enter send (or run highlighted command / select picker option / accept input)
355
+ alt+enter ⋅ ctrl+j newline
356
+ ↑ / ↓ history · navigate the command/file list · move picker selection
357
+ tab accept the highlighted completion / insert @file path
358
+ 1–9 quick-select a picker option
359
+ esc cancel a picker/modal or close the list — otherwise interrupt the turn
360
+ ctrl+c interrupt ctrl+d quit
361
+ ```
362
+
363
+ ## 🛠️ Contributing
364
+
365
+ Contributions, bug reports, and ideas are very welcome! 🙌
366
+
367
+ ```sh
368
+ git clone https://github.com/fariz/xli
369
+ cd xli
370
+ pip install -e ".[dev,markdown,images]"
371
+ pytest # run the tests
372
+ ruff check . # lint
373
+ mypy xli # type-check
374
+ ```
375
+
376
+ Found a rough edge or have a use case xli doesn't cover cleanly? Open an
377
+ [issue](https://github.com/fariz/xli/issues) — the API is small on purpose, so design
378
+ conversations matter.
379
+
380
+ ## 📍 Status
381
+
382
+ **Pre-1.0** (currently `0.2.0`). The API is stable enough to build on; versions are bumped
383
+ thoughtfully if anything user-facing changes.
384
+
385
+ ## 🙏 Credits
386
+
387
+ xli stands on the shoulders of two excellent libraries:
388
+
389
+ - [**rich**](https://github.com/Textualize/rich) — all the rendering.
390
+ - [**prompt_toolkit**](https://github.com/prompt-toolkit/python-prompt-toolkit) — all the input.
391
+
392
+ xli's contribution is the *composition*: the API you'd actually want to write a chat/agent terminal
393
+ app in.
394
+
395
+ ## 📄 License
396
+
397
+ [MIT](LICENSE) © xli contributors