Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createTerminal() {
// Create the terminal and setup event hooks
XTerminal.loadAddon('fit')
// Take out values from config
const { cursorBlink, cursorStyle } = Store.config
this.Terminal = new XTerminal({ cursorBlink, cursorStyle })
this.Terminal.on('open', this.onTerminalOpen)
// Window Events listeners
window.addEventListener('resize', this.onWindowResize)
this.Terminal.open(this.Term, true)
this.Terminal.fit()
}
// - onShellExit
shell.on('data', this.onShellData)
shell.on('exit', this.onShellExit)
// SETTING UP THE TERMINAL:
// - Taking values from the Store
// - Taking ID, cols and rows from props
// - Creating the Terminal object
const { cursorBlink, cursorStyle } = Store.config
const { id, cols, rows } = this.props
// Creating the terminal with the default
// options plus TODO: custom ones
this.terminal = Store.tabs[id].terminal =
new TERMINAL({
cursorBlink,
cursorStyle,
cols,
rows
})
const { terminal } = this
// - SETTING UP EVENTS:
// - onTerminalOpen
// - onTerminalData
// - onTerminalTitle (linked to the shell)
// - onTerminalResize
terminal.on('open', this.onTerminalOpen )
terminal.on('data', this.onTerminalData )
terminal.on('title', this.onTerminalTitle )
terminal.on('resize', this.onTerminalResize)
constructor(id) {
let io = this.ws(`/session/${id}/io`)
let control = this.ws(`/session/${id}/control`)
this.xterm = new Xterm()
this.xterm.attach(io)
this.elem = document.createElement('div')
this.elem.style.flex = '1'
this.xterm.open(this.elem)
control.addEventListener('open', () => {
window.addEventListener('resize', debounce(() => this.xterm.fit(), 100))
this.xterm.on('resize', (size) => {
control.send(JSON.stringify({
command: 'window-resize',
args: {width: size.cols.toString(), height: size.rows.toString()},
}))
})
})
constructor(props) {
super(props);
this.term = new XTerm();
this.stdin = new PassThrough();
this.stdout = new PassThrough();
this.stdout.rows = 0;
this.stdout.columns = 0;
this.term.on(`resize`, ({ rows, cols: columns }) => {
Object.assign(this.stdout, { rows, columns }).emit(`resize`);
});
this.term.on(`data`, data => {
this.stdin.write(data.toString());
});
this.stdout.on(`data`, data => {
startProcess(command, args, options) {
const projectPaths = atom.project.getPaths();
const defaultOptions = {
name: 'xterm-color',
cwd: path.resolve(process.env.HOME),
env: Object.assign({}, process.env, {
TERM: 'xterm-256color',
CLICOLOR: '1',
LSCOLORS: 'ExFxCxDxBxegedabagacad'
})
};
this.pty = spawnPty(command, args || [], Object.assign(defaultOptions, options));
this.terminal = new Terminal();
this.terminal.open(this.getElement(), true);
this.terminal.on('data', (data) => {
return this.pty.write(data);
});
this.showInitialMessage();
this.element.addEventListener('focus', () => this.terminal.focus());
this.resizeObserver = new ResizeObserver(this.elementDidResize.bind(this));
this.resizeObserver.observe(this.element);
this.pty.on('data', (data) => {
return this.terminal.write(data);
});
this.pty.on('exit', () => {
this.emitter.emit('didExitProccess');
this.destroy();
});
return this.pty;
_openTerminal() {
this.pty = this._openPseudoterminal();
this.terminal = new Terminal();
this.terminal.open(this.element, true);
this.applyThemeStyles();
}
public constructor(
@inject(TYPES.ISettingsManager) settingsManager: ISettingsManager,
@inject(TYPES.IShell) shell: IShell,
useFallbackShell = false
) {
this.settingsManager = settingsManager;
this.shell = shell;
this.useFallbackShell = useFallbackShell;
(Xterm as any).loadAddon("fit");
this.xterm = new Xterm({
cursorBlink: this.settingsManager.settings.terminal.cursorBlink
});
this.shell.spawn(this.shellName);
this.shell.attach(this.xterm);
}
initialize(terminal) {
this.terminal = terminal;
this.emulator = new TerminalEmulator({cursorBlink: true, rows: 16});
this.attach();
this.subscribe();
this.resizeAfterDrag = this.resizeAfterDrag.bind(this)
}