|
@ -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) |
|
|