How about removing text buffer from conhost #2425

Open
opened 2026-01-30 22:54:47 +00:00 by claunia · 0 comments
Owner

Originally created by @mcpiroman on GitHub (Jun 30, 2019).

Note that this is my understanding, please correct me if I'm wrong.

Currently when conhost acts as bridge between kernel and terminal (is in vt mode), both conhost and terminal have a TextBuffer. If there is an API call from app, then conhost executes it as it used to in window mode, possibly altering buffer, but instead of displaying the changes in the window it sends them to terminal via text/vt sequence.

While being niffty idea to reuse much code and clever use of polymorphism, I don't think it works so well:

  • It requires both buffers and other data to be kept in sync.
  • When one buffer changes, the other loses context of that change. E.g. when there is a resize (the issue I'm currently most concerned about.), the other buffer deletes its content and writes it anew, which prevents it from keeping track of the character position transitions. And this is very complicated and apparently error prone (#1465).
  • If it's not slow, at least it seems to be. Don't show it to linux users.

So I suggest that conhost should translate API calls directly to text/vt. I also summize that this was the first obvious idea, but then something... something I'd like to know and potentially conquer.

There are problematic API calls that don't have correspondig vt sequence. Like ReadConsoleOutput - it clearly has to access the buffer. So there should be another way of IPC between terminal and conhost, besides the two text/vt pipes. But it would need to be anyway and right now it even exists - signal pipe that currently only sends one type of message: resize event. For performace reasons conhost would probably still cache some data, but not entire text buffer.

Maybe buffer could be in shared memory with access from both terminal and conhost?

Let's discuss the issues which led us to current design and prevent from the one above. If it is still beneficial, at least leave some spec about this and someone from community 'd be likely to implemement it.

Originally created by @mcpiroman on GitHub (Jun 30, 2019). Note that this is my understanding, please correct me if I'm wrong. Currently when conhost acts as bridge between kernel and terminal (is in vt mode), both conhost and terminal have a `TextBuffer`. If there is an API call from app, then conhost executes it as it used to in window mode, possibly altering buffer, but instead of displaying the changes in the window it sends them to terminal via text/vt sequence. While being niffty idea to reuse much code and clever use of polymorphism, I don't think it works so well: - It requires both buffers and other data to be kept in sync. - When one buffer changes, the other loses context of that change. E.g. when there is a resize (the issue I'm currently most concerned about.), the other buffer deletes its content and writes it anew, which prevents it from keeping track of the character position transitions. And this is very complicated and apparently error prone (#1465). - If it's not slow, at least it seems to be. Don't show it to linux users. So I suggest that conhost should translate API calls directly to text/vt. I also summize that this was the first obvious idea, but then something... something I'd like to know and potentially conquer. There are problematic API calls that don't have correspondig vt sequence. Like `ReadConsoleOutput` - it clearly has to access the buffer. So there should be another way of IPC between terminal and conhost, besides the two text/vt pipes. But it would need to be anyway and right now it even exists - signal pipe that currently only sends one type of message: resize event. For performace reasons conhost would probably still cache some data, but not entire text buffer. Maybe buffer could be in shared memory with access from both terminal and conhost? Let's discuss the issues which led us to current design and prevent from the one above. If it is still beneficial, at least leave some spec about this and someone from community 'd be likely to implemement it.
claunia added the Issue-QuestionResolution-DuplicateArea-InteropProduct-Conpty labels 2026-01-30 22:54:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2425