How to use ansi-escape-sequences - 10 common examples

To help you get started, we’ve selected a few ansi-escape-sequences 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 jsdoc2md / jsdoc-to-markdown / bin / cli.js View on Github external
function halt (err) {
  if (err.code === 'EPIPE') process.exit(0) /* no big deal */

  if (config) {
    if (config.verbose) {
      console.error(ansi.format(err.stack || err, 'red'))
    } else {
      console.error(ansi.format('Error: ' + err.message, 'red'))
      console.error(ansi.format('(run jsdoc2md with --verbose for a stack trace)', 'red'))
    }
  } else {
    console.error(ansi.format(err.message, 'red'))
  }
  console.error(usage)
  process.exitCode = 1
}
github jsdoc2md / jsdoc-to-markdown / bin / cli.js View on Github external
function halt (err) {
  if (err.code === 'EPIPE') process.exit(0) /* no big deal */

  if (config) {
    if (config.verbose) {
      console.error(ansi.format(err.stack || err, 'red'))
    } else {
      console.error(ansi.format('Error: ' + err.message, 'red'))
      console.error(ansi.format('(run jsdoc2md with --verbose for a stack trace)', 'red'))
    }
  } else {
    console.error(ansi.format(err.message, 'red'))
  }
  console.error(usage)
  process.exitCode = 1
}
github pterodactyl / daemon / src / controllers / server.js View on Github external
};

            // If the server "crashed" with a normal exit code indicating that it was stopped successfully
            // don't force it to reboot. This can happen if a plugin stops the server for someone.
            if (!Config.get('internals.clean_exit_is_crash', true) && parseInt(props.ExitCode, 10) === 0 && !props.OOMKilled) {
                return;
            }

            // If crash detection is disabled for the server don't do anything.
            if (!_.get(this.json, 'container.crashDetection', true)) {
                this.log.warn(props, 'Server detected as entering a crashed state; crash handler is disabled; aborting reboot.');
                return;
            }

            this.emit('console', `${Ansi.style['bg-red']}${Ansi.style.white}[Pterodactyl Daemon] ---------- Detected server process in a crashed state! ----------`);
            this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] Exit Code: ${Ansi.style.reset}${props.ExitCode}`);
            this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] Out of Memory: ${Ansi.style.reset}${props.OOMKilled}`);
            this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] Error Response: ${Ansi.style.reset}${props.Error}`);
            this.emit('crashed');

            if (moment.isMoment(this.lastCrash) && moment(this.lastCrash).add(60, 'seconds').isAfter(moment())) {
                this.setCrashTime();
                this.log.warn(props, 'Server detected as crashed but has crashed within the last 60 seconds; aborting reboot.');
                this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] Aborting automatic reboot due to crash within the last 60 seconds.`);

                return;
            }

            this.log.warn(props, 'Server detected as crashed! Attempting server reboot.');
            this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] Server process detected as entering a crashed state; rebooting.`);
            this.setCrashTime();
github pterodactyl / daemon / src / controllers / docker.js View on Github external
this.stream.on('data', data => {
                    if (!throttleEnabled || throttleTriggered) {
                        return;
                    }

                    const lines = _.split(data, /\r?\n/);
                    linesSent += (lines.length - 1);

                    // If we've suddenly gone over the trigger threshold send a message to the console and register
                    // that event. The trigger will be reset automatically by the check interval time.
                    if (linesSent > maxLinesPerInterval) {
                        throttleTriggered = true;
                        throttleTriggerCount += 1;

                        this.server.log.debug({ throttleTriggerCount }, 'Server has passed the throttle detection threshold. Penalizing server process.');
                        this.server.output(`${Ansi.style.yellow}[Pterodactyl Daemon] Your server is sending too much data too quickly! Automatic spam detection triggered.`);
                    }

                    // We've triggered it too many times now, kill the server because clearly something is not
                    // working correctly.
                    if (throttleTriggerCount > maximumThrottleTriggers) {
                        this.server.output(`${Ansi.style.red}[Pterodactyl Daemon] Your server is sending too much data, process is being killed.`);
                        this.server.log.warn('Server has triggered automatic kill due to excessive data output. Potential DoS attack.');
                        this.server.kill(() => {}); // eslint-disable-line
                    }
                }).on('end', () => {
                    this.stream = undefined;
github pterodactyl / daemon / src / controllers / server.js View on Github external
},
                    callback => {
                        this.log.info('Completed rebuild process for server container.');
                        this.emit('console', `${Ansi.style.green}[Pterodactyl Daemon] Completed rebuild process for server. Server is now booting.`);
                        this.start(callback);
                    },
                ], err => {
                    if (err) {
                        this.setStatus(Status.OFF);
                        this.emit('console', `${Ansi.style.red}[Pterodactyl Daemon] A fatal error was encountered booting this container.`);
                        this.buildInProgress = false;
                        this.log.error(err);
                    }
                });
            } else {
                this.emit('console', `${Ansi.style.cyan}[Pterodactyl Daemon] Please wait while your server is being rebuilt.`);
            }
            return next(new Error('Server is currently queued for a container rebuild. Your request has been accepted and will be processed once the rebuild is complete.'));
        }

        Async.series([
            callback => {
                this.log.debug('Checking size of server folder before booting.');
                this.emit('console', `${Ansi.style.yellow}[Pterodactyl Daemon] Checking size of server data directory...`);
                this.fs.size((err, size) => {
                    if (err) return callback(err);

                    // 10 MB overhead accounting.
                    const sizeInMb = Math.round(size / (1000 * 1000));
                    this.currentDiskUsed = sizeInMb;

                    if (this.json.build.disk > 0 && sizeInMb > this.json.build.disk) {
github pterodactyl / daemon / src / controllers / docker.js View on Github external
linesSent += (lines.length - 1);

                    // If we've suddenly gone over the trigger threshold send a message to the console and register
                    // that event. The trigger will be reset automatically by the check interval time.
                    if (linesSent > maxLinesPerInterval) {
                        throttleTriggered = true;
                        throttleTriggerCount += 1;

                        this.server.log.debug({ throttleTriggerCount }, 'Server has passed the throttle detection threshold. Penalizing server process.');
                        this.server.output(`${Ansi.style.yellow}[Pterodactyl Daemon] Your server is sending too much data too quickly! Automatic spam detection triggered.`);
                    }

                    // We've triggered it too many times now, kill the server because clearly something is not
                    // working correctly.
                    if (throttleTriggerCount > maximumThrottleTriggers) {
                        this.server.output(`${Ansi.style.red}[Pterodactyl Daemon] Your server is sending too much data, process is being killed.`);
                        this.server.log.warn('Server has triggered automatic kill due to excessive data output. Potential DoS attack.');
                        this.server.kill(() => {}); // eslint-disable-line
                    }
                }).on('end', () => {
                    this.stream = undefined;
github machinelabs / machinelabs / server / src / code-runner / downloader / docker-file-downloader.spec.ts View on Github external
.subscribe(null, null, () => {
        expect(outgoingMessages.length).toBe(8);
        expect(outgoingMessages[0]).toEqual(stdoutMsg(`Downloading inputs. Hold on.${newLine()}`));
        // tslint:disable-next-line
        expect(outgoingMessages[1]).toEqual(
          stdoutMsg(
            `${ansi.cursor.down(3)}\rDownloading ${bold(inputs[0].url)} to ${bold('./inputs/' + inputs[0].name)}`
          )
        );
        expect(outgoingMessages[2]).toEqual(
          stdoutMsg(
            `${ansi.cursor.down(3)}\rDownloading ${bold(inputs[1].url)} to ${bold('./inputs/' + inputs[1].name)}`
          )
        );
        // jump 5 lines up after both captions are written
        expect(outgoingMessages[3]).toEqual(stdoutMsg(ansi.cursor.up(5)));
        // tslint:disable-next-line
        expect(outgoingMessages[4]).toEqual(
          stdoutMsg(
            ansi.cursor.down(downloader.relativeOffset(0)) +
              `progress 1st file` +
              ansi.cursor.up(downloader.relativeOffset(0))
          )
github machinelabs / machinelabs / server / src / code-runner / downloader / docker-file-downloader.spec.ts View on Github external
`${ansi.cursor.down(3)}\rDownloading ${bold(inputs[0].url)} to ${bold('./inputs/' + inputs[0].name)}`
          )
        );
        expect(outgoingMessages[2]).toEqual(
          stdoutMsg(
            `${ansi.cursor.down(3)}\rDownloading ${bold(inputs[1].url)} to ${bold('./inputs/' + inputs[1].name)}`
          )
        );
        // jump 5 lines up after both captions are written
        expect(outgoingMessages[3]).toEqual(stdoutMsg(ansi.cursor.up(5)));
        // tslint:disable-next-line
        expect(outgoingMessages[4]).toEqual(
          stdoutMsg(
            ansi.cursor.down(downloader.relativeOffset(0)) +
              `progress 1st file` +
              ansi.cursor.up(downloader.relativeOffset(0))
          )
        );
        expect(outgoingMessages[5]).toEqual(
          stdoutMsg(
            ansi.cursor.down(downloader.relativeOffset(1)) +
              `progress 2nd file` +
              ansi.cursor.up(downloader.relativeOffset(1))
          )
        );
        // jump 9 lines down and write a new line after both downloads completed
        expect(outgoingMessages[6]).toEqual(stdoutMsg(ansi.cursor.down(9) + newLine()));
        expect(outgoingMessages[7]).toEqual(stdoutMsg(`Finished downloading inputs${newLine()}`));
        done();
      });
  });
github choojs / bankai / lib / ui.js View on Github external
function clearScreen () {
    diff.update('')
    // Ensure it's _completely_ cleared so that nothing lingers between views.
    // Some views (*cough* log *cough*) don't use ansi-diff so we can't just rely on that.
    process.stdout.write(ansi.erase.display(2))
  }
github giano / Telegrammer / code / logger.js View on Github external
error: function (error) {
    if (error) {
      Logger.trace();
      var error_msg = ansi.format(_.trim(error.message || error), 'red');
      if (log_file_path) {
        try {
          fs.appendFile(log_file_path, formatForLogFile(error_msg));
        } catch (e) {

        }
      } else {
        console.error(error_msg);
      }
    }
  },
  /**

ansi-escape-sequences

A simple library containing all known terminal ansi escape codes and sequences.

MIT
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis