summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-30 23:58:54 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:18 -0300
commit3815a0bfad5818e2caf85a00c0c2d3aecc13bd1c (patch)
treedfb1920c13ac0e113d9294c96f86d36ecf95bbc9 /test
parent03ace1893d1a4b509c209e4e8ca023f7261e5cb9 (diff)
downloadpardes-3815a0bfad5818e2caf85a00c0c2d3aecc13bd1c.tar.gz
pardes-3815a0bfad5818e2caf85a00c0c2d3aecc13bd1c.zip
pardes - reads stdin into a +Pager pane, and is a terminal's PAGER and GIT_PAGER, Pager pardes|off to opt out; command panes page through cat
A paging command in a terminal, or run through its pty/run, sat in less, and a pty/run never answered. `pardes -` now reads stdin to its end, strips terminal escapes (colour, OSC, overstrike), and shows it: inside a session as a clean <cwd>/+Pager pane made through pane/new and back at once, outside one as a new editor whose first pane it is, as `vim -` does. A terminal's shell gets PAGER and GIT_PAGER set to this pardes's own path and `-` where the user's environment sets neither; `Pager off`, a setting in /ctl, init and DumpConfig, leaves terminals started after it to the environment. A command pane's one-shot shell keeps cat, its output being a pane already. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/fs.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/fs.py b/test/fs.py
index 23647b45..282cca8b 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -479,6 +479,22 @@ def run_file(binary):
assert run(client, term, b'fi\n') == b'error not run\n' # a syntax error runs nothing
assert run(client, term, b"echo 'open\n") == b'error not run\n' # nor does an open quote
assert run(client, term, b'true\n') == b'exit 0\n' # ...and the shell is clear after
+ # A paging command run through pty/run does not wait in less: the
+ # terminal's PAGER is `pardes -`, and its text is a +Pager pane.
+ if shutil.which('git'):
+ repo = root / 'pagedrepo'
+ repo.mkdir()
+ git = ['git', '-C', str(repo), '-c', 'user.name=p', '-c', 'user.email=p@x']
+ subprocess.run(git + ['init', '-q'], check=True, env=dict(os.environ, HOME=str(root)))
+ (repo / 'f').write_text('x\n')
+ subprocess.run(git + ['add', 'f'], check=True, env=dict(os.environ, HOME=str(root)))
+ subprocess.run(git + ['commit', '-qm', 'paged-commit-subject'], check=True, env=dict(os.environ, HOME=str(root)))
+ assert run(client, term, b'git -C pagedrepo log\n').startswith(b'exit 0\n')
+ pager = [r.split()[0].decode() for r in client.read('/index').splitlines() if r.split()[3:4] == [f'{repo}/+Pager'.encode()]] # git -C runs it in the repo
+ assert len(pager) == 1, client.read('/index')
+ assert b'paged-commit-subject' in client.read(f'/pane/{pager[0]}/body')
+ assert b'\x1b' not in client.read(f'/pane/{pager[0]}/body')
+ client.remove(f'/pane/{pager[0]}')
# A pty is not given one row (it loses the prompt's input mark,
# and the shell would read busy for ever): refused, and said.
try:
@@ -1421,6 +1437,17 @@ def test(binary, quic=False):
# A pane address the session has not is refused in words, exit
# 1, no pane made for a file of that name; one it has is looked
# at. A name with a newline is said in words, not an error name.
+ # `pardes -` (a terminal's PAGER): stdin, its escapes stripped, in a
+ # +Pager pane of the session, clean, and back at once.
+ fed = subprocess.run([binary, '-'], cwd=root, env=env, input=b'\x1b[1mbold\x1b[0m text\n',
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10)
+ assert fed.returncode == 0, fed.stderr
+ made_now, = serials() - before
+ assert client.read(f'/pane/{made_now}/name') == f'{root}/+Pager\n'.encode()
+ assert client.read(f'/pane/{made_now}/body') == b'bold text\n'
+ row = [r for r in client.read('/index').splitlines() if r.split()[0] == str(made_now).encode()][0]
+ assert row.split()[2] == b'0', row # clean: nothing to ask at Exit
+ client.remove(f'/pane/{made_now}')
# A new name in a directory there but not writable: refused now,
# not a pane that only fails at Save.
shut = root / 'shut-dir'
@@ -1450,6 +1477,30 @@ def test(binary, quic=False):
assert orphan.poll() is None
assert orphan.wait(timeout=5) == 1
+ # `pardes -` outside a session: an editor whose first pane is a
+ # +Pager of stdin, as `vim -`; here a detached one, to read it.
+ outside_env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_')}
+ outside_env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), PARDES_NOTIME='1')
+ boot = subprocess.Popen([binary, '--detach=stdinboot', '-'], cwd=root, env=outside_env,
+ stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
+ start_new_session=True)
+ try:
+ boot.stdin.write(b'\x1b[32mfrom stdin\x1b[m\nsecond\n')
+ boot.stdin.close()
+ sock = root / 'pardes-9p-stdinboot.sock'
+ deadline = time.monotonic() + 10
+ while not sock.exists():
+ assert boot.poll() is None, boot.stderr.read()
+ assert time.monotonic() < deadline, 'the stdin boot never listened'
+ time.sleep(.05)
+ with Client(str(sock)) as booted:
+ first = booted.read('/index').split(b'\n')[0].split()
+ assert first[3] == f'{root}/+Pager'.encode(), first
+ assert booted.read(f'/pane/{first[0].decode()}/body') == b'from stdin\nsecond\n'
+ finally:
+ boot.terminate()
+ boot.wait(timeout=10)
+
# Killed with SIGTERM or SIGHUP, a tty editor puts its terminal
# back (main screen, cooked mode) before it dies: a nested one
# killed in a pane leaves that pane usable.