Skip to content

Commit 02ee2e9

Browse files
JanWielemakerclaude
andcommitted
FIXED: Windows: quitting the pager of help/1 left the screen cleared
A pager on Windows takes a screen buffer of its own from the console API, and the console swaps back to the previous one when it exits: that is what puts the terminal back as it was. A pseudo console does not carry those calls -- its alternate screen is the DEC private mode and nothing else -- so an Epilog window was left with whatever the pager had drawn on it. with_pager/1 now asks for the alternate screen itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VnmviTFXmNbwtckwLhxHvP
1 parent 20a39b4 commit 02ee2e9

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

library/help.pl

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@
352352
with_pager(Goal) :-
353353
pager_ok(Pager, Options),
354354
!,
355+
current_output(Screen),
356+
setup_call_cleanup(
357+
pager_screen(Screen, enter),
358+
paged(Pager, Options, Goal),
359+
pager_screen(Screen, leave)).
360+
with_pager(Goal) :-
361+
call(Goal).
362+
363+
paged(Pager, Options, Goal) :-
355364
Catch = error(io_error(_,_), _),
356365
current_output(OldIn),
357366
setup_call_cleanup(
@@ -364,8 +373,33 @@
364373
( set_output(OldIn),
365374
close(In, [force(true)])
366375
)).
367-
with_pager(Goal) :-
368-
call(Goal).
376+
377+
%! pager_screen(+Screen, +Which) is det.
378+
%
379+
% Give the pager a screen of its own, so that quitting it leaves the
380+
% terminal as it was. Windows only: a pager there takes a screen
381+
% buffer from the console API and the console swaps back to the
382+
% previous one when the pager exits, but a pseudo console -- which is
383+
% what an Epilog window gives its children -- does not carry those
384+
% calls. Its alternate screen is the DEC private mode and nothing
385+
% else, so the terminal is told here rather than by the pager.
386+
%
387+
% Elsewhere the pager does this itself, from its terminal description,
388+
% and a pager that does not (`cat`) is one whose output should stay.
389+
390+
pager_screen(_Screen, _Which) :-
391+
\+ current_prolog_flag(windows, true),
392+
!.
393+
pager_screen(Screen, _Which) :-
394+
\+ stream_property(Screen, tty(true)),
395+
!.
396+
pager_screen(Screen, enter) :-
397+
!,
398+
format(Screen, '\e[?1049h', []),
399+
flush_output(Screen).
400+
pager_screen(Screen, leave) :-
401+
format(Screen, '\e[?1049l', []),
402+
flush_output(Screen).
369403

370404
pager_ok(_Path, _Options) :-
371405
current_prolog_flag(help_pager, false),

0 commit comments

Comments
 (0)