How to use the ansi-escapes.image function in ansi-escapes

To help you get started, we’ve selected a few ansi-escapes 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 tslide / tslide / index.js View on Github external
function images (content) {
  var pattern = /^!\[.*?\]\((.*)\)/mg
  var notIterm = !/^iterm/i.test(process.env.TERM_PROGRAM)
  var match
  var image

  if (notIterm) {
    return content
  }

  while (match = pattern.exec(content)) {
    try {
      var url = path.join(path.dirname(file), match[1])

      image = imgcat(fs.readFileSync(url))
      content = content.replace(match[0], image)
    } catch (error) {
      // Either file doesn't exist
      // or terminal doesn't support images
    }
  }

  return content;
}
github sindresorhus / term-img / index.js View on Github external
if (process.env.TERM_PROGRAM !== 'iTerm.app') {
		return fallback;
	}

	const version = iterm2Version();

	if (Number(version[0]) < 3) {
		return fallback;
	}

	if (typeof image === 'string') {
		image = fs.readFileSync(image);
	}

	return ansiEscapes.image(image, options);
}
github kodie / progress-img / index.js View on Github external
}
      }
    }
  }

  this.cleared = false
  this.current = frameNumber
  this.lastSet = Date.now()
  this.prevOptions = opts

  var content

  if (this.fallback) {
    content = this.fallbackFrames[frameNumber]
  } else {
    content = ansiEscapes.image(this.frames[frameNumber], opts)
  }

  if (opts.textTop) {
    content = opts.textTop + '\n' + content
  }

  if (opts.textBottom) {
    content += '\n' + opts.textBottom
  }

  this.log(content)

  return this
}