Skip to content
Open
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
94 changes: 77 additions & 17 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ jobs:
${{ runner.os }}

- name: Install dependencies
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
run: cabal build --only-dependencies --enable-tests --enable-benchmarks all
- name: Build
run: cabal build --enable-tests --enable-benchmarks all
- name: Run tests
run: cabal test all --enable-tests
- if: matrix.ghc != '8.4.4'
# disable doc builds on older ghcs because some dependency docs aren't compatible
name: Build Docs
run: cabal haddock
run: cabal haddock all

packaged-source:
runs-on: ubuntu-latest
Expand All @@ -64,35 +64,95 @@ jobs:
ghc-version: '9.12.3'
cabal-version: '3.16.1.0'
- run: cabal update
- run: cabal sdist
- name: Check packaged fixtures and run the extracted suite
- run: cabal sdist all
- name: Check packaged fixtures and run the extracted suites
shell: python
run: |
import pathlib
import subprocess
import tarfile
import tempfile

archives = list(pathlib.Path("dist-newstyle/sdist").glob("reflex-vty-*.tar.gz"))
assert len(archives) == 1, archives
def find_archives():
archives = {}
for path in pathlib.Path("dist-newstyle/sdist").glob("*.tar.gz"):
with tarfile.open(path) as archive:
for name in archive.getnames():
parts = name.split("/")
if len(parts) == 2 and parts[1].endswith(".cabal"):
archives[parts[1][: -len(".cabal")]] = path
return archives

archives = find_archives()
expected_packages = {"reflex-vty", "reflex-vty-widgets"}
assert set(archives) == expected_packages, archives

expected = {str(p): p.read_bytes() for p in pathlib.Path("test/goldens").glob("*.txt")}
assert expected, "No repository goldens found"

with tempfile.TemporaryDirectory() as directory:
with tarfile.open(archives[0]) as archive:
roots = {name.split("/")[0] for name in archive.getnames()}
assert len(roots) == 1, roots
root = roots.pop()
for name, content in expected.items():
member = archive.extractfile(f"{root}/{name}")
assert member is not None and member.read() == content, name
archive.extractall(directory, filter="data")
source = pathlib.Path(directory) / root
sources = {}
for package, path in archives.items():
with tarfile.open(path) as archive:
roots = {name.split("/")[0] for name in archive.getnames()}
assert len(roots) == 1, (package, roots)
root = roots.pop()
assert root == f"{package}-" + root.rsplit("-", 1)[1], root
if package == "reflex-vty":
for name, content in expected.items():
member = archive.extractfile(f"{root}/{name}")
assert member is not None and member.read() == content, name
# Both shared test-support modules must ship in the
# core archive.
for helper in (
"test-support/Reflex/Vty/Test/AppHarness.hs",
"test-support/Reflex/Vty/Test/Snapshot.hs",
):
assert any(n.endswith(helper) for n in archive.getnames()), helper
else:
# The companion archive must contain the shared
# test-support modules and its registered specs.
for required in (
"test-support/Reflex/Vty/Test/AppHarness.hs",
"test-support/Reflex/Vty/Test/Snapshot.hs",
"test/Spec.hs",
"test/Reflex/Vty/Widget/KeySpec.hs",
"test/Reflex/Vty/Widget/Layout/SpacingSpec.hs",
"test/Reflex/Vty/Widget/GridSpec.hs",
"test/Reflex/Vty/Widget/PaginatorSpec.hs",
"test/Reflex/Vty/Widget/OverlaySpec.hs",
"app/Main.hs",
"app/Example/TierA.hs",
):
assert any(n.endswith(required) for n in archive.getnames()), required
archive.extractall(directory, filter="data")
sources[package] = pathlib.Path(directory) / root

def write_project(path, packages):
path.write_text(
"packages: " + "\n ".join([""] + [str(sources[p]) for p in packages]) + "\n"
)

