Skip to content

feat: ASCII animation player + anim%save fix + gfortran 16 spec workaround#1828

Merged
krystophny merged 2 commits intomainfrom
feature/ascii-animation-player
May 7, 2026
Merged

feat: ASCII animation player + anim%save fix + gfortran 16 spec workaround#1828
krystophny merged 2 commits intomainfrom
feature/ascii-animation-player

Conversation

@krystophny
Copy link
Copy Markdown
Collaborator

Summary

  • New `fortplot_ascii_player` module + `fortplot_play_ascii` CLI that play back `.txt` animations produced by `save_animation('*.txt')`. Parses the `=== Frame N ===` framing the existing pipeline already emits, prints frames to stdout (or any unit), and sleeps via libc `nanosleep` between frames.
  • Make `anim%save(...)` work directly as the README documents. Previously the type-bound save returned -1 unless `save_animation()` had been called first to register the impl pointer; now the facade `FuncAnimation` wires it up at construction.
  • Reconcile the README with reality: animation save accepts `.txt` (no ffmpeg needed); add a player invocation snippet.
  • Fix an unrelated gfortran 16 `-O0` miscompile that crashed `test_spec` on system gfortran 16.1.1. Reduced and filed upstream as [gfortran 16, -O0] deferred-length character concatenation produces all-blanks for certain RHS shapes (64-char total) krystophny/gcc-dev#167. Worked around in `spec_to_json` by routing the schema header through a `len=*` formal.

Test plan

  • `fpm test test_ascii_player` -- parse-header edge cases, frame count, dry-run, capture-to-unit, missing-file / zero-fps error paths.
  • `fpm test test_ascii_player_e2e` -- save_animation .txt -> player end-to-end.
  • `fpm test test_animation_txt_save` -- existing .txt animation save test still green.
  • `make example ARGS="save_animation_demo"` -- mp4 save still works.
  • `make test` -- whole suite green on local gfortran 16.1.1 (CachyOS / Arch).

Verification

Test fails on main (system gfortran 16, -O0)

```
$ git checkout main && fpm test test_spec
...
FAIL: rt line: parse succeeds
FAIL: rt line: mark type
...
At line 669 of file test/test_spec.f90
Fortran runtime error: Index '1' of dimension 1 of array 'parsed...%columns' below lower bound of
Error termination.
cmd_run:stopping due to failed executions
STOP 2
```

```
$ git checkout main && fpm test test_animation_txt_save # writes a .txt animation

(passes, but no way to play it back -- before this PR)

```

```
$ # README example pattern: anim%save("movie.txt", status=status)

Returns -1 with "Animation save implementation not initialized" before this PR.

```

Test passes after fix

```
$ make test 2>&1 | tail -3
ALL TESTS PASSED (fpm test)
```

```
$ fpm test test_spec 2>&1 | tail -4
=== Spec Test Summary ===
Tests passed: 158 / 158
All spec tests PASSED!
STOP 0
```

```
$ fpm test test_ascii_player test_ascii_player_e2e 2>&1 | tail -4
PASS test_ascii_player
PASS test_ascii_player_e2e
```

Player demo

```
$ fpm run --target fortplot_play_ascii -- /tmp/wave.txt --fps 24 --loop
=== Frame 1 ===
ascii animation
+--------------------------------------------------------------------------------+
|...|
... (animated)
```

Notes

krystophny added 2 commits May 7, 2026 13:06
- Add fortplot_ascii_player module that parses the `=== Frame N ===`
  format produced by save_animation('*.txt') and plays frames at a
  chosen FPS, with optional ANSI clear-screen between frames.
- Add fortplot_play_ascii CLI app: file + --fps + --loop / --once /
  --no-clear / --dry-run flags, sleeps via libc nanosleep.
- Tests: parse-header edge cases, frame count, dry-run, capture-to-unit,
  missing-file/zero-fps error paths, plus an end-to-end test that
  drives save_animation('*.txt') and the player together.
- Make `anim%save(...)` work directly, as documented in README. Routed
  through a facade FuncAnimation that registers the save implementation
  pointer up front, so users do not need to call save_animation() first
  to wake the dispatcher.
- README: mention .txt as a supported animation format and how to play
  it back; example/animation/README likewise.
- Work around a gfortran 16 -O0 miscompile of certain
  `'{' // new_line('a') // <chunk>` deferred-length allocatable
  concatenations in spec_to_json that produced an all-blanks header
  and crashed test_spec downstream. MRE filed at
  krystophny/gcc-dev#167; the fix routes the schema header through a
  `len=*` formal so the buggy expansion is never emitted.
The C binding to nanosleep is POSIX-only and hangs the Windows runner
(symbol is absent from MSVC libc and unreliable under MinGW). Replace
sleep_ms with a system_clock-based busy wait that matches the existing
fortplot pattern (animation_core, matplotlib_session). Resolves the
test_ascii_player Windows timeout (exit 124) on PR #1828.
@krystophny krystophny merged commit a93ee49 into main May 7, 2026
5 checks passed
@krystophny krystophny deleted the feature/ascii-animation-player branch May 7, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant