Browse Source

update xterm

pull/268/head
butlerx 5 years ago
parent
commit
6f4d663ede
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 5
      package.json
  2. 25
      src/client/index.ts
  3. 10
      src/client/resize.ts
  4. 2
      src/client/wetty.scss
  5. 4131
      yarn.lock

5
package.json

@ -1,6 +1,6 @@
{ {
"name": "wetty", "name": "wetty",
"version": "1.3.2", "version": "1.4.0",
"description": "WeTTY = Web + TTY. Terminal access in browser over http/https", "description": "WeTTY = Web + TTY. Terminal access in browser over http/https",
"homepage": "https://github.com/butlerx/wetty", "homepage": "https://github.com/butlerx/wetty",
"repository": { "repository": {
@ -71,7 +71,8 @@
"source-map-loader": "^0.2.4", "source-map-loader": "^0.2.4",
"toastify-js": "^1.6.1", "toastify-js": "^1.6.1",
"winston": "^3.2.1", "winston": "^3.2.1",
"xterm": "^3.14.5", "xterm": "^4.8.1",
"xterm-addon-fit": "^0.4.0",
"yargs": "^14.0.0" "yargs": "^14.0.0"
}, },
"devDependencies": { "devDependencies": {

25
src/client/index.ts

@ -1,17 +1,17 @@
import { Terminal } from 'xterm'; import { Terminal } from 'xterm';
import { isNull } from 'lodash'; import { isNull } from 'lodash';
import { FitAddon } from 'xterm-addon-fit';
import { dom, library } from '@fortawesome/fontawesome-svg-core'; import { dom, library } from '@fortawesome/fontawesome-svg-core';
import { faCogs } from '@fortawesome/free-solid-svg-icons/faCogs'; import { faCogs } from '@fortawesome/free-solid-svg-icons/faCogs';
import Toastify from 'toastify-js'; import Toastify from 'toastify-js';
import * as fileType from 'file-type'; import * as fileType from 'file-type';
import { socket } from './socket'; import { socket } from './socket';
import { overlay, terminal } from './elements'; import { overlay, terminal } from './elements';
import { FileDownloader } from './download'; import { FileDownloader } from './download';
import verifyPrompt from './verify'; import verifyPrompt from './verify';
import disconnect from './disconnect'; import disconnect from './disconnect';
import mobileKeyboard from './mobile'; import mobileKeyboard from './mobile';
import resize from './resize';
import loadOptions from './options'; import loadOptions from './options';
import { copySelected, copyShortcut } from './copyToClipboard'; import { copySelected, copyShortcut } from './copyToClipboard';
import './wetty.scss'; import './wetty.scss';
@ -24,7 +24,13 @@ dom.watch();
socket.on('connect', () => { socket.on('connect', () => {
const term = new Terminal(); const term = new Terminal();
if (isNull(terminal)) return; if (isNull(terminal)) return;
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.open(terminal); term.open(terminal);
const resize = (): void => {
fitAddon.fit();
socket.emit('resize', { cols: term.cols, rows: term.rows });
};
const options = loadOptions(); const options = loadOptions();
Object.entries(options).forEach(([key, value]) => { Object.entries(options).forEach(([key, value]) => {
@ -45,7 +51,7 @@ socket.on('connect', () => {
const value = updated[key]; const value = updated[key];
term.setOption(key, value); term.setOption(key, value);
}); });
resize(term)(); resize();
} catch { } catch {
// skip // skip
editor.classList.add('error'); editor.classList.add('error');
@ -73,8 +79,8 @@ socket.on('connect', () => {
false false
); );
window.onresize = resize(term); window.onresize = resize;
resize(term)(); resize();
term.focus(); term.focus();
mobileKeyboard(); mobileKeyboard();
@ -101,7 +107,8 @@ socket.on('connect', () => {
} }
// Check if the buffer is ASCII // Check if the buffer is ASCII
// Ref: https://stackoverflow.com/a/14313213 // Ref: https://stackoverflow.com/a/14313213
else if (/^[\x00-\xFF]*$/.test(fileCharacters)) { // eslint-disable-line no-control-regex // eslint-disable-next-line no-control-regex
else if (/^[\x00-\xFF]*$/.test(fileCharacters)) {
mimeType = 'text/plain'; mimeType = 'text/plain';
fileExt = 'txt'; fileExt = 'txt';
} }
@ -128,10 +135,10 @@ socket.on('connect', () => {
}).showToast(); }).showToast();
}); });
term.on('data', data => { term.onData(data => {
socket.emit('input', data); socket.emit('input', data);
}); });
term.on('resize', size => { term.onResize(size => {
socket.emit('resize', size); socket.emit('resize', size);
}); });
socket socket
@ -143,7 +150,7 @@ socket.on('connect', () => {
}) })
.on('login', () => { .on('login', () => {
term.writeln(''); term.writeln('');
resize(term)(); resize();
}) })
.on('logout', disconnect) .on('logout', disconnect)
.on('disconnect', disconnect) .on('disconnect', disconnect)

10
src/client/resize.ts

@ -1,10 +0,0 @@
import { Terminal } from 'xterm';
import { fit } from 'xterm/lib/addons/fit/fit';
import { socket } from './socket';
export default function resize(term: Terminal): Function {
return (): void => {
fit(term);
socket.emit('resize', { cols: term.cols, rows: term.rows });
};
}

2
src/client/wetty.scss

@ -1,4 +1,4 @@
@import '~xterm/dist/xterm'; @import '~xterm/css/xterm';
@import '~toastify-js/src/toastify.css'; @import '~toastify-js/src/toastify.css';
$black: #000; $black: #000;

4131
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save