Giter Club home page Giter Club logo

term-img's Introduction

term-img

Display images in iTerm

You probably want the higher-level terminal-image package for displaying your images.

Even animated gifs!

Currently only supported on iTerm >=3.

Install

npm install term-img

Usage

import terminalImage from 'term-img';

function fallback() {
	// Return something else when not supported
}

console.log(terminalImage('unicorn.jpg', {fallback}));

API

terminalImage(image, options?)

Get the image as a string that you can log manually.

image

Type: string | Uint8Array

File path to an image or an image as a buffer.

options

Type: object

width
height

Type: 'auto' | string | number

The width and height are given as a number followed by a unit, or the word 'auto'.

  • N: N character cells.
  • Npx: N pixels.
  • N%: N percent of the session's width or height.
  • auto: The image's inherent size will be used to determine an appropriate dimension.
preserveAspectRatio

Type: boolean
Default: true

fallback

Type: Function
Default: () => throw new UnsupportedTerminalError()

Enables you to do something else when the terminal doesn't support images.

Related

term-img's People

Contributors

bendingbender avatar kevva avatar michaeldeboey avatar richienb avatar sindresorhus avatar tbjgolden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

term-img's Issues

Support tmux

It requires some wrapper escape codes to please it.

https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat

Specifically:

# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
# only accepts ESC backslash for ST.
function print_osc() {
    if [[ $TERM == screen* ]] ; then
        printf "\033Ptmux;\033\033]"
    else
        printf "\033]"
    fi
}

# More of the tmux workaround described above.
function print_st() {
    if [[ $TERM == screen* ]] ; then
        printf "\a\033\\"
    else
        printf "\a"
    fi
}

I will get to this eventually, but I don't use tmux, so not a priority. A pull request would be welcomed :)

CHANGELOG missing

I just saw the package is updated from v2.1.0 to v3.0.0 which implies breaking changes, but I can't find any CHANGELOG to check them all out.

Would you be so kind to provide us with a decent CHANGELOG please? ๐Ÿ™‚

Thanks for all your great work @sindresorhus! ๐Ÿ™‚

Deprecation warning when installing term-img in a clean project

After installing term-img in a clean project, I get the following deprecation warning:

npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead

This warning is coming from [email protected]'s dependency app-path dependency.

I've added a similar issue upstream, which is already fixed.

Can the iterm2-version dependency be updated please?

Thanks for all your great work @sindresorhus! ๐Ÿ™‚

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.