-
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
Introduce Buffer and BufferSet classes #717
Conversation
src/InputHandler.ts
Outdated
this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 1); | ||
this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine()); | ||
this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollTop, 1); | ||
this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine()); | ||
} | ||
// this.maxRange(); | ||
this._terminal.updateRange(this._terminal.scrollTop); |
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.
this._terminal.ScrollTop and this._terminal.ScrollBottom seems should be in the buffer too.
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.
"ybase", "ydisp" and "lines" should be deleted from ITerminal, because it will be used from buffer.
Seems "cursorHidden", "cursorState", "defAttr" should be moved from ITerminal to the Buffer and restored after switching from alt buffer to normal buffer(and otherwise) => 1047, 47, 1049 in the InputHandler...
fbb6605
to
6643472
Compare
src/Buffer.ts
Outdated
* This class represents a terminal buffer (an internal state of the terminal)/ | ||
*/ | ||
export class Buffer { | ||
public lines: CircularList<string>; |
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.
FYI this is a CircularList<[string, number, string]>
. Also it will change soon, see #756
src/InputHandler.ts
Outdated
@@ -900,7 +900,7 @@ export class InputHandler implements IInputHandler { | |||
|
|||
// TODO: Why are params[0] compares nested within a switch for params[0]? | |||
|
|||
this._terminal.x10Mouse = params[0] === 9; | |||
this._terminal.buffer.x10Mouse = params[0] === 9; |
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.
@parisk Are you sure this line should be changed?
src/InputHandler.ts
Outdated
@@ -1094,7 +1078,7 @@ export class InputHandler implements IInputHandler { | |||
case 1000: // vt200 mouse | |||
case 1002: // button event mouse | |||
case 1003: // any event mouse | |||
this._terminal.x10Mouse = false; | |||
this._terminal.buffer.x10Mouse = false; |
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.
@parisk Are you sure this line should be changed?
src/Interfaces.ts
Outdated
defAttr: number; | ||
scrollback: number; | ||
buffers: any; // This should be a `BufferSet` class, but it would result in circular dependency |
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.
Let's use interfaces here so they're typed.
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.
I tried this and it displays a weird error that ICircularList
does not have a _length
attribute 😕.
I added the _length
attribute to ICircularList
and it displays an error that this is a private attribute .
I am not expert with these, so if you have any tip here it could help.
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.
Hmm, I would only expect that error if you added _length
to the interface.
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.
I fixed this up and pushed to this branch. The types were a bit messy, the list is actually a CircularList<[number, string, number][]>
😅
src/xterm.js
Outdated
@@ -242,21 +219,27 @@ function Terminal(options) { | |||
// leftover surrogate high from previous write invocation | |||
this.surrogate_high = ''; | |||
|
|||
// Create the terminal's buffers and set the current buffer | |||
this.buffers = new BufferSet(this); | |||
this.buffer = this.buffers.active; // Convenience shortcut; |
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.
I think this should note:
// TODO: Change to a getter when moved to TypeScript
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.
Are you aware if there any chances of this affecting performance if it becomes a getter since term.buffer
is being accessed quite frequently?
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.
It looks like getters should be pretty fast, this TS:
export class CircularList<T> extends EventEmitter {
...
public get maxLength(): number {
return this._array.length;
}
Compiles to:
var CircularList = (function (_super) {
...
Object.defineProperty(CircularList.prototype, "maxLength", {
get: function () {
return this._array.length;
},
src/xterm.js
Outdated
@@ -2301,9 +2284,13 @@ Terminal.prototype.reset = function() { | |||
this.options.cols = this.cols; | |||
var customKeyEventHandler = this.customKeyEventHandler; | |||
var cursorBlinkInterval = this.cursorBlinkInterval; | |||
var inputHandler = this.inputHandler; | |||
var buf = this.buffers; |
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.
Nit: this is the only one here that doesn't use the full name.
1 similar comment
Signed-off-by: Aleksandr Andriienko <oandriie@redhat.com>
This should be ready for a final review 😄. /cc @Tyriar |
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.
Looks good, just 1 small comment.
FYI in case you missed the comment above, I pushed to type IBuffer, IBufferSet and also fix up the type of CircularList<[number, string, number][]>
everywhere.
This should lead to some fun merge conflicts in #756 😛
src/xterm.js
Outdated
this.buffers.on('activate', function (buffer) { | ||
this._terminal.buffer = buffer; | ||
}); | ||
|
||
/** |
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.
This comment is no longer relevant, should be safe to remove as I'm going to heavily document the buffer format in #756
Also > 70% test coverage 🎉 |
This broke in xtermjs#717. Fixes xtermjs#818
This broke in xtermjs#717. Fixes xtermjs#818
This PR introduces the
Buffer
andBufferSet
classes to help:Buffer
class)normal
andalt
buffer (BufferSet
class)BufferSet
events)To-do
lines
withBuffer
everywhereBuffer
andBufferSet
classesBuffer
andBufferSet
classesThis will eventually help ship #613.