From 27389dc7d4aacc15a6201621fb793b3e1027f46e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 4 Oct 2023 14:22:35 +0200 Subject: Adding upstream version 1.7.4. Signed-off-by: Daniel Baumann --- html/src/components/app.tsx | 1 + html/src/components/terminal/xterm/addons/zmodem.ts | 16 ++++++++++++++++ html/src/components/terminal/xterm/index.ts | 19 +++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) (limited to 'html/src/components') diff --git a/html/src/components/app.tsx b/html/src/components/app.tsx index 71a2d89..1ad5fd3 100644 --- a/html/src/components/app.tsx +++ b/html/src/components/app.tsx @@ -15,6 +15,7 @@ const clientOptions = { enableZmodem: false, enableTrzsz: false, enableSixel: false, + isWindows: false, } as ClientOptions; const termOptions = { fontSize: 13, diff --git a/html/src/components/terminal/xterm/addons/zmodem.ts b/html/src/components/terminal/xterm/addons/zmodem.ts index 3d38c5c..8571f68 100644 --- a/html/src/components/terminal/xterm/addons/zmodem.ts +++ b/html/src/components/terminal/xterm/addons/zmodem.ts @@ -7,6 +7,7 @@ import { TrzszFilter } from 'trzsz'; export interface ZmodeOptions { zmodem: boolean; trzsz: boolean; + windows: boolean; onSend: () => void; sender: (data: string | Uint8Array) => void; writer: (data: string | Uint8Array) => void; @@ -54,6 +55,11 @@ export class ZmodemAddon implements ITerminalAddon { this.terminal.focus(); } + private addDisposableListener(target: EventTarget, type: string, listener: EventListener) { + target.addEventListener(type, listener); + this.disposables.push({ dispose: () => target.removeEventListener(type, listener) }); + } + @bind private trzszInit() { const { terminal } = this; @@ -68,6 +74,16 @@ export class ZmodemAddon implements ITerminalAddon { }, sendToServer: data => sender(data), terminalColumns: terminal.cols, + isWindowsShell: this.options.windows, + }); + const element = terminal.element as EventTarget; + this.addDisposableListener(element, 'dragover', event => event.preventDefault()); + this.addDisposableListener(element, 'drop', event => { + event.preventDefault(); + this.trzszFilter + .uploadFiles((event as DragEvent).dataTransfer?.items as DataTransferItemList) + .then(() => console.log('[ttyd] upload success')) + .catch(err => console.log('[ttyd] upload failed: ' + err)); }); this.disposables.push(terminal.onResize(size => this.trzszFilter.setTerminalColumns(size.cols))); } diff --git a/html/src/components/terminal/xterm/index.ts b/html/src/components/terminal/xterm/index.ts index e6809e4..06d97ee 100644 --- a/html/src/components/terminal/xterm/index.ts +++ b/html/src/components/terminal/xterm/index.ts @@ -44,6 +44,7 @@ export interface ClientOptions { enableTrzsz: boolean; enableSixel: boolean; titleFixed?: string; + isWindows: boolean; } export interface FlowControl { @@ -94,7 +95,10 @@ export class Xterm { private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data)); - constructor(private options: XtermOptions, private sendCb: () => void) {} + constructor( + private options: XtermOptions, + private sendCb: () => void + ) {} dispose() { for (const d of this.disposables) { @@ -199,13 +203,13 @@ export class Xterm { terminal.write(data, () => { this.pending = Math.max(this.pending - 1, 0); if (this.pending < lowWater) { - this.socket?.send(textEncoder.encode(Command.PAUSE)); + this.socket?.send(textEncoder.encode(Command.RESUME)); } }); this.pending++; this.written = 0; if (this.pending > highWater) { - this.socket?.send(textEncoder.encode(Command.RESUME)); + this.socket?.send(textEncoder.encode(Command.PAUSE)); } } else { terminal.write(data); @@ -218,7 +222,10 @@ export class Xterm { if (socket?.readyState !== WebSocket.OPEN) return; if (typeof data === 'string') { - socket.send(textEncoder.encode(Command.INPUT + data)); + const payload = new Uint8Array(data.length * 3 + 1); + payload[0] = Command.INPUT.charCodeAt(0); + const stats = textEncoder.encodeInto(data, payload.subarray(1)); + socket.send(payload.subarray(0, (stats.written as number) + 1)); } else { const payload = new Uint8Array(data.length + 1); payload[0] = Command.INPUT.charCodeAt(0); @@ -320,6 +327,7 @@ export class Xterm { this.zmodemAddon = new ZmodemAddon({ zmodem: prefs.enableZmodem, trzsz: prefs.enableTrzsz, + windows: prefs.isWindows, onSend: this.sendCb, sender: this.sendData, writer: this.writeData, @@ -370,6 +378,9 @@ export class Xterm { this.titleFixed = value; document.title = value; break; + case 'isWindows': + if (value) console.log('[ttyd] is windows'); + break; default: console.log(`[ttyd] option: ${key}=${JSON.stringify(value)}`); if (terminal.options[key] instanceof Object) { -- cgit v1.2.3