Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ws.onopen = function(event) {
console.log('[ttyd] websocket opened');
wsError = false;
sendMessage(JSON.stringify({AuthToken: authToken}));
if (typeof term !== 'undefined') {
term.dispose();
}
// expose term handle for some programatic cases
// which need to get the content of the terminal
term = window.term = new Terminal({
fontSize: 13,
fontFamily: '"Menlo for Powerline", Menlo, Consolas, "Liberation Mono", Courier, monospace',
theme: {
foreground: '#d2d2d2',
background: '#2b2b2b',
cursor: '#adadad',
black: '#000000',
red: '#d81e00',
green: '#5ea702',
yellow: '#cfae00',
blue: '#427ab3',
magenta: '#89658e',
cyan: '#00a7aa',
white: '#dbded8',
brightBlack: '#686a66',
brightRed: '#f54235',
componentDidMount () {
const _this = this
_this.props.tab.title = 'Shell'
const terminalManager = new TerminalManager()
TerminalState.terminalManager = terminalManager
const uiTheme = SettingState.settings.appearance.ui_theme.value
let theme = BRIGHT_THEME
if (uiTheme === 'dark') {
theme = DARK_THEME
}
const terminal = this.terminal = new Terminal({
fontSize: 12,
// theme: themeName,
cols: 80,
rows: 24,
// fontFamily: 'Menlo, Monaco, "DejaVu Sans Mono", Consolas, "Andale Mono", monospace;',
})
terminal.attachCustomKeyEventHandler((e) => {
if (e.keyCode === 66 && e.altKey) {
terminalManager.getSocket().emit('term.input', { id: terminal.id, input: '\u001bb' }) // x1bb
return false
} else if (e.keyCode === 70 && e.altKey) {
terminalManager.getSocket().emit('term.input', { id: terminal.id, input: '\u001bf' }) // x1bf
return false
} else if (e.keyCode === 68 && e.altKey) {
terminalManager.getSocket().emit('term.input', { id: terminal.id, input: '\u001bd' })
constructor() {
// Create our xterm element
this.xterm = new Terminal();
this.xterm.on("paste", this.onPaste);
this.xterm.on("resize", this.handleTermResize);
// Create our Shell and tty
this.wapmTty = new WapmTty(this.xterm);
this.wapmShell = new WapmShell(this.wapmTty);
this.xterm.on("data", this.wapmShell.handleTermData);
}
function createTerminal(terminalContainer, {env, cwd, command, autoRestart, socket, fontFamily}) {
const fitAddon = new FitAddon();
const webglAddon = new WebglAddon();
const terminal = new Terminal({
scrollback: 1000,
tabStopWidth: 4,
fontFamily,
});
terminal.open(terminalContainer);
terminal.focus();
terminal.loadAddon(webglAddon);
terminal.loadAddon(fitAddon);
fitAddon.fit();
terminal.onResize(onTermResize(socket));
terminal.onData(onTermData(socket));
window.addEventListener('resize', onWindowResize(fitAddon));
initTerminal () {
let term = this.$_terminal = new Terminal({
cols: this.cols,
rows: this.rows,
theme: this.theme,
...this.options
})
webLinks.webLinksInit(term, this.handleLink)
term.open(this.$refs.render)
term.on('blur', () => this.$emit('blur'))
term.on('focus', () => this.$emit('focus'))
if (this.autoSize) {
this.$nextTick(this.fit)
}
},
private setupTerminal() {
this.terminal = new Terminal({
cursorBlink: false,
});
this.terminal.open(this.terminalContainer.nativeElement);
this.terminal.focus();
fit(this.terminal);
}
}
async function start() {
const el = document.getElementById('term');
Terminal.applyAddon(fit);
Terminal.applyAddon(WebfontLoader);
const term = new Terminal({
fontFamily: 'Source Code Pro',
rendererType: 'dom',
allowTransparency: true,
fontSize: 14,
disableStdin: true,
theme: {
background: 'transparent',
cursorStyle: 'underline',
},
});
el.innerHTML = '';
term.open(el);
term.fit();
onSocketOpen(event) {
console.log('Websocket connection opened');
const { socket, textEncoder } = this;
socket.send(textEncoder.encode(JSON.stringify({AuthToken: ''})));
if (this.terminal) {
this.terminal.destroy();
}
this.terminal = new TERMINAL({
fontSize: 13,
fontFamily: '"Menlo for Powerline", Menlo, Consolas, "Liberation Mono", Courier, monospace',
theme: {
foreground: '#d2d2d2',
background: '#2b2b2b',
cursor: '#adadad',
black: '#000000',
red: '#d81e00',
green: '#5ea702',
yellow: '#cfae00',
blue: '#427ab3',
magenta: '#89658e',
cyan: '#00a7aa',
white: '#dbded8',
brightBlack: '#686a66',
brightRed: '#f54235',
private openTerminal() {
if (this.terminal) {
this.terminal.dispose();
}
this.socket = new WebSocket(this.props.url, ['tty']);
this.terminal = new Terminal(this.props.options);
const { socket, terminal, container, fitAddon, overlayAddon } = this;
window.term = terminal as TerminalExtended;
window.term.fit = () => {
this.fitAddon.fit();
};
socket.binaryType = 'arraybuffer';
socket.onopen = this.onSocketOpen;
socket.onmessage = this.onSocketData;
socket.onclose = this.onSocketClose;
socket.onerror = this.onSocketError;
terminal.loadAddon(fitAddon);
terminal.loadAddon(overlayAddon);
terminal.loadAddon(new WebLinksAddon());
terminal.loadAddon(this.zmodemAddon);
componentWillUnmount() {
term.destroy();
term = new Terminal({
theme: { background: '#090c0f' }
});
term.write(this.state.cwd + '\r\n' + '$');
}
render() {