Skip to content

Conversation

@davidrg
Copy link
Owner

@davidrg davidrg commented Oct 18, 2025

The primary goal of this PR is to implement the Xterm alternate screen, something that all other terminals maintained in the last 20 years support now. But as that is really just a subset of the VT paging feature, thats being implmented here too with the Xterm alternate screen implemented as an additional page with some special rules around it (can't get to/from it via VT paging control sequences, etc).

While the changes involved are much more extensive than the last attempt at the alternate screen feature (#244), I think crossing off another VT420 feature is worth it plus there should be less opportunity for weird bugs and unnoticed array out-of-bounds problems than trying to add a second terminal vscreen and trying to make them both share a single input queue, etc.

While K95 does emulate other terminals that support paging (WY370 at least), paging support won't be attempted for those at the moment due to both a lack of hardware and software to test against, and a lack of users to report bugs.

Implementation:

  • The great paging refactor to support multiple pages per vscreen, and separate view and cursor pages
  • xterm alternate screen - modes 1046, 1047, 1048, 1049 and terminfo file updated
  • NP, PP, PPA, PPR, PPB
  • Page Cursor Coupling - implemented, but only given a basic test
  • Make margins page-specific
  • DECCRA - support source and destination pages, and while we're there make it work properly: copy attributes, and obey DECOM
  • DECRQCRA - support page number
  • DECSPMA - set number of pages available
  • MC - print cursor page, print screen, print all pages
  • Try to avoid dirtying the vscrn for changes made to pages in the background - no point triggering a repaint if the page on screen hasn't changed
  • Check over documentation and notes to see if there are any other settings that should be page-specific
  • Consider commands to set the number of pages (and only allocate memory for the number required)
  • Show current page in status bar when not on page 1
  • Update control sequences documentation to discuss paging features in more detail

And Testing - in particular make sure having the cursor on some other page with PCCM disabled doesn't break things that should act on the view page:

  • Save scrollback
  • Clear terminal, clear scrollback
  • Search
  • Set bookmark
  • Goto bookmark
  • Reverse screen
  • Status line updating while viewing scrollback
  • mark mode, copy (both via keyboard and with mouse)
  • hyperlinks (whatever VscrnURL does)
  • Printing (esp. DECMC-10 and DECMC-11)
  • Enlarge scrollback - looks like this got broken in the 24bit color work months back, but easier to fix on this branch
  • Try to find some existing software that actually uses VT paging
  • Review all the code changes to ensure everything at least appears reasonable (the final review of the 24-bit color work caught a few things)

These changes *should* be enough to support implementing both xterms alternate screen, and DECs page memory extension. Might be enough to implement paging support for other terminals that have such a feature too.

These changes have only been tested to the extent that the xterm alternate screen feature needs them - there may well be bugs that turn up when page cursor coupling is turned off.

Allocating a bunch of pages for VTERM whether or not the current terminal emulation supports them is a bit wasteful on memory too. Would be nice to have a SET TERM PAGES command or similar. *Ideally* pages would only be allocated when first used too, but the way VscrnSetBufferSize works makes that too difficult right now.
This should implement all of xterms alternate screen feature except for DECSET-47 as that conflicts with DECGRCM and I've not decided yet which of the two definitions for this mode I'd like the K95 terminal type to implement.

It has been lightly tested and seems to work OK. Behaviour for all four modes seems to match xterm. Due to the nature of the change, and the significant set of changes to enable paging that this is built on, it could really do with some solid testing.

Closes #231
@davidrg davidrg linked an issue Oct 18, 2025 that may be closed by this pull request
@davidrg davidrg mentioned this pull request Oct 18, 2025
5 tasks
I didn't really like that macro anyway...
when switching away from page 0. For some reason this didn't seem to happen when switching to the alternate buffer which is odd. Perhaps related to the issue where the horizontal scrollbar would partially come to life for some non-obvious reason. Not sure what is special about page 10 to cause that.
Kermit 95 can now move around the available pages. These control sequences are not available while on the alternate screen, and they can not be used to access the alternate screen (which is really just a bonus page that's treated specially).
Seems to work OK in my brief testing. More extensive testing will be required later to ensure all of the various functions like mark/copy, search, etc, still work while the cursor is on a different page from the one on screen.
We support enough of it now that its probably reasonable to do this, and the remaining bits that aren't supported will follow along soon.
@davidrg davidrg changed the title Alternate Screen Buffer and some work towards VT Paging Alternate Screen and VT paging Oct 18, 2025
@davidrg davidrg linked an issue Oct 18, 2025 that may be closed by this pull request
And, while I'm here, also make it work properly: it should now respect DECOM, and also copy attributes.

The demo script has also been updated to make use of both per-page margins and DECCRA to copy a string from another page. Conveniently with the exception of colour and the strike-through attribute Kermit 95 matches what my VT520 does, while every other terminal is broken in some way.
As Kermit 95 doesn't support multiple sessions, this currently just restricts the number of pages available to applications. It can be requested via DECRQSS.
Print Composed Main Display, and Print All Pages.
Should have tested that commit first...
This should speed up changes to background page slightly. I've only bothered making this change to control sequences that are implemented by a VT420 or similar - a few SCO and ANSI control sequences were left alone.

Also fixed the scrollback getting disabled when the cursor was on a different page while PCCM wasoff.
No point wasting memory allocating 10 pages if the user is just emulating something like an H19 which only has one.
But only when its not on page 1, and show an 'A' when its on the alternate screen. This required enlarging the panel in the status bar slightly.
While this isn't really intended as a kind of torture test, its nice if it happens to show VT features that K95 implements properly that other terminals get wrong. And every other terminal I have handy gets at least *something* wrong here - only K95 and my trusty VT520 can do it properly (though of course without colour on the VT520)
SET TERM PAGE can be used to change the cursor page, turn page cursor coupling on/off, and to set the total number of available pages.
Not really related to paging, but it is part of the windowing feature and its easy to do. Reduced a bit of duplicate code in the process.
As it *really* breaks stuff in most terminals, and its a bit unfair as most don't even attempt to implement it.

Rectangular area options, which also breaks stuff in most terminals surprisingly, is still always on.
Otherwise, if the terminal is viewing scroll back when switching to another page you end up with a blank terminal
This was probably also an issue if the remote host turned off the cursor - it would also end up being turned off during mark mode making it rather difficult to use.
Sometimes when switching pages the console mode renderer wasn't refreshing the screen until some other event (eg, a keypress) set the dirty flag again. Adding a brief pause after switching pages seems to help.
with the way DECSSDT works for the VT520 and K95 terminal types. This fixes the temporary status line not appear when the status line has been turned off via command rather than DECSSDT.
Because I do not fully understand why the previous version did not work in 24bit colour builds. But this seems to work correctly, so it will do until this whole function is eventually rewritten to be more reasonable.
Mostly making sure consistent use of page numbers.
about an undeclared function. Could cause issues on 64bit windows.
@davidrg davidrg marked this pull request as ready for review October 24, 2025 09:23
@davidrg davidrg merged commit 61a2617 into master Oct 24, 2025
32 checks passed
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.

VT420 Page memory Alternate screen buffer

3 participants