├── .editorconfig
├── .gitattributes
├── .gitignore
├── .npmrc
├── .travis.yml
├── fixture.png
├── index.js
├── license
├── package.json
├── readme.md
├── screenshot.png
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [*.yml]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | /dist.js
4 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '10'
4 | - '8'
5 |
--------------------------------------------------------------------------------
/fixture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevva/ink-image/0652db96913f6ac258e71c625f0222c967fcba2e/fixture.png
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | const React = require('react');
3 | const {Box} = require('ink');
4 | const omit = require('lodash.omit');
5 | const propTypes = require('prop-types');
6 | const termImg = require('term-img');
7 |
8 | const Image = props => (
9 |
10 | {termImg.string(props.src, Object.assign(omit(props, ['alt', 'src']), {
11 | fallback: () => props.alt
12 | }))}
13 |
14 | );
15 |
16 | Image.propTypes = {
17 | alt: propTypes.string,
18 | src: propTypes.oneOfType([
19 | propTypes.object,
20 | propTypes.string
21 | ]).isRequired
22 | };
23 |
24 | Image.defaultProps = {
25 | alt: ''
26 | };
27 |
28 | module.exports = Image;
29 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Kevin Mårtensson (github.com/kevva)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ink-image",
3 | "version": "2.0.0",
4 | "description": "Image component for Ink",
5 | "license": "MIT",
6 | "repository": "kevva/ink-image",
7 | "author": {
8 | "name": "Kevin Mårtensson",
9 | "email": "kevinmartensson@gmail.com",
10 | "url": "github.com/kevva"
11 | },
12 | "engines": {
13 | "node": ">=8"
14 | },
15 | "scripts": {
16 | "build": "babel index.js --out-file=dist.js",
17 | "prepublish": "npm run build",
18 | "pretest": "npm run build",
19 | "test": "xo && ava"
20 | },
21 | "main": "dist.js",
22 | "files": [
23 | "dist.js"
24 | ],
25 | "keywords": [
26 | "ink-component",
27 | "ink",
28 | "component",
29 | "image"
30 | ],
31 | "dependencies": {
32 | "lodash.omit": "^4.5.0",
33 | "prop-types": "^15.7.2",
34 | "term-img": "^4.0.0"
35 | },
36 | "devDependencies": {
37 | "@babel/cli": "^7.2.3",
38 | "@babel/core": "^7.3.3",
39 | "@babel/preset-react": "^7.0.0",
40 | "ava": "^1.3.1",
41 | "eslint-config-xo-react": "^0.19.0",
42 | "eslint-plugin-react": "^7.12.4",
43 | "eslint-plugin-react-hooks": "^1.4.0",
44 | "ink": "^2.0.3",
45 | "ink-testing-library": "^1.0.0",
46 | "react": "^16.8.2",
47 | "xo": "^0.24.0"
48 | },
49 | "peerDependencies": {
50 | "ink": ">=2.0.0",
51 | "react": ">=16.8.0"
52 | },
53 | "babel": {
54 | "presets": [
55 | "@ava/stage-4",
56 | "@babel/preset-react"
57 | ]
58 | },
59 | "xo": {
60 | "extends": [
61 | "xo-react"
62 | ],
63 | "rules": {
64 | "jsx-quotes": [
65 | "error",
66 | "prefer-single"
67 | ]
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # ink-image [](https://travis-ci.org/kevva/ink-image)
2 |
3 | > Image component for [Ink](https://github.com/vadimdemedes/ink)
4 |
5 | 
6 |
7 | *Currently only supported on [iTerm >=3](https://www.iterm2.com/downloads.html).*
8 |
9 |
10 | ## Install
11 |
12 | ```
13 | $ npm install ink-image
14 | ```
15 |
16 |
17 | ## Usage
18 |
19 | ```js
20 | import React from 'react';
21 | import {render} from 'ink';
22 | import Image from 'ink-image';
23 |
24 | render(
25 |
26 | );
27 | ```
28 |
29 |
30 | ## API
31 |
32 | ### ``
33 |
34 | Besides the props below, it accepts props allowed in [`ansi-escapes`](https://github.com/sindresorhus/ansi-escapes#options).
35 |
36 | #### src
37 |
38 | Type: `string | Buffer`
39 |
40 | Path to an image or the image as a `Buffer`.
41 |
42 | #### alt
43 |
44 | Type: `string`
45 |
46 | Alternative text to show when an image can't be displayed.
47 |
48 |
49 | ## License
50 |
51 | MIT © [Kevin Mårtensson](https://github.com/kevva)
52 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevva/ink-image/0652db96913f6ac258e71c625f0222c967fcba2e/screenshot.png
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | import {serial as test} from 'ava';
2 | import React from 'react';
3 | import {render} from 'ink-testing-library';
4 | import {string as termImgString} from 'term-img';
5 | import Image from '.';
6 |
7 | test('render', t => {
8 | const actual = render();
9 | const expected = termImgString('./fixture.png', {
10 | fallback: () => ''
11 | });
12 |
13 | t.is(actual.lastFrame(), expected);
14 | });
15 |
16 | test('pass props to ansi-escapes', t => {
17 | const actual = render();
18 | const expected = termImgString('./fixture.png', {
19 | width: '5px',
20 | preserveAspectRatio: true,
21 | fallback: () => ''
22 | });
23 |
24 | t.is(actual.lastFrame(), expected);
25 | });
26 |
27 | test('alt text', t => {
28 | const {TERM_PROGRAM} = process.env;
29 | process.env.TERM_PROGRAM = 'Unicorn.app';
30 | t.is(render().lastFrame(), 'Hello');
31 | process.env.TERM_PROGRAM = TERM_PROGRAM;
32 | });
33 |
--------------------------------------------------------------------------------