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

Fix #948 #1108

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const CHAR_DATA_ATTR_INDEX = 0;
export const CHAR_DATA_CHAR_INDEX = 1;
export const CHAR_DATA_WIDTH_INDEX = 2;
export const CHAR_DATA_CODE_INDEX = 3;
export const MAX_BUFFER_SIZE = -1 >>> 0; // 2^32 - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this works consistently across all browsers? Doing an unsigned bit operation on a signed number seems dangerous. Might be better to just stick the number in there.


/**
* This class represents a terminal buffer (an internal state of the terminal), where the
Expand Down Expand Up @@ -68,7 +69,10 @@ export class Buffer implements IBuffer {
if (!this._hasScrollback) {
return rows;
}
return rows + this._terminal.options.scrollback;

const correctBuferLength = rows + this._terminal.options.scrollback;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correctBuferLengthcorrectBufferLength

Also, is this here only to cover the case where scrollback is set from the Terminal constructor? If so it might be good to validate at in the Terminal constructor instead of every time _getCorrectBufferLength is requested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i first bumped into this was via terminal.setOption(), and if my understanding is correct we could also trigger this by resizing the terminal, and increasing the number of rows if the buffer size was MAX_BUFFER_SIZE.


return correctBuferLength > MAX_BUFFER_SIZE ? MAX_BUFFER_SIZE : correctBuferLength;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { BufferSet } from './BufferSet';
import { Buffer } from './Buffer';
import { Buffer, MAX_BUFFER_SIZE } from './Buffer';
import { CompositionHelper } from './CompositionHelper';
import { EventEmitter } from './EventEmitter';
import { Viewport } from './Viewport';
Expand Down Expand Up @@ -384,6 +384,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
}
break;
case 'scrollback':
value = value > 0 && value <= MAX_BUFFER_SIZE ? value : MAX_BUFFER_SIZE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.min would be preferable to this ternary, I was surprised how fast it was when I looked into it.


if (value < 0) {
console.warn(`${key} cannot be less than 0, value: ${value}`);
return;
Expand Down