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

Introduce Buffer and BufferSet classes #717

Merged
merged 26 commits into from Jul 16, 2017
Merged

Introduce Buffer and BufferSet classes #717

merged 26 commits into from Jul 16, 2017

Conversation

parisk
Copy link
Contributor

@parisk parisk commented Jun 19, 2017

This PR introduces the Buffer and BufferSet classes to help:

  1. Organize all buffer information into a single place (Buffer class)
  2. Manage a set of normal and alt buffer (BufferSet class)
  3. Know when a buffer gets activated (BufferSet events)

To-do

  • Replace usage of lines with Buffer everywhere
  • Get existing tests work
  • Write tests for Buffer and BufferSet classes
  • Document Buffer and BufferSet classes

This will eventually help ship #613.

@parisk parisk added the work-in-progress Do not merge label Jun 19, 2017
@parisk parisk added this to the 2.8.0 milestone Jun 19, 2017
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);
Copy link
Contributor

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.

Copy link
Contributor

@AndrienkoAleksandr AndrienkoAleksandr left a 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...

AndrienkoAleksandr added a commit to AndrienkoAleksandr/xterm.js that referenced this pull request Jun 21, 2017
@Tyriar Tyriar mentioned this pull request Jun 21, 2017
10 tasks
@parisk parisk force-pushed the buffer-set branch 2 times, most recently from fbb6605 to 6643472 Compare June 30, 2017 10:20
@parisk parisk modified the milestones: 2.9.0, 2.8.0 Jul 3, 2017
src/Buffer.ts Outdated
* This class represents a terminal buffer (an internal state of the terminal)/
*/
export class Buffer {
public lines: CircularList<string>;
Copy link
Member

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

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

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?

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

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?

defAttr: number;
scrollback: number;
buffers: any; // This should be a `BufferSet` class, but it would result in circular dependency
Copy link
Member

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.

Copy link
Contributor Author

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 :trollface:.

I am not expert with these, so if you have any tip here it could help.

Copy link
Member

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.

Copy link
Member

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

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

Copy link
Contributor Author

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?

Copy link
Member

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

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.

@coveralls
Copy link

coveralls commented Jul 14, 2017

Coverage Status

Coverage increased (+0.3%) to 69.832% when pulling 6b98ef2 on buffer-set into 7cfc2ff on master.

@coveralls
Copy link

coveralls commented Jul 14, 2017

Coverage Status

Coverage increased (+0.3%) to 69.832% when pulling 575577e on buffer-set into 7cfc2ff on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 69.832% when pulling 575577e on buffer-set into 7cfc2ff on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 69.832% when pulling 575577e on buffer-set into 7cfc2ff on master.

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage increased (+0.3%) to 69.784% when pulling f840997 on buffer-set into c94fdae on master.

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage increased (+0.7%) to 70.145% when pulling 1a2e3fb on buffer-set into c94fdae on master.

@parisk parisk removed the work-in-progress Do not merge label Jul 15, 2017
@parisk
Copy link
Contributor Author

parisk commented Jul 15, 2017

This should be ready for a final review 😄. /cc @Tyriar

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage increased (+0.7%) to 70.145% when pulling c27431b on buffer-set into c94fdae on master.

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage increased (+0.7%) to 70.145% when pulling c27431b on buffer-set into c94fdae on master.

Copy link
Member

@Tyriar Tyriar left a 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;
});

/**
Copy link
Member

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

@Tyriar
Copy link
Member

Tyriar commented Jul 15, 2017

Also > 70% test coverage 🎉

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage increased (+0.7%) to 70.145% when pulling c27431b on buffer-set into c94fdae on master.

@coveralls
Copy link

coveralls commented Jul 16, 2017

Coverage Status

Coverage increased (+0.7%) to 70.145% when pulling 4cefa34 on buffer-set into c94fdae on master.

@parisk parisk merged commit 48dab49 into master Jul 16, 2017
@parisk parisk deleted the buffer-set branch July 16, 2017 00:47
Tyriar added a commit to Tyriar/xterm.js that referenced this pull request Jul 27, 2017
Tyriar added a commit to Tyriar/xterm.js that referenced this pull request Jul 27, 2017
cheton added a commit to cncjs/cncjs that referenced this pull request Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants