Add support for the HPA escape sequence #4682

Closed
opened 2026-01-30 23:54:03 +00:00 by claunia · 4 comments
Owner

Originally created by @j4james on GitHub (Oct 27, 2019).

Description of the new feature/enhancement

HPA is an escape sequence for setting the horizontal cursor position.

Technically there is a distinction between HPA, which sets the data position, and CHA, which sets the presentation position (at least according to ECMA-048). However, I believe that only applies to bidirectional environments, and from what I've seen, it looks like most terminal emulators just treat them as synonyms.

Since we already support CHA, this doesn't really provide us with any new functionality, but it is one of the sequences tested by Vttest, so it would be nice to support, and it should be trivial to add.

Proposed technical implementation details (optional)

  1. Add a new entry in the VTActionCodes enum.
  2. Update the OutputStateMachineEngine::ActionCsiDispatch method to treat that new code as a synonym for the existing CHA_CursorHorizontalAbsolute.

If you care about tracking it as a separate telemetry entry, that would require a little more duplication of code, but it's still fairly trivial.

Originally created by @j4james on GitHub (Oct 27, 2019). # Description of the new feature/enhancement [`HPA`](https://vt100.net/docs/vt510-rm/HPA.html) is an escape sequence for setting the horizontal cursor position. Technically there is a distinction between `HPA`, which sets the data position, and [`CHA`](https://vt100.net/docs/vt510-rm/CHA.html), which sets the presentation position (at least according to ECMA-048). However, I believe that only applies to bidirectional environments, and from what I've seen, it looks like most terminal emulators just treat them as synonyms. Since we already support `CHA`, this doesn't really provide us with any new functionality, but it is one of the sequences tested by [Vttest](https://invisible-island.net/vttest/), so it would be nice to support, and it should be trivial to add. # Proposed technical implementation details (optional) 1. Add a new entry in the [`VTActionCodes`](https://github.com/microsoft/terminal/blob/08464648f280624023d3572346a75dee7a428de8/src/terminal/parser/OutputStateMachineEngine.hpp#L85) enum. 2. Update the [`OutputStateMachineEngine::ActionCsiDispatch`](https://github.com/microsoft/terminal/blob/a82d6b8c69f6e4b2fe946097da0e4c403cb42100/src/terminal/parser/OutputStateMachineEngine.cpp#L279) method to treat that new code as a synonym for the existing `CHA_CursorHorizontalAbsolute`. If you care about tracking it as a separate telemetry entry, that would require a little more duplication of code, but it's still fairly trivial.
Author
Owner

@egmontkob commented on GitHub (Oct 27, 2019):

However, I believe that only applies to bidirectional environments

Yes, this distinction is due to BiDi. ECMA's BiDi was designed way before the Unicode BiDi Algorithm, with apparently hardly any experience or prior art in the topic. There's no known implementation of ECMA 48 and TR/53's BiDi support I could find being even mentioned. As I detail in my revamped BiDi proposal, ECMA suffers from quite a few problems, including that the idea of doing any operation on the presentational component is just fundamentally broken.

So, using HPA would be the proper choice, as opposed to CHA which is used in practice.

Similarly, HPB and HPR instead of CUB and CUF. Interestingly, HPB is missing from VT510 (according to the doc you linked) and xterm doesn't implement it either.

None of these HP_s are implemented by VTE. VTE only implements HPA out of the HP_ ones.

I guess we'll just have to accept that CHA, CUB, CUF have become what HPA, HPB, HPR were designed to be, and it's unlikely to ever change. The fix would be to revise the documentation around the data vs. presentation components, and as a by-product of that, redefine CHA, CUB, CUF to operate on the data component (the only place where it makes sense to operate).

tested by Vttest

In which submenu exactly?

Let's note that the documentation you linked is obviously buggy, it says for HPA and HPR:

Inquire as to the amount of free memory for programmable key operations.

which is, like, what the heck?

