Skip to content

Commit

Permalink
fix this.refresh not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
butlerx committed Aug 17, 2022
1 parent 66773d6 commit 920557d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@
"prom-client": "^14.0.1",
"response-time": "^2.3.2",
"sass": "^1.54.4",
"socket.io": "^4.4.1",
"socket.io-client": "^4.4.1",
"socket.io": "^4.5.1",
"socket.io-client": "^4.5.1",
"toastify-js": "^1.9.1",
"url-value-parser": "^2.1.0",
"winston": "^3.3.3",
"xterm": "^4.8.1",
"xterm-addon-fit": "^0.4.0",
"xterm-addon-web-links": "^0.4.0",
"xterm": "^4.19.0",
"xterm-addon-fit": "^0.5.0",
"xterm-addon-web-links": "^0.6.0",
"yargs": "^15.4.1"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions src/client/wetty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ import { mobileKeyboard } from './wetty/mobile.js';
import { overlay } from './shared/elements.js';
import { socket } from './wetty/socket.js';
import { verifyPrompt } from './shared/verify.js';
import { terminal } from './wetty/term.js';
import { terminal, Term } from './wetty/term.js';

// Setup for fontawesome
library.add(faCogs);
dom.watch();

function onResize(term: Term): () => void {
return function resize() {
term.resizeTerm();
};
}

socket.on('connect', () => {
const term = terminal(socket);
if (_.isUndefined(term)) return;

if (!_.isNull(overlay)) overlay.style.display = 'none';
window.addEventListener('beforeunload', verifyPrompt, false);
window.addEventListener('resize', term.resizeTerm, false);
window.addEventListener('resize', onResize(term), false);

term.resizeTerm();
term.focus();
Expand Down
20 changes: 15 additions & 5 deletions src/client/wetty/term.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import type { Socket } from 'socket.io-client';
import _ from 'lodash';

import { Terminal } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { WebLinksAddon } from 'xterm-addon-web-links';

import type { Options } from './term/confiruragtion/shared/options';
import { configureTerm, shouldFitTerm } from './term/confiruragtion.js';
import { loadOptions } from './term/confiruragtion/load';
import { configureTerm } from './term/confiruragtion.js';
import { terminal as termElement } from '../shared/elements.js';

export class Term extends Terminal {
socket: Socket;
fitAddon: FitAddon;
loadOptions: () => Options;

constructor(socket: Socket) {
super();
this.socket = socket;
this.fitAddon = new FitAddon();
this.loadAddon(this.fitAddon);
this.loadAddon(new WebLinksAddon());
this.loadOptions = loadOptions;
}

resizeTerm(): void {
this.refresh(0, this.rows - 1);
if (shouldFitTerm()) this.fitAddon.fit();
if (this.shouldFitTerm) this.fitAddon.fit();
this.socket.emit('resize', { cols: this.cols, rows: this.rows });
}

get shouldFitTerm(): boolean {
return this.loadOptions().wettyFitTerminal ?? true;
}
}

declare global {
Expand All @@ -37,12 +45,14 @@ declare global {
}

export function terminal(socket: Socket): Term | undefined {
const term = new Term(socket) as Term;
const term = new Term(socket);
if (_.isNull(termElement)) return undefined;
termElement.innerHTML = '';
term.open(termElement);
configureTerm(term);
window.onresize = term.resizeTerm;
window.onresize = function onResize() {
term.resizeTerm();
};
window.wetty_term = term;
return term;
}
4 changes: 0 additions & 4 deletions src/client/wetty/term/confiruragtion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@ export function configureTerm(term: Term): void {
false,
);
}

export function shouldFitTerm(): boolean {
return loadOptions().wettyFitTerminal ?? true;
}
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6010,7 +6010,7 @@ socket.io-adapter@~2.4.0:
resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-2.4.0.tgz#b50a4a9ecdd00c34d4c8c808224daa1a786152a6"
integrity sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg==

socket.io-client@^4.4.1:
socket.io-client@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-4.5.1.tgz#cab8da71976a300d3090414e28c2203a47884d84"
integrity sha512-e6nLVgiRYatS+AHXnOnGi4ocOpubvOUCGhyWw8v+/FxW8saHkinG6Dfhi9TU0Kt/8mwJIAASxvw6eujQmjdZVA==
Expand All @@ -6037,7 +6037,7 @@ socket.io-parser@~4.2.0:
"@socket.io/component-emitter" "~3.1.0"
debug "~4.3.1"

socket.io@^4.4.1:
socket.io@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.5.1.tgz#aa7e73f8a6ce20ee3c54b2446d321bbb6b1a9029"
integrity sha512-0y9pnIso5a9i+lJmsCdtmTTgJFFSvNQKDnPQRz28mGNnxbmqYg2QPtJTLFxhymFZhAIn50eHAKzJeiNaKr+yUQ==
Expand Down Expand Up @@ -6996,17 +6996,17 @@ xmlhttprequest-ssl@~2.0.0:
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67"
integrity sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==

xterm-addon-fit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.4.0.tgz#06e0c5d0a6aaacfb009ef565efa1c81e93d90193"
integrity sha512-p4BESuV/g2L6pZzFHpeNLLnep9mp/DkF3qrPglMiucSFtD8iJxtMufEoEJbN8LZwB4i+8PFpFvVuFrGOSpW05w==
xterm-addon-fit@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.5.0.tgz#2d51b983b786a97dcd6cde805e700c7f913bc596"
integrity sha512-DsS9fqhXHacEmsPxBJZvfj2la30Iz9xk+UKjhQgnYNkrUIN5CYLbw7WEfz117c7+S86S/tpHPfvNxJsF5/G8wQ==

xterm-addon-web-links@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.4.0.tgz#265cbf8221b9b315d0a748e1323bee331cd5da03"
integrity sha512-xv8GeiINmx0zENO9hf5k+5bnkaE8mRzF+OBAr9WeFq2eLaQSudioQSiT34M1ofKbzcdjSsKiZm19Rw3i4eXamg==
xterm-addon-web-links@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.6.0.tgz#0296cb6c99588847894670d998c9ea6a6aeb26ee"
integrity sha512-H6XzjWWZu8FBo+fnYpxdPk9w5M6drbsvwPEJZGRS38MihiQaVFpKlCMKdfRgDbKGE530tw1yH54rhpZfHgt2/A==

xterm@^4.8.1:
xterm@^4.19.0:
version "4.19.0"
resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.19.0.tgz#c0f9d09cd61de1d658f43ca75f992197add9ef6d"
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
Expand Down

0 comments on commit 920557d

Please sign in to comment.