Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Deleting an attribute on {class}`~libvt.snapshot.Snapshot` now raises

### Documentation

#### Drive a Python child from the README (#131)

The README quickstart uses {func}`~libvt.aio.open_pty` and
{meth}`~libvt.aio.PtySession.wait_for` to start a Python child in a POSIX
terminal, send input, and assert the child's committed response on screen.

#### Test selection and cancellation in fzf (#138)

The {ref}`fzf recipe <topics-testing-fzf>` drives a live picker in a private
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ styles:
Use [`Snapshot.find_cells()`][find_cells] to turn a visible label into cell
coordinates for a click, highlight, or assertion.

### Drive a terminal program

On POSIX, use [`open_pty()`][open_pty] to launch a program, send input, and
wait for a committed [`Snapshot`][snapshot] showing the child's response. The
child prints `Taken: key` only after it reads the command:

```python
>>> import asyncio
>>> import os
>>> import sys
>>> from libvt import Snapshot
>>> from libvt.aio import open_pty

>>> async def take_key() -> Snapshot:
... child = "print('Quay'); print('Taken: ' + input())"
... async with open_pty([sys.executable, "-u", "-c", child]) as session:
... await session.wait_for("Quay", timeout=5)
... session.paste("key")
... session.send_key("enter")
... return await session.wait_for(
... lambda snap: "Taken: key" in snap.lines, timeout=5
... )

>>> if os.name == "posix":
... snap = asyncio.run(take_key())
... assert "Taken: key" in snap.lines
```

### Assert screen boxes inline

Most unit tests can stop at [`assert_screen_box()`][assert_screen_box], which
Expand Down Expand Up @@ -224,6 +252,8 @@ MIT License. See [LICENSE](LICENSE).
[find_cells]: https://libvt.git-pull.com/topics/snapshots/#locate-text-by-cell-coordinates
[committed]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Terminal.committed
[viewport]: https://libvt.git-pull.com/api/snapshot/#libvt.snapshot.Snapshot.viewport
[open_pty]: https://libvt.git-pull.com/api/aio/pty/#libvt.aio.open_pty
[snapshot]: https://libvt.git-pull.com/api/snapshot/#libvt.snapshot.Snapshot
[assert_screen_box]: https://libvt.git-pull.com/api/testing/#libvt.testing.assert_screen_box
[contrib_syrupy]: https://libvt.git-pull.com/api/contrib/syrupy/
[pytest_plugin]: https://libvt.git-pull.com/api/pytest_plugin/
Expand Down
Loading