From dbb2320e833ef51dde9c995336de56b6fc28d544 Mon Sep 17 00:00:00 2001 From: Paris Kasidiaris Date: Wed, 28 Mar 2018 10:22:42 +0300 Subject: [PATCH 1/3] Fix linting errors --- src/Terminal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index d1a266b2..7004954a 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -622,7 +622,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT // Create main element container this.element = this._document.createElement('div'); - this.element.dir = 'ltr'; //xterm.css assumes LTR + this.element.dir = 'ltr'; // xterm.css assumes LTR this.element.classList.add('terminal'); this.element.classList.add('xterm'); this.element.setAttribute('tabindex', '0'); From 516903e29ebc39d1d6dc0547559951a67003a75f Mon Sep 17 00:00:00 2001 From: Alexandre Petit-Pas Date: Tue, 27 Mar 2018 16:32:19 +0200 Subject: [PATCH 2/3] Handle blob in attach Addon I have added blob handler for the attach Addon. This allows to handle Docker with ws (works on Docker API v1.35) I have also added a callback to handle asynchronous FileReader. --- src/addons/attach/attach.ts | 44 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/addons/attach/attach.ts b/src/addons/attach/attach.ts index cbfd4a24..73aeb8d4 100644 --- a/src/addons/attach/attach.ts +++ b/src/addons/attach/attach.ts @@ -43,23 +43,37 @@ export function attach(term: Terminal, socket: WebSocket, bidirectional: boolean addonTerminal.__getMessage = function(ev: MessageEvent): void { let str; if (typeof ev.data === 'object') { - if (ev.data instanceof ArrayBuffer) { - if (!myTextDecoder) { - myTextDecoder = new TextDecoder(); - } - - str = myTextDecoder.decode( ev.data ); - } else { - throw 'TODO: handle Blob?'; + if (!myTextDecoder) { + myTextDecoder = new TextDecoder(); } - } - - if (buffered) { - addonTerminal.__pushToBuffer(str || ev.data); - } else { - addonTerminal.write(str || ev.data); - } + if (ev.data instanceof ArrayBuffer) { + str = myTextDecoder.decode( ev.data ); + displayData( str ); + } else { + let fileReader = new FileReader(); + fileReader.onload = function() { + str = myTextDecoder.decode( this.result ); + displayData( str ); + }; + fileReader.readAsArrayBuffer( ev.data ); + } + } }; + + /** + * Push data to buffer or write it in the terminal. + * This is used as a callback for FileReader.onload. + * + * @param str String decoded by FileReader. + * @param data The data of the EventMessage. + */ + function displayData(str?: string, data?: string) { + if (buffered) { + addonTerminal.__pushToBuffer(str || data); + } else { + addonTerminal.write(str || data); + } + } addonTerminal.__sendData = (data: string) => { if (socket.readyState !== 1) { From 63f711e634183a0e1ce06203b67f10a76326693c Mon Sep 17 00:00:00 2001 From: Paris Kasidiaris Date: Wed, 28 Mar 2018 10:57:21 +0300 Subject: [PATCH 3/3] Fix styling and make `string` messages to work again --- src/addons/attach/attach.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/addons/attach/attach.ts b/src/addons/attach/attach.ts index 73aeb8d4..b3b2e993 100644 --- a/src/addons/attach/attach.ts +++ b/src/addons/attach/attach.ts @@ -42,24 +42,30 @@ export function attach(term: Terminal, socket: WebSocket, bidirectional: boolean addonTerminal.__getMessage = function(ev: MessageEvent): void { let str; - if (typeof ev.data === 'object') { + + if (typeof ev.data == 'object') { if (!myTextDecoder) { myTextDecoder = new TextDecoder(); } if (ev.data instanceof ArrayBuffer) { - str = myTextDecoder.decode( ev.data ); - displayData( str ); + str = myTextDecoder.decode(ev.data); + displayData(str); } else { let fileReader = new FileReader(); - fileReader.onload = function() { - str = myTextDecoder.decode( this.result ); - displayData( str ); - }; - fileReader.readAsArrayBuffer( ev.data ); + + fileReader.addEventListener('load', function() { + str = myTextDecoder.decode(this.result); + displayData(str); + }); + fileReader.readAsArrayBuffer(ev.data); } - } + } else if (typeof ev.data == 'string') { + displayData(ev.data) + } else { + throw Error(`Cannot handle "${typeof ev.data}" websocket message.`); + } }; - + /** * Push data to buffer or write it in the terminal. * This is used as a callback for FileReader.onload.