xtermjs / xterm.js

A terminal for the web
https://xtermjs.org/
MIT License
17.79k stars 1.64k forks source link

make extended cell attributes extendable #3489

Closed jerch closed 2 years ago

jerch commented 3 years ago

Coming from https://github.com/xtermjs/xterm.js/pull/2503. Also related https://github.com/xtermjs/xterm.js/pull/2904.

Extended attributes on cells offer a simply way of extending terminal buffer functionality for other purposes. Currently it is not possible to extend them in a flexible way to be used for custom data from addons.

TODO: Come up with an easy to interface to extend extended attributes from addons. Bonus goal - make this type safe even for runtime extensions (hard one with TS' static type system).

Tyriar commented 3 years ago

Related: https://github.com/xtermjs/xterm.js/issues/2919

jerch commented 3 years ago

@Tyriar Yeah the CellMarker idea is somewhat related. But I am not sure, whether to go that path at all - in the image addon I cancelled that idea and went with a viewport scan, which turned out to be fast enough for that purpose. CellMarker would certainly speedup those tasks, but would penalize the buffer logic at other ends.

jerch commented 2 years ago

Somewhat obsolete, thus closing.

jtbandes commented 1 week ago

Is there any way to do this now? I am interested in attaching custom attributes to cells (actually, whole lines of input).

I see that there is a registerMarker API, however:

Tyriar commented 1 week ago

It seems that markers cannot be reliably added due to async processing of input

@jtbandes see my response on https://github.com/xtermjs/xterm.js/issues/5214#issuecomment-2485981081

They don't offer a way to attach custom metadata/attributes

You can attach whatever data you want here, and modify the presentation of cells in a few ways (eg. hook into bg/fg rendering)

I would like to determine when a marked area is hovered with the mouse, and don't see a way to do that (OSC 8 links can be abused for this purpose, but the styling is not customizable)

If you want underline/italics/etc. this would be a new feature request to add to IDecorationOptions which sounds reasonable. You could hack this in a less bad way than OSC 8 links by adding border-bottom to the decoration.

jtbandes commented 1 week ago

Thanks for the tips and for your patience with my questions!

You can attach whatever data you want here

By "here", do you mean on the marker? I didn't see anything in the API or docs to indicate it is "safe"/expected to modify the IMarker object, but perhaps that's what you are suggesting?

(eg. hook into bg/fg rendering)

Could you expand on this – I don't see where cell rendering can be customized in the public API other than setting the theme options.

jerch commented 1 week ago

I didn't see anything in the API or docs to indicate it is "safe"/expected to modify the IMarker object, but perhaps that's what you are suggesting?

In the first place markers are just stable buffer line references into the terminal buffer. Their line number will mutate by various actions on the ringbuffer (index gets updated) to keep the referenced line stable. Eventually it gets disposed (e.g. buffer line drops off the scrollbuffer at the top). They are not meant be customized itself.

What you can do with markers - attach custom functionality to a certain buffer line. This can be used to a great extend for your custom logic, e.g. do something, when the marked line is in the viewport. Important here - your custom logic is typically is outside of the terminal itself / fully managed by your code. Example: the image addon uses markers to track images still present in the scrollbuffer. When the marked line gets disposed / drops off the scrollbuffer the addon also disposes the linked image data to free the memory again.

Tyriar commented 1 week ago

By "here", do you mean on the marker? I didn't see anything in the API or docs to indicate it is "safe"/expected to modify the IMarker object, but perhaps that's what you are suggesting?

@jtbandes using the IMarker object as a key in a Map for example: Map<IMarker, MyExtraAttributes>

Could you expand on this – I don't see where cell rendering can be customized in the public API other than setting the theme options.

See backgroundColor, foregroundColor and layer on IDecorationOptions:

https://github.com/xtermjs/xterm.js/blob/41e8ae395937011d6bf6c7cb618b851791aed395/typings/xterm.d.ts#L596-L615