@egmontkob commented on GitHub (Oct 27, 2019): > However, I believe that only applies to bidirectional environments Yes, this distinction is due to BiDi. ECMA's BiDi was designed way before the Unicode BiDi Algorithm, with apparently hardly any experience or prior art in the topic. There's no known implementation of ECMA 48 and TR/53's BiDi support I could find being even mentioned. As I detail in my revamped BiDi proposal, ECMA suffers from quite a few problems, including that the idea of doing _any_ operation on the presentational component is just fundamentally broken. So, using `HPA` would be the proper choice, as opposed to `CHA` which is used in practice. Similarly, `HPB` and `HPR` instead of `CUB` and `CUF`. Interestingly, `HPB` is missing from VT510 (according to the doc you linked) and xterm doesn't implement it either. ~~None of these `HP_`s are implemented by VTE.~~ VTE only implements `HPA` out of the `HP_` ones. I guess we'll just have to accept that `CHA`, `CUB`, `CUF` have become what `HPA`, `HPB`, `HPR` were designed to be, and it's unlikely to ever change. The fix would be to revise the documentation around the data vs. presentation components, and as a by-product of that, redefine `CHA`, `CUB`, `CUF` to operate on the data component (the only place where it makes sense to operate). > tested by Vttest In which submenu exactly? Let's note that the documentation you linked is obviously buggy, it says for `HPA` and `HPR`: > Inquire as to the amount of free memory for programmable key operations. which is, like, what the heck?
Author
Owner

@j4james commented on GitHub (Oct 28, 2019):

Similarly, HPB and HPR instead of CUB and CUF.

I was looking at those too (as well as VPB and VPR), but I didn't think they were exact synonyms for the CUx commands - I think there's a difference in the margin handling. I'll raise a separate issue for them once I have a better idea of how they're supposed to function (at least HPR and VPR - I don't really care about HPB and VPB).

tested by Vttest

In which submenu exactly?

Under Test non-VT100 there's a ISO-6429 cursor-movement section which includes the HPA test, and then there's also a VT520 section, which has a Cursor-movement subsection, which includes the HPA test.

Let's note that the documentation you linked is obviously buggy, it says for HPA and HPR:

Inquire as to the amount of free memory for programmable key operations.

Yeah I noticed that. There are a bunch of commands with that mistake - it's in the original PDF of the VT510 manual too. The mistake was fixed in the VT520/VT525 manual, but there's no HTML version of that, so it's not great for linking.

@j4james commented on GitHub (Oct 28, 2019): > Similarly, HPB and HPR instead of CUB and CUF. I was looking at those too (as well as VPB and VPR), but I didn't think they were exact synonyms for the CUx commands - I think there's a difference in the margin handling. I'll raise a separate issue for them once I have a better idea of how they're supposed to function (at least HPR and VPR - I don't really care about HPB and VPB). > > tested by Vttest > > In which submenu exactly? Under _Test non-VT100_ there's a _ISO-6429 cursor-movement_ section which includes the HPA test, and then there's also a _VT520_ section, which has a _Cursor-movement_ subsection, which includes the HPA test. > Let's note that the documentation you linked is obviously buggy, it says for HPA and HPR: > > > Inquire as to the amount of free memory for programmable key operations. Yeah I noticed that. There are a bunch of commands with that mistake - it's in the original PDF of the VT510 manual too. The mistake was fixed in the VT520/VT525 manual, but there's no HTML version of that, so it's not great for linking.
Author
Owner

@egmontkob commented on GitHub (Oct 28, 2019):

Whoops, I was wrong about VTE: It does support HPA and VPA, but not the rest.

as well as VPB and VPR), but I didn't think they were exact synonyms for the CUx commands - I think there's a difference in the margin handling

I'll double check VTE when you open that other issue with your margin handling findings (the VP_ ones ignoring the scrolling region?).

Thanks!

@egmontkob commented on GitHub (Oct 28, 2019): Whoops, I was wrong about VTE: It does support `HPA` and `VPA`, but not the rest. > as well as VPB and VPR), but I didn't think they were exact synonyms for the CUx commands - I think there's a difference in the margin handling I'll double check VTE when you open that other issue with your margin handling findings (the `VP_` ones ignoring the scrolling region?). Thanks!
Author
Owner

@ghost commented on GitHub (Nov 26, 2019):

:tada:This issue was addressed in #3368, which has now been successfully released as Windows Terminal Preview v0.7.3291.0.🎉

Handy links:

@ghost commented on GitHub (Nov 26, 2019): :tada:This issue was addressed in #3368, which has now been successfully released as `Windows Terminal Preview v0.7.3291.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.7.3291.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4682