1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/env python3
"""reflow -- layouts that reflow the way you expect.
The arrangement is derived from the window, never stored. Turn it a quarter,
shrink the terminal until boxes become a tidy list, grow it back: the exact
arrangement returns, because there was nothing stored to drift.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from castgen import Recorder, out_path
ENV = {"PS1": "$ ", "ENV": "/dev/null"}
r = Recorder(["/bin/sh"], cols=100, rows=28, title="layouts that reflow", env=ENV)
# Three named panes, built over the socket -- the demo is about the layout.
r.api("split", dir="cols")
r.api("split", dir="rows")
for pid, name in zip(
sorted(p["id"] for p in r.api("panes")["panes"]), ["editor", "server", "logs"]
):
r.api("set-name", target="pane", id=pid, name=name)
r.capture(force=True)
r.pause(1.0)
r.run("echo this arrangement is derived, not stored", wait="derived")
r.pause(1.2)
# A quarter turn: the same panes, the layout re-derived on the spot.
r.key(" ", dt=0.5)
r.pause(1.3)
# Down. Each stop holds long enough to see the layout re-derive itself.
for size in [(84, 24), (66, 18), (50, 13), (36, 8)]:
r.resize(*size, dt=0.55)
r.pause(0.75)
r.pause(1.2) # the small screen: a list, not clutter
# And back. The exact arrangement returns.
for size in [(50, 13), (66, 18), (84, 24), (100, 28)]:
r.resize(*size, dt=0.55)
r.pause(0.6)
r.pause(1.6)
r.save(out_path("reflow"), tail=2.0)
|