-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Buffer API #2074
Buffer API #2074
Conversation
This is needed since the API/public buffer now differs from the TerminalCore's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍 , just two concerns from my side.
@Tyriar I think this is not an issue if we clearly document that ppl should avoid holding refs to members on nonlocal scope (rule of thumb - no event loop in between), instead always refer to them by the full descent like function someFunc() {
const line = terminal.buffer().getLine(y);
// iterate over cells
for (let x=0; 0 < line.length; ++x) {
someAction(line.getCell(x));
}
} While this might lead to unexpected results: function someFunc() {
const line = terminal.buffer().getLine(y);
// iterate over cells
for (let x=0; 0 < line.length; ++x) {
// by the time doSomethingWithCell is called
// line does not point to buffer[y] anymore
setTimeout(() => someAction(line.getCell(x)), timeout);
}
} The latter can be fixed like this (but leads to the intermediate object overhead): function someFunc() {
// iterate over cells
for (let x=0; 0 < terminal.cols; ++x) {
setTimeout(() => someAction(terminal.buffer().getLine(y).getCell(x)), timeout);
}
} |
@jerch I think this is fine if it's called out in the documentation as you mention, I'll add some more details to the jsdoc |
This exposes the primary parts of the buffer to APIs, see changes to xterm.d.ts for the actual public API. It works by having a "view" object in public/ that owns the actual object and exposes friendly aliases for the properties, for example
viewportY
instead ofydisp
,cursorX
overx
,getLine
overlines.get(x)
, etc.The first usage of this will be moving the search addon into the new addon API #2065, built 100% on stable API! The buffer API is currently marked experimental to make sure it meets the needs of the search addon, we can remove experimental at or before v4 #2075
Fixes #1994