summaryrefslogtreecommitdiffstats
path: root/html/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-04 12:22:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-04 12:22:44 +0000
commit258ebf86e270c9730a876c7aa1bdb69d0de6f9aa (patch)
tree09e011af68711c0e5c92298d475450cbd1cc7be1 /html/src
parentReleasing debian version 1.7.3-2. (diff)
downloadttyd-258ebf86e270c9730a876c7aa1bdb69d0de6f9aa.tar.xz
ttyd-258ebf86e270c9730a876c7aa1bdb69d0de6f9aa.zip
Merging upstream version 1.7.4.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'html/src')
-rw-r--r--html/src/components/app.tsx1
-rw-r--r--html/src/components/terminal/xterm/addons/zmodem.ts16
-rw-r--r--html/src/components/terminal/xterm/index.ts19
3 files changed, 32 insertions, 4 deletions
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) {