-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copying HTML-formatted output #1883
Comments
@Eugeny does switching to the DOM renderer and copying the inner HTML of |
It should, but with the webgl renderer coming up, it might make sense to have a frontend-independent API for that. What do you think? |
I stumbled over this myself the other day when I tried to copy over a terminal page into a rich text editor (libreoffice). I kinda expected it to preserve the text attributes and the font (at least as monospaced), but it stripped all for any renderer. Maybe we need something like an optional rich text copy renderer? |
When we added this to VS Code the feature really annoyed me and many other users, the reason being it replaced ctrl+c and almost always personally I was non-formatted text. While the copy action does copy both text, it will always paste the rich text one into editors that support it. Downstream issue: microsoft/vscode#20813 |
@Tyriar: "While the copy action does copy both text, it will always paste the rich text one into editors that support it." When I've pasted into LibreOffice, in the past it has asked me if I wanted rich test. When I tried right now, it didn't - perhaps it remembers my previous choice and pasted rich text. DomTerm has a separate "CopyAsHtml" option, which creates html, but with the |
To be able to detach a terminal session, you need to be able to save (serialize) the terminal state in some fashion, and then restore it later. DomTerm saves the output as HTML, slightly cleaned up, along with JSON for other state. On a later attach, it re-creates the DOM (using It is not sure that that HTML is the best serialization format for xterm.js's output state, but it does have some advantages. |
@PerBothner it's not about serialization, it's about getting the content with the formatting included |
@Eugeny: "it's not about serialization, it's about getting the content with the formatting included" Of course. My point is that being able convert part or the whole the output buffer to HTML, could also be useful for serialization, and it might be useful to keep use-case in mind. |
fwiw, copying the innerHTML from the DomRenderer view does not work when the content is taller than the viewport. |
Is there any way to get all of the content of the terminal as a plain text? |
@XiaocongDong Plain text is already possible via API with |
Thanks jerch, another question on this term.buffer. Does this buffer have a limit? What happen if this buffer goes too large. Will some of the lines be removed? Thanks. |
@XiaocongDong The line buffer is a circular buffer with a max size of |
Thanks @jerch , that just answers my question. |
Current plan AFAIK is to enable supporting this eventually via an addon and the buffer API #2075 |
Opps, just duplicated this #3436 I don't think this meets the bar for a core feature and it aligns closely with what the serialize addon already does. Having the addon able to do this would enable embedders to route ctrl+c or a context menu to use it instead of regular copy. |
In case anyone fancies extracting it into an addon, here's the code: https://github.com/Eugeny/tabby/blob/4f244a126c30181862ebd29bb41261394ad71bf9/tabby-terminal/src/frontends/xtermFrontend.ts#L335-L390 |
To some degree it does actually the same as the serialize addon, but for different output formats (and slightly different needs). While the serialize addon currently only supports "terminal escape sequence text format", imho it makes sense to transform the addon into a more general output format thingy, maybe also for HTML/Richtext formats. (We discussed that with the initial addon PR, but the idea back then was to keep the code slim and not bloat with hypothetical use cases.) Further note, that all those serialize actions are in fact render actions, as they all would grab things a renderer has to push to the screen, but here instead into some data format. I am still a fan of the renderer API idea (wel thats mostly covered by the buffer API now, still I have to deal with several nasty private imports in the image addon for its image renderer). 😸 |
@Eugeny nice, btw I sent you an email |
@Tyriar already answered, check your spam :) |
fwiw, as part of Kui from the Kubernetes SIG-CLI, we have code that exports the xterm Buffer model to an This includes squashing down contiguous cells with identical styling, and handling line wrapping. |
@starpit Eww, your sameStyle function would have been a one-liner (2 uint32 mask & compare operations), if we would not try so hard to hide the internal buffer layout behind "convenience" (in fact creating inconvenience and a runtime penalty here) 😊 |
lol, yeah that was painful to write. |
@jerch maybe we should just expose the raw fg/bg numbers and add some things to watch out for in the jsdoc |
@Tyriar Yeah that would do. As long as the shape of fg/bg as a bit compound gets explained, ppl can use it. It has a small drawback though - if we ever reshape things internally, we'd have to provide those fields explicitly, prolly as getter. But thats not a biggy either. |
Yeah one of the caveats I had in mind was compatibility across xterm.js versions is not guaranteed. |
Please consider adding an API to copy terminal contents as a HTML string.
The text was updated successfully, but these errors were encountered: