From 4a71a413807526ca7d4cc8bf8699d5430694c911 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Jun 2016 18:01:34 -0700 Subject: [PATCH 1/3] Fix cursor blinking when enabled Fixes #119 --- src/xterm.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index 7f01e2a4..3be3244d 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1283,7 +1283,7 @@ }; Terminal.prototype._cursorBlink = function() { - if (Terminal.focus !== this) return; + if (document.activeElement !== this.element) return; this.cursorState ^= 1; this.refresh(this.y, this.y); }; @@ -1293,8 +1293,7 @@ this.cursorState = 1; this.refresh(this.y, this.y); } else { - // Temporarily disabled: - // this.refreshBlink(); + this.refreshBlink(); } }; From cb4728f8f5beb9b5459fa9d623ad98fa8a186ec6 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Jun 2016 18:05:24 -0700 Subject: [PATCH 2/3] Tidy up code --- src/xterm.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index 3be3244d..22106e5e 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1299,17 +1299,13 @@ Terminal.prototype.startBlink = function() { if (!this.cursorBlink) return; - var self = this; - this._blinker = function() { - self._cursorBlink(); - }; - this._blink = setInterval(this._blinker, 500); + this._blink = setInterval(this._cursorBlink.bind(this), 500); }; Terminal.prototype.refreshBlink = function() { if (!this.cursorBlink) return; clearInterval(this._blink); - this._blink = setInterval(this._blinker, 500); + this._blink = setInterval(this._cursorBlink.bind(this), 500); }; Terminal.prototype.scroll = function() { From 0d803ac895e33b48ade3d30a664c99787362401f Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 14 Jun 2016 10:52:49 -0700 Subject: [PATCH 3/3] Use CSS animations --- src/xterm.css | 15 +++++++++++++++ src/xterm.js | 28 +++++----------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/xterm.css b/src/xterm.css index 5a325ed9..1f49d690 100644 --- a/src/xterm.css +++ b/src/xterm.css @@ -57,6 +57,21 @@ background-color: transparent; } +.terminal .terminal-cursor.blinking { + animation: blink-cursor 1.2s infinite step-end; +} + +@keyframes blink-cursor { + 0% { + background-color: #fff; + color: #000; + } + 50% { + background-color: transparent; + color: #FFF; + } +} + /* * Determine default colors for xterm.js */ diff --git a/src/xterm.js b/src/xterm.js index 1ac384c8..a11c81ea 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -765,9 +765,6 @@ // Ensure there is a Terminal.focus. this.focus(); - // Start blinking the cursor. - this.startBlink(); - on(this.element, 'mouseup', function() { var selection = document.getSelection(), collapsed = selection.isCollapsed, @@ -1250,7 +1247,11 @@ } if (data !== this.defAttr) { if (data === -1) { - out += ''; + out += ''; } else { var classNames = []; @@ -1363,32 +1364,13 @@ this.emit('refresh', {element: this.element, start: start, end: end}); }; - Terminal.prototype._cursorBlink = function() { - if (document.activeElement !== this.element) return; - this.cursorState ^= 1; - this.refresh(this.y, this.y); - }; - Terminal.prototype.showCursor = function() { if (!this.cursorState) { this.cursorState = 1; this.refresh(this.y, this.y); - } else { - this.refreshBlink(); } }; - Terminal.prototype.startBlink = function() { - if (!this.cursorBlink) return; - this._blink = setInterval(this._cursorBlink.bind(this), 500); - }; - - Terminal.prototype.refreshBlink = function() { - if (!this.cursorBlink) return; - clearInterval(this._blink); - this._blink = setInterval(this._cursorBlink.bind(this), 500); - }; - Terminal.prototype.scroll = function() { var row;