How to use the readline.emitKeypressEvents function in readline

To help you get started, we’ve selected a few readline 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 gngeorgiev / JsShell / src / shell.js View on Github external
this.paths = this.settings.env.PATH.split(':');

            this.home = this.settings.env.HOME;
            this.cwd = this.home;
            this.completer = new Completer(this);
            this.executor = new Executor(this);

            const input = process.stdin;
            const output = process.stdout;
            const terminal = true;
            const completer = this.completer.complete.bind(this.completer);
            this.rl = readline.createInterface({input, output, terminal, completer});
            this.setPrompt();
            this._readHistory();

            readline.emitKeypressEvents(process.stdin, this.rl);
            if (process.stdin.isTTY) {
                process.stdin.setRawMode(true);
            }

            this._lineCallbacks = [];
            this._attachHandlers();
            this._fireInitialized();
        });
    }
github terkelg / prompts / lib / elements / prompt.js View on Github external
constructor(opts={}) {
    super();

    this.firstRender = true;
    this.in = opts.stdin || process.stdin;
    this.out = opts.stdout || process.stdout;
    this.onRender = (opts.onRender || (() => void 0)).bind(this);
    const rl = readline.createInterface(this.in);
    readline.emitKeypressEvents(this.in, rl);

    if (this.in.isTTY) this.in.setRawMode(true);
    const isSelect = [ 'SelectPrompt', 'MultiselectPrompt' ].indexOf(this.constructor.name) > -1;
    const keypress = (str, key) => {
      let a = action(key, isSelect);
      if (a === false) {
        this._ && this._(str, key);
      } else if (typeof this[a] === 'function') {
        this[a](key);
      } else {
        this.bell();
      }
    };

    this.close = () => {
      this.out.write(cursor.show);

readline

Simple streaming readline module.

BSD
Latest version published 9 years ago

Package Health Score

62 / 100
Full package analysis