Skip to content

Commit

Permalink
💩 try to support trzsz
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 25, 2022
1 parent 45ef578 commit 951b2b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
"base64-js": "^1.5.1",
"decko": "^1.2.0",
"file-saver": "^2.0.5",
"preact": "^10.10.0",
"trzsz": "^0.4.3",
"whatwg-fetch": "^3.6.2",
"xterm": "^4.19.0",
"xterm-addon-fit": "^0.5.0",
Expand Down
19 changes: 18 additions & 1 deletion html/src/components/terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { WebglAddon } from 'xterm-addon-webgl';
import { WebLinksAddon } from 'xterm-addon-web-links';

import { OverlayAddon } from './overlay';
import { TrzszFilter } from 'trzsz';
import { fromByteArray } from 'base64-js';
import { ZmodemAddon, FlowControl } from '../zmodem';

import 'xterm/css/xterm.css';
Expand Down Expand Up @@ -53,6 +55,7 @@ export class Xterm extends Component<Props> {
private textDecoder: TextDecoder;
private container: HTMLElement;
private terminal: Terminal;
private trzszFilter: TrzszFilter;

private fitAddon: FitAddon;
private overlayAddon: OverlayAddon;
Expand Down Expand Up @@ -193,6 +196,20 @@ export class Xterm extends Component<Props> {
}
terminal.open(container);
fitAddon.fit();

this.trzszFilter = new TrzszFilter({
writeToTerminal: (data) => this.zmodemAddon.consume(data as ArrayBuffer),
sendToServer: (data) => {
if (data instanceof Uint8Array) {
this.socket.send(JSON.stringify({ binary: fromByteArray(data) }));
} else {
this.socket.send(JSON.stringify({ input: data }));
}
},
terminalColumns: terminal.cols,
});
terminal.onData(this.trzszFilter.processTerminalInput);
terminal.onBinary(this.trzszFilter.processBinaryInput);
}

@bind
Expand Down Expand Up @@ -360,7 +377,7 @@ export class Xterm extends Component<Props> {

switch (cmd) {
case Command.OUTPUT:
zmodemAddon.consume(data);
this.trzszFilter.processServerOutput(data);
break;
case Command.SET_WINDOW_TITLE:
this.title = textDecoder.decode(data);
Expand Down
10 changes: 10 additions & 0 deletions html/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,11 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=

base64-js@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

base@^0.11.1:
version "0.11.2"
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
Expand Down Expand Up @@ -6499,6 +6504,11 @@ trim-newlines@^2.0.0:
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-2.0.0.tgz#b403d0b91be50c331dfc4b82eeceb22c3de16d20"
integrity sha1-tAPQuRvlDDMd/EuC7s6yLD3hbSA=

trzsz@^0.4.3:
version "0.4.3"
resolved "https://registry.yarnpkg.com/trzsz/-/trzsz-0.4.3.tgz#936ff6714c3dc194448d9e091240d615b4e62bb8"
integrity sha512-OcOOPM7XN9kNxjuABsxBv8Zyd9pNi9qfXNW8Ad+30BcGmxZI89wRG/Am38hWw2MOiLoqi3SAch7uysqUCG36Gg==

ts-loader@^9.3.1:
version "9.3.1"
resolved "https://mirrors.cloud.tencent.com/npm/ts-loader/-/ts-loader-9.3.1.tgz#fe25cca56e3e71c1087fe48dc67f4df8c59b22d4"
Expand Down

0 comments on commit 951b2b9

Please sign in to comment.