# Both packages together.
project = pathlib.Path(directory) / "cabal.project"
write_project(project, ["reflex-vty", "reflex-vty-widgets"])
subprocess.run(
["cabal", "test", "all", "--enable-tests", "--test-show-details=direct"],
cwd=source, check=True,
cwd=directory, check=True,
)
for name, content in expected.items():
assert (sources["reflex-vty"] / name).read_bytes() == content, f"Golden rewritten: {name}"

# Core alone: its bundled test-support sources must suffice
# without the companion package present.
core_project = pathlib.Path(directory) / "cabal.project.core"
write_project(core_project, ["reflex-vty"])
subprocess.run(
["cabal", "test", "all", "--enable-tests", "--test-show-details=direct", "--project-file=cabal.project.core"],
cwd=directory, check=True,
)
for name, content in expected.items():
assert (source / name).read_bytes() == content, f"Golden rewritten: {name}"
assert (sources["reflex-vty"] / name).read_bytes() == content, f"Golden rewritten: {name}"

terminal:
strategy:
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add five interactive gallery examples to the `examples` executable: `prevent-quit` (confirm before exit), `print-key` (inspect keyboard events), `realtime` (background activity that never blocks input), `simple` (a five-second countdown that exits on its own), and `fullscreen` (the countdown on the alternate screen). Each has a VHS tape under `doc/examples/` and a hosted recording linked from the README gallery.
* Add the `canvas` gallery example: an interactive `Reflex.Vty.Canvas` board showing transparency, wide glyphs, combining marks with distinct attributes, and Vty's ellipsis clipping, with keyboard-driven overlay movement.
* Fix: pane mouse capture survives unrelated button presses/releases. The owning button's release (or an unspecified-button release) completes the gesture, so nested overlays can settle deferred visibility without losing that release.

## 1.3.0.0

Expand Down
46 changes: 46 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,49 @@ highlight overlay; placing it over a glyph clips or covers it per the same
policy, and moving away restores it. ([source](src-bin/Example/CanvasDemo.hs))

<img src="https://vhs.charm.sh/vhs-4Pb8inOYo4dWwFvmYXf6ib.gif" alt="canvas board demo: a checkerboard with a wide glyph, a combining-mark glyph, an ellipsis-clipped glyph at the right edge, and a movable highlight overlay" width="560">

## One note, one dialog

The companion package's small note editor runs with:

```bash
nix-shell --run 'cabal run widgets-demo'
```

[`Example.TierA`](reflex-vty-widgets/app/Example/TierA.hs) demonstrates one
composition: a text field inside a dialog, with explicit save and cancel.
The screen starts with `Note: Ship on Friday` and just two controls:
`e` opens the editor; `q` quits.

In the dialog, Enter saves the draft and Escape discards it. Reopening always
starts from the saved note, not a canceled draft. Printable keys—including
`e` and `q`—edit the draft instead of triggering background commands.
Ctrl+C quits from either screen. Notes live only for the current process;
this example does not write a file.

![Editing, canceling, and saving a single note](doc/widgets-demo.gif)

To regenerate the recording, prebuild the executable and run the tape:

```bash
nix-shell --run 'cabal build widgets-demo'
nix-shell -p vhs ttyd ffmpeg chromium python3 --run 'vhs doc/widgets-demo.tape'
```

The recording changes Friday to Monday and cancels, reopens the original
Friday text, then makes the same edit and saves. Short captions and visible
key badges explain those two outcomes; no unrelated widgets share the screen.
Each bold pink key badge brightens smoothly once over one second when its
caption appears, then stays steady. The animation never blinks or shifts text.

The tape uses [`widgets-demo-pty.py`](doc/widgets-demo-pty.py) only to select
captions with recording control bytes and paint a three-row band outside the
application viewport. All editing uses real keys and typed text. Caption
output never interrupts a partial terminal escape sequence or follows
application cleanup. The adapter propagates the child's exit status, which
the tape checks. Recording stops before sending the quit key, so restoration
of the pre-demo terminal stays off camera.

