Skip to content

Terminal should provide API to notify data cleaned by control sequences #29840

Closed

Description

I noticed that the terminal no sends Operating System Commands (OSC) like setting the window title. Right now the task runner filters them but this gets more and more complex and I am actually not an expert with this. So I would like to request that the terminal provides API to notify data without control sequences. Currently I used these two regular expressions to filter them:

	private static ANSI_CONTROL_SEQUENCE: RegExp = /\x1b[[()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
	private static OPERATING_SYSTEM_COMMAND_SEQUENCE: RegExp = /\x1b[\]](?:.*)(?:\x07|\x1b\\)/g;

Activity

  1. added
    terminal
    feature-request
    and removed on Jun 29, 2017
  2. Tyriar commented on Jun 29, 2017

    @Tyriar
    Contributor

    There are two unknowns to me right now with this:

    • Various control sequences can do a whole lot of stuff, so where is the best place to gather this data? It might be worth seeing if adding listeners to addChar and lineFeed will give what you need.
    • How do this efficiently. Because a lot of data can stream through the terminal, we should probably only enable this when it's explicitly requested (ie. only fire the event if something is listening). It should probably also be batched.

    PR welcome upstream.

  3. added
    upstream
    on Jun 29, 2017
  4. added this to the Backlog milestone on Jun 29, 2017
  5. dbaeumer commented on Jun 30, 2017

    @dbaeumer
    MemberAuthor

    From a problem matcher point of view it would be enough sending the line. We could sent it when a linefeed is added. Then there is still the problem of a line content changing. We once discussed the idea of a line identifier to signal that. I agree that sending single characters might not be a smart idea in terms of performance.

  6. Tyriar commented on Jun 30, 2017

    @Tyriar
    Contributor

    If it's just on line feed then many characters could go missing, eg. "abc" "def" would result in "def" only. Maybe this is not something we care about, but it could lead to some obscure bugs if people relied on this new API.

  7. dbaeumer commented on Jul 6, 2017

    @dbaeumer
    MemberAuthor

    This is a good example why something like a line model would be helpful: #22065 (comment).

    After looking into the issue it looks like that pester constantly 'repaints' the whole screen hence the terminal sending the same line onData over and over again. For me it is very hard to tell whether I have seen that line and whether I have processed it already (the same content). What would be cool if the terminal could provide a line model where is line has an id (number) and changes are signaled on that model instead of sending raw data.

  8. Tyriar commented on Jul 6, 2017

    @Tyriar
    Contributor

    Dirk Bäumer (@dbaeumer) I actually added an ID concept to the buffer when doing the selection stuff (xtermjs/xterm.js@65256c8) but I ended up not needing it and pulling it out, instead the selection listens to when the buffer is trimmed and adjusts the indexes of its own model.

    It really didn't feel very good adding it as it introduced much more complexity to the already complex circular list and added the overhead of an addition object for every entry - which is a lot when you need to create tens of thousands of these things in an instant. There were other issues that come up with this like IDs being interleaved due to programs having the ability to delete/insert lines so there's no way I could think of to optimize it nicely, leading to a slower, more memory hungry terminal.

    It would probably be easier and more performant to just deduplicate these errors on your end. For example you could record a hash for current problems and check it before adding new problems, or perhaps even better, record the raw terminal line of the error so you don't need to parse it again for duplicate problems.

  9. dbaeumer commented on Jul 7, 2017

    @dbaeumer
    MemberAuthor

    I implemented the deduplicate yesterday but it feels like a hack on my side :-) I need to create a unique key for something that doesn't necessarily have one. I still think having a line bassed model comparable to what the editor exposes would be a nice thing. Me giving the raw data is comparable to the editor signaling raw cursor moves and text changes. Instead I get a nice model with text edit events. And I am not interested in color information like I am not interested in this on an editor buffer.

  10. dbaeumer commented on Jul 7, 2017

    @dbaeumer
    MemberAuthor

    Just for the record. I can not filter on the line itself from the terminal without knowing if I have parsed that line already. Matchers are multiline aware and there could be two equal lines in one output on purpose since they difference is made by a line above. Me knowing this is implementing a line model on top of it :-)

  11. Tyriar commented on Jul 7, 2017

    @Tyriar
    Contributor

    Dirk Bäumer (@dbaeumer) isn't the point of programs rewriting lines that the lines do change and that they may need to be reparsed?

    Here's one idea that might work for both of us: exposing some data stream you can listen to as in the original comment, but only ever pushing data if it's on the last line in the terminal. Would this cover your use case? For the PS case #22065 (comment) you would get multiple lines for the last line but maybe this could be more clever somehow in recording when the cursor moves and only reporting the line a single time (not by using IDs but by only reporting once after a lineFeed call inserts a new line.

  12. 2 remaining items

  13. dbaeumer commented on Jul 12, 2017

    @dbaeumer
    MemberAuthor

    Daniel Imms (@Tyriar) thanks a lot for the detailed explanation. Having solution 2 will for sure make my life easier and will not make things worse on my end. Regarding option 3: I am not interested in the view model since I need lines unwrapped. The line model is what would work best for me assuming that the line model doesn't have any \n in there to make lines visually wrap .

  14. Tyriar commented on Jul 12, 2017

    @Tyriar
    Contributor

    Dirk Bäumer (@dbaeumer) option 3 including reflow xtermjs/xterm.js#644 (comment) is required in order to get unwrapped lines

    Not sure when I'll have time to work on this, pretty swamped atm. It might be a good opportunity to collaborate if this is high priority for you?

  15. dbaeumer commented on Jul 13, 2017

    @dbaeumer
    MemberAuthor

    Daniel Imms (@Tyriar) I will be out on vacation until 2. August. I think we need to address this sooner than later since we can't assume that problems always fit onto one line.

    An interims solution could be as follows: can we introduce a custom control sequence (e.g. a operating system control sequence) that describes the new lines inserted to wrap the text. I could then filter them on my end since I would be able to distinguish them from normal newline. Would this be something you can add in July then I would catchup with it for the July build ?

  16. Tyriar commented on Jul 13, 2017

    @Tyriar
    Contributor

    Dirk Bäumer (@dbaeumer) I actually expect you to get the unwrapped lines currently, xterm.js just wraps the lines when they are going to overflow https://github.com/sourcelair/xterm.js/blob/2ebc926f4e438c77c4da702b14f82f46424120a8/src/InputHandler.ts#L55, that's the only wrapping it knows about.

    On Windows though I'm not sure rows are ever marked to be wrapped (not 100% sure), at least on PowerShell. This is just how winpty works.

  17. removed
    upstream
    on Oct 26, 2017
  18. added a commit that references this issue on Oct 26, 2017
    8bf87ab
  19. added
    debt
    on Oct 30, 2017
  20. removed
    feature-request
    on Nov 1, 2017
  21. locked and limited conversation to collaborators on Dec 10, 2017
  22. added a commit that references this issue on Sep 6, 2026
    dc36feb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debtterminal

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions