Rerender cursor if state changes
This commit is contained in:
@@ -61,13 +61,6 @@ const WRITE_BUFFER_PAUSE_THRESHOLD = 5;
|
|||||||
*/
|
*/
|
||||||
const WRITE_BATCH_SIZE = 300;
|
const WRITE_BATCH_SIZE = 300;
|
||||||
|
|
||||||
/**
|
|
||||||
* The time between cursor blinks. This is driven by JS rather than a CSS
|
|
||||||
* animation due to a bug in Chromium that causes it to use excessive CPU time.
|
|
||||||
* See https://github.com/Microsoft/vscode/issues/22900
|
|
||||||
*/
|
|
||||||
const CURSOR_BLINK_INTERVAL = 600;
|
|
||||||
|
|
||||||
// TODO: Most of the color code should be removed after truecolor is implemented
|
// TODO: Most of the color code should be removed after truecolor is implemented
|
||||||
// Colors 0-15
|
// Colors 0-15
|
||||||
const tangoColors: string[] = [
|
const tangoColors: string[] = [
|
||||||
@@ -197,10 +190,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
|
|
||||||
private sendDataQueue: string;
|
private sendDataQueue: string;
|
||||||
private customKeyEventHandler: CustomKeyEventHandler;
|
private customKeyEventHandler: CustomKeyEventHandler;
|
||||||
// The ID from a setInterval that tracks the blink animation. This animation
|
|
||||||
// is done in JS due to a Chromium bug with CSS animations that thrashed the
|
|
||||||
// CPU.
|
|
||||||
private cursorBlinkInterval: NodeJS.Timer;
|
|
||||||
|
|
||||||
// modes
|
// modes
|
||||||
public applicationKeypad: boolean;
|
public applicationKeypad: boolean;
|
||||||
@@ -341,7 +330,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.cursorHidden = false;
|
this.cursorHidden = false;
|
||||||
this.sendDataQueue = '';
|
this.sendDataQueue = '';
|
||||||
this.customKeyEventHandler = null;
|
this.customKeyEventHandler = null;
|
||||||
this.cursorBlinkInterval = null;
|
|
||||||
|
|
||||||
// modes
|
// modes
|
||||||
this.applicationKeypad = false;
|
this.applicationKeypad = false;
|
||||||
@@ -488,12 +476,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this[key] = value;
|
this[key] = value;
|
||||||
this.options[key] = value;
|
this.options[key] = value;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'cursorBlink': this.setCursorBlinking(value); break;
|
|
||||||
case 'cursorStyle':
|
|
||||||
this.element.classList.toggle(`xterm-cursor-style-block`, value === 'block');
|
|
||||||
this.element.classList.toggle(`xterm-cursor-style-underline`, value === 'underline');
|
|
||||||
this.element.classList.toggle(`xterm-cursor-style-bar`, value === 'bar');
|
|
||||||
break;
|
|
||||||
case 'fontFamily':
|
case 'fontFamily':
|
||||||
case 'fontSize':
|
case 'fontSize':
|
||||||
// When the font changes the size of the cells may change which requires a renderer clear
|
// When the font changes the size of the cells may change which requires a renderer clear
|
||||||
@@ -511,28 +493,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.renderer.onOptionsChanged();
|
this.renderer.onOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private restartCursorBlinking(): void {
|
|
||||||
this.setCursorBlinking(this.options.cursorBlink);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setCursorBlinking(enabled: boolean): void {
|
|
||||||
this.element.classList.toggle('xterm-cursor-blink', enabled);
|
|
||||||
this.clearCursorBlinkingInterval();
|
|
||||||
if (enabled) {
|
|
||||||
this.cursorBlinkInterval = setInterval(() => {
|
|
||||||
this.element.classList.toggle('xterm-cursor-blink-on');
|
|
||||||
}, CURSOR_BLINK_INTERVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private clearCursorBlinkingInterval(): void {
|
|
||||||
this.element.classList.remove('xterm-cursor-blink-on');
|
|
||||||
if (this.cursorBlinkInterval) {
|
|
||||||
clearInterval(this.cursorBlinkInterval);
|
|
||||||
this.cursorBlinkInterval = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds the desired focus behavior on a given terminal object.
|
* Binds the desired focus behavior on a given terminal object.
|
||||||
*/
|
*/
|
||||||
@@ -542,7 +502,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
}
|
}
|
||||||
this.element.classList.add('focus');
|
this.element.classList.add('focus');
|
||||||
this.showCursor();
|
this.showCursor();
|
||||||
this.restartCursorBlinking.apply(this);
|
|
||||||
this.emit('focus');
|
this.emit('focus');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -563,7 +522,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.send(C0.ESC + '[O');
|
this.send(C0.ESC + '[O');
|
||||||
}
|
}
|
||||||
this.element.classList.remove('focus');
|
this.element.classList.remove('focus');
|
||||||
this.clearCursorBlinkingInterval.apply(this);
|
|
||||||
this.emit('blur');
|
this.emit('blur');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,8 +654,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.element = this.document.createElement('div');
|
this.element = this.document.createElement('div');
|
||||||
this.element.classList.add('terminal');
|
this.element.classList.add('terminal');
|
||||||
this.element.classList.add('xterm');
|
this.element.classList.add('xterm');
|
||||||
this.element.classList.add(`xterm-cursor-style-${this.options.cursorStyle}`);
|
|
||||||
this.setCursorBlinking(this.options.cursorBlink);
|
|
||||||
|
|
||||||
this.element.setAttribute('tabindex', '0');
|
this.element.setAttribute('tabindex', '0');
|
||||||
|
|
||||||
@@ -1462,8 +1418,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.restartCursorBlinking();
|
|
||||||
|
|
||||||
if (!this.compositionHelper.keydown(ev)) {
|
if (!this.compositionHelper.keydown(ev)) {
|
||||||
if (this.buffer.ybase !== this.buffer.ydisp) {
|
if (this.buffer.ybase !== this.buffer.ydisp) {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
@@ -2171,12 +2125,10 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
this.options.rows = this.rows;
|
this.options.rows = this.rows;
|
||||||
this.options.cols = this.cols;
|
this.options.cols = this.cols;
|
||||||
const customKeyEventHandler = this.customKeyEventHandler;
|
const customKeyEventHandler = this.customKeyEventHandler;
|
||||||
const cursorBlinkInterval = this.cursorBlinkInterval;
|
|
||||||
const inputHandler = this.inputHandler;
|
const inputHandler = this.inputHandler;
|
||||||
const buffers = this.buffers;
|
const buffers = this.buffers;
|
||||||
this.setup();
|
this.setup();
|
||||||
this.customKeyEventHandler = customKeyEventHandler;
|
this.customKeyEventHandler = customKeyEventHandler;
|
||||||
this.cursorBlinkInterval = cursorBlinkInterval;
|
|
||||||
this.inputHandler = inputHandler;
|
this.inputHandler = inputHandler;
|
||||||
this.buffers = buffers;
|
this.buffers = buffers;
|
||||||
this.refresh(0, this.rows - 1);
|
this.refresh(0, this.rows - 1);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { COLOR_CODES } from './ColorManager';
|
|||||||
const BLINK_INTERVAL = 600;
|
const BLINK_INTERVAL = 600;
|
||||||
|
|
||||||
export class CursorRenderLayer extends BaseRenderLayer {
|
export class CursorRenderLayer extends BaseRenderLayer {
|
||||||
private _state: [number, number];
|
private _state: [number, number, string];
|
||||||
private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void};
|
private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void};
|
||||||
private _cursorBlinkStateManager: CursorBlinkStateManager;
|
private _cursorBlinkStateManager: CursorBlinkStateManager;
|
||||||
private _isFocused: boolean;
|
private _isFocused: boolean;
|
||||||
@@ -118,7 +118,10 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
|
|
||||||
if (this._state) {
|
if (this._state) {
|
||||||
// The cursor is already in the correct spot, don't redraw
|
// The cursor is already in the correct spot, don't redraw
|
||||||
if (this._state[0] === terminal.buffer.x && this._state[1] === viewportRelativeCursorY) {
|
if (this._state[0] === terminal.buffer.x &&
|
||||||
|
this._state[1] === viewportRelativeCursorY &&
|
||||||
|
this._state[2] === terminal.options.cursorStyle) {
|
||||||
|
// TODO: Ideally cursorStyle would be stored as a number here to prevent the string compare
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._clearCursor();
|
this._clearCursor();
|
||||||
@@ -128,7 +131,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
||||||
this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
||||||
this._ctx.restore();
|
this._ctx.restore();
|
||||||
this._state = [terminal.buffer.x, viewportRelativeCursorY];
|
this._state = [terminal.buffer.x, viewportRelativeCursorY, terminal.options.cursorStyle];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _clearCursor(): void {
|
private _clearCursor(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user