Production-widget tests cover draft reset, save/cancel, input isolation,
resizing, and shutdown. Direct-PTY checks run the executable without the
recording adapter to verify the workflow and terminal restoration.
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
./reflex-vty-widgets
9 changes: 9 additions & 0 deletions doc/articles-demo-scenes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"intro": ["Down", "Move the selection", "Up and Down change the highlighted article; nothing opens yet."],
"scenes": {
"0x01": ["Enter", "Read the selected article", "Enter opens whichever article is highlighted."],
"0x02": ["Escape", "Return to the list", "The circle turns hollow, marking the article as read."],
"0x04": ["Down · Enter", "Read another article", "The selection survived the round trip; one Down moves it on."],
"0x05": ["q", "Quit from the list", "q quits here; the reading view ignores it."]
}
}
Binary file added doc/articles-demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions doc/articles-demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# VHS tape for the articles demo: select, read, return, read the marker, quit.
# Render with: nix-shell -p vhs ttyd ffmpeg chromium python3 --run 'vhs doc/articles-demo.tape'
# Docs: https://github.com/charmbracelet/vhs
#
# doc/widgets-demo-pty.py paints the caption band from
# doc/articles-demo-scenes.json. Recording control bytes are consumed by the
# adapter and never reach the demo:
# Ctrl+A read caption Ctrl+B return caption
# Ctrl+D next-article caption Ctrl+E quit caption
# Every recorded action uses the demo's real keys: Down, Enter, Escape, q.

Output doc/articles-demo.gif

Set Shell "bash"
Set FontFamily "DejaVu Sans Mono"
Set FontSize 20
Set Width 900
Set Height 540
Set Padding 15
Set Theme "Dracula"
Set TypingSpeed 45ms
Set WaitTimeout 180s

# Prebuild articles-demo. Keep startup and the exit-status check off camera.
Hide
Type `PS1='ARTICLES_DEMO_READY> '`
Enter
Wait+Line /^ARTICLES_DEMO_READY> *$/
Type `nix-shell --run 'python3 doc/widgets-demo-pty.py doc/articles-demo-scenes.json "$(cabal list-bin articles-demo)"'`
Enter
Wait+Screen /Articles/
Wait+Screen /● Reflex 1.3 released/
Wait+Screen /● Terminal scrolling deep dive/
Wait+Screen /● Grid layout tips/
Wait+Screen /Enter: Read \| q: Quit/
Show
Sleep 2s

# Intro scene: Down only moves the highlight; no article opens.
Down
Sleep 1200ms

# Enter opens the highlighted second article.
Ctrl+A
Sleep 800ms
Enter
Wait+Screen /Terminal scrolling deep dive/
Wait+Screen /Escape: Back/
Sleep 2600ms

# Escape returns; the hollow bullet marks the article read.
Ctrl+B
Sleep 800ms
Escape
Wait+Screen /Enter: Read \| q: Quit/
Wait+Screen /○ Terminal scrolling deep dive/
Sleep 2600ms

# Selection was preserved; one Down reaches the third article.
Ctrl+D
Sleep 800ms
Down
Sleep 800ms
Enter
Wait+Screen /Grid layout tips/
Wait+Screen /Escape: Back/
Sleep 1400ms
Escape
Wait+Screen /Enter: Read \| q: Quit/
Wait+Screen /○ Grid layout tips/
Sleep 1000ms

# Stop recording before q restores the pre-demo terminal.
Ctrl+E
Sleep 800ms
Hide
Type "q"
Wait+Line /^ARTICLES_DEMO_READY> *$/
# VHS 0.11 reads Screen from buffer row 0, including old scrollback.
# Clear the hidden shell screen/scrollback without losing the demo's status.
Type `demo_status=$?; clear; (exit "$demo_status")`
Enter
Wait+Line /^ARTICLES_DEMO_READY> *$/
Type "echo ARTICLES_DEMO_EXIT=$?"
Enter
Wait+Screen /ARTICLES_DEMO_EXIT=0/
Loading
Loading