Skip to content
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

make extended cell attributes extendable #3489

Closed
jerch opened this issue Sep 28, 2021 · 8 comments
Closed

make extended cell attributes extendable #3489

jerch opened this issue Sep 28, 2021 · 8 comments
Assignees
Labels
area/parser type/enhancement Features or improvements to existing features

Comments

@jerch
Copy link
Member

jerch commented Sep 28, 2021

Coming from #2503. Also related #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).

@jerch jerch added type/enhancement Features or improvements to existing features area/parser labels Sep 28, 2021
@jerch jerch self-assigned this Sep 28, 2021
This was referenced Sep 28, 2021
@Tyriar
Copy link
Member

Tyriar commented Oct 20, 2021

Related: #2919

@jerch
Copy link
Member Author

jerch commented Oct 20, 2021

@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
Copy link
Member Author

jerch commented Dec 8, 2021

Somewhat obsolete, thus closing.

@jerch jerch closed this as completed Dec 8, 2021
@jtbandes
Copy link
Contributor

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
Copy link
Member

Tyriar commented Nov 19, 2024

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

@jtbandes see my response on #5214 (comment)

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
Copy link
Contributor

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
Copy link
Member Author

jerch commented Nov 20, 2024

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
Copy link
Member

Tyriar commented Nov 20, 2024

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:

xterm.js/typings/xterm.d.ts

Lines 596 to 615 in 41e8ae3

/**
* The background color of the cell(s). When 2 decorations both set the
* foreground color the last registered decoration will be used. Only the
* `#RRGGBB` format is supported.
*/
readonly backgroundColor?: string;
/**
* The foreground color of the cell(s). When 2 decorations both set the
* foreground color the last registered decoration will be used. Only the
* `#RRGGBB` format is supported.
*/
readonly foregroundColor?: string;
/**
* What layer to render the decoration at when {@link backgroundColor} or
* {@link foregroundColor} are used. `'bottom'` will render under the
* selection, `'top`' will render above the selection\*.
*/
readonly layer?: 'bottom' | 'top';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/parser type/enhancement Features or improvements to existing features
Projects
None yet
Development

No branches or pull requests

3 participants