How to use xterm - 10 common examples

To help you get started, we’ve selected a few xterm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tsl0922 / ttyd / html / js / app.js View on Github external
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',
github Coding / WebIDE-Frontend / app / components / Terminal / Xterm.jsx View on Github external
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' })
github Chhekur / colon-ide / assets / js / terminal.js View on Github external
var os = require('os');
var pty = require('node-pty');
var Terminal = require('xterm').Terminal;
var fs = require('fs');
let fit = require('../../node_modules/xterm/lib/addons/fit/fit.js');

// Initialize node-pty with an appropriate shell
Terminal.applyAddon(fit);
var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
// const shell = process.env[os.platform() === 'win32' ? 'COMSPEC' : 'SHELL'];
const ptyProcess = pty.spawn(shell, [], {
  name: 'xterm-color',
//   cols: 10,
//   rows: 500,
  cwd: ((file.path != undefined) && (fs.existsSync(file.path))) ? path.join(file.path, '..') : process.env.HOME,
  // cwd: '.',
  env: process.env
});
console.log(file.path);
// console.log(process.env);

// Initialize xterm.js and attach it to the DOM
global.xterm = new Terminal({ allowTransparency: true });
xterm.open(document.getElementById('terminal'));
github alibaba / ice / packages / iceworks-client / src / utils / termManager.js View on Github external
cursor: 'rgba(0, 0, 0, 0.5)',
  selection: 'rgba(0, 0, 0, 0.5)',
  brightGreen: '#42b983',
  brightYellow: '#ea6e00',
};

// default options
const defaultOptions = {
  cols: 100,
  rows: 30,
  theme: defaultTheme,
};

// initialize addon
Terminal.applyAddon(fit);
Terminal.applyAddon(webLinks);

// format and write the text content of the terminal
const writeChunkFn = term => {
  const writeChunk = (data, ln = true) => {
    if (data && data.indexOf('\n') !== -1) {
      data.split('\n').forEach(value => writeChunk(value));
      return;
    }
    if (typeof data === 'string') {
      if (ln) {
        term.writeln(data);
      } else {
        term.write(data);
      }
    } else {
      term.writeln('');
github pterodactyl / panel / resources / scripts / components / server / Console.tsx View on Github external
useEffect(() => {
        if (connected && terminalElement && !terminal.element) {
            terminal.open(terminalElement);

            // @see https://github.com/xtermjs/xterm.js/issues/2265
            // @see https://github.com/xtermjs/xterm.js/issues/2230
            TerminalFit.fit(terminal);

            // Add support for copying terminal text.
            terminal.attachCustomKeyEventHandler((e: KeyboardEvent) => {
                // Ctrl + C
                if (e.ctrlKey && (e.key === 'c')) {
                    document.execCommand('copy');
                    return false;
                }

                return true;
            });
        }
    }, [ terminal, connected, terminalElement ]);
github vterm / vterm / src / components / terminalError.jsx View on Github external
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()
  }
github vterm / vterm / src / components / terminalError.jsx View on Github external
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()
  }
github alibaba / ice / packages / iceworks-client / src / utils / termManager.js View on Github external
create(id, container, options = {}) {
    const opts = deepmerge(defaultOptions, options);
    if (!this.terms[id]) {
      this.terms[id] = new Terminal(opts);
      this.terms[id].writeChunk = writeChunkFn(this.terms[id]);
      this.terms[id].writeLog = writeLog(this.terms[id]);
    } else {
      this.terms[id]._core.options.theme = opts.theme;
    }

    // initialize the web links addon, registering the link matcher
    webLinks.webLinksInit(this.terms[id], (event, uri) => {
      window.open(uri, 'blank');
    });

    // opens the terminal within an element.
    this.terms[id].open(container);

    // Note: need to initialize the fit plugin when the component is re-rendered
    // make the terminal's size and geometry fit the size of #terminal-container
    this.terms[id].fit();

    return this.terms[id];
  }
github tbodt / ish / app / xtermjs / term.js View on Github external
import Terminal from 'xterm';
import 'xterm/dist/xterm.css';
import './term.css';

// monkey patching so xterm doesn't need a textarea
Terminal.prototype.focus = function() {
    this.textarea.dispatchEvent(new FocusEvent('focus'));
};
Terminal.prototype.blur = function() {
    this.textarea.dispatchEvent(new FocusEvent('blur'));
};

window.term = new Terminal();
// there is no public interface to disable linkifying
term.linkifier._linkMatchers = [];
term.open(document.getElementById('terminal'), true);
term.on('focus', function() {
    webkit.messageHandlers.focus.postMessage('focus');
});
term.on('resize', function(size) {
    webkit.messageHandlers.resize.postMessage('resize');
});

// copied from the fit addon, but without subtracting 17 pixels for a nonexistent scrollbar
function fit() {
github wasmerio / wasmer-js / examples / wapm-shell / services / wapm-terminal / wapm-terminal.ts View on Github external
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);
  }