shellfie 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # shellfie 🤳🏽
2
2
 
3
- create beautiful terminal screenshots from formatted string
3
+ <img src="./shellfies/logo.png" />
4
4
 
5
5
  # install
6
6
  ```bash
7
- yarn add shellfie
7
+ npm install shellfie
8
8
  ```
9
9
 
10
10
  # the holy trinity ▽
11
- `shellfie` respects the holy trinity: the lib, the service, and the cli.
11
+ `shellfie` respects the holy trinity: the lib, the service, and the holy cli.
12
12
  - [shellfie](https://github.com/tool3/shellfie)
13
13
  - [shellfied](https://github.com/tool3/shellfied)
14
14
  - [shellfie-cli](https://github.com/tool3/shellfie-cli)
15
15
 
16
16
  # usage
17
- ```js
17
+ ```javascript
18
18
  const data = [
19
19
  '\x1b[105mSHELLFIE\\x1b[0m🤳',
20
20
  '\x1b[38;5;225mthe easiest way',
@@ -54,10 +54,10 @@ outputs:
54
54
  ### `location`
55
55
  **type**: `string`
56
56
  **description**: relative path to save your shellfies
57
- ### `puppeteerArgs`
58
- **type**: `string[]`
57
+ ### `puppeteerOptions`
58
+ **type**: `object`
59
59
  **description**: optional puppteer args
60
- **default**: `['--no-sandbox', '--disable-setuid-sandbox']`
60
+ **default**: `{ args: ['--no-sandbox', '--disable-setuid-sandbox'] }`
61
61
  ### `mode`
62
62
  **type**: `string`
63
63
  **description**: can allow raw string input. for example: `yarn test --colors > help.txt`, then copy the text and provide it to `shellfie` with this option set to `raw`.
@@ -95,15 +95,15 @@ outputs:
95
95
  **type**: `number`
96
96
  **description**: viewport height
97
97
 
98
- # examples
99
- ```js
100
- await shellfie(["\x1b[32mGreen line", "\x1b[31;1mRED bold"], { name: 'small', viewport: { width: 200, height: 200 } });
101
- ```
98
+ # examples
99
+ ```javascript
100
+ await shellfie(["\x1b[32mGreen line", "\x1b[31;1mRED bold"], { name: 'small', viewport: { width: 200, height: 200 } });
101
+ ```
102
102
 
103
103
  <img src="./shellfies/small.png" />
104
104
 
105
105
 
106
- ```js
106
+ ```javascript
107
107
  const testResults = [
108
108
  "yarn run v1.22.5",
109
109
  "$ mocha --no-timeouts tests/ --colors",
@@ -129,6 +129,43 @@ const testResults = [
129
129
  "Done in 19.60s.",
130
130
  ];
131
131
  await shellfie(testResults, { name: 'fira', style: { fontFamily: 'Fira Code', fontWeight: 'bold' } });
132
+ await shellfie(testResults, { name: 'monospace', style: { fontFamily: 'monospace' } });
133
+ await shellfie(testResults, { name: 'monaco', style: { fontFamily: 'Monaco' } });
132
134
  ```
133
135
 
134
136
  <img src="./shellfies/fira.png" />
137
+ <img src="./shellfies/monospace.png" />
138
+ <img src="./shellfies/monaco.png" />
139
+
140
+ ### raw mode
141
+ ```javascript
142
+ const string = `
143
+ cristal ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
144
+ teen ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
145
+ mind ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
146
+ morning ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
147
+ vice ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
148
+ passion ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
149
+ fruit ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
150
+ instagram ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
151
+ atlas ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
152
+ retro ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
153
+ summer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
154
+ pastel ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
155
+ rainbow ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
156
+ `
157
+ await shellfie(string, { name: 'gradient', mode: 'raw', viewport: {width: 600, height: 350} });
158
+ ```
159
+ <img src="./shellfies/gradient.png" />
160
+
161
+ ### bash colors
162
+ ```javascript
163
+ const shellfie = require('shellfie');
164
+ let backgroundColors = '';
165
+ for (let i = 0; i < 255; i++) {
166
+ backgroundColors += `\x1b[48;5;${i}m ${i}\x1b[0m`;
167
+ }
168
+ await shellfie(backgroundColors, { name: 'background', viewport: {width: 500, height: 400} });
169
+ ```
170
+
171
+ <img src="./shellfies/background.png" />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shellfie",
3
- "version": "1.2.5",
4
- "description": "create beautiful terminal screenshots from formatted string",
3
+ "version": "1.3.0",
4
+ "description": "create beautiful terminal screenshots programmatically",
5
5
  "main": "shellfie.js",
6
6
  "directories": {
7
7
  "test": "tests"
@@ -25,8 +25,8 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "puppeteer": "^5.5.0",
28
- "xterm": "^4.9.0",
29
- "xterm-addon-fit": "^0.4.0"
28
+ "xterm": "^4.14.1",
29
+ "xterm-addon-fit": "^0.5.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "mocha": "^8.2.1"
package/shellfie.d.ts CHANGED
@@ -1,27 +1,29 @@
1
- export type ShellfieTheme = {
1
+ declare type ShellfieTheme = {
2
2
  background: string;
3
3
  foreground: string;
4
4
  };
5
5
 
6
- export type ShellfieStyle = {
6
+ declare type ShellfieStyle = {
7
7
  fontFamily: string;
8
8
  fontWeight: string;
9
9
  fontSize: number;
10
10
  };
11
11
 
12
- export type ShellfieViewport = {
12
+ declare type ShellfieViewport = {
13
13
  width: number;
14
14
  height: number;
15
15
  };
16
16
 
17
- export type ShellfieOptions = {
17
+ declare type ShellfieOptions = {
18
18
  name?: string;
19
19
  location?: string;
20
20
  theme?: ShellfieTheme;
21
21
  style?: ShellfieStyle;
22
22
  viewport?: ShellfieViewport;
23
23
  mode?: string;
24
- puppeteerArgs?: string[];
24
+ puppeteerOptions?: Record<string, any>;
25
25
  };
26
26
 
27
- export default function shellfie(data: string | string[], options: ShellfieOptions): Promise<void>;
27
+ declare function shellfie(data: string | string[], options: ShellfieOptions): Promise<void>;
28
+
29
+ export = shellfie;
package/shellfie.js CHANGED
@@ -9,9 +9,8 @@ async function shellfie(data, config) {
9
9
  throw new Error('no data provided.\nshelffie needs a string || string[] to produce an image.')
10
10
  }
11
11
  const localPath = process.env.INIT_CWD || process.cwd();
12
- const { name, location, style, theme, ext, puppeteerArgs, viewport, mode } = getConfig(config, localPath);
13
-
14
- const browser = await puppeteer.launch({ args: puppeteerArgs });
12
+ const { name, location, style, theme, ext, puppeteerOptions, viewport, mode, rendererType } = getConfig(config, localPath);
13
+ const browser = await puppeteer.launch(puppeteerOptions);
15
14
  const page = await browser.newPage();
16
15
 
17
16
  await page.setViewport({ ...viewport, deviceScaleFactor: 4 });
@@ -33,7 +32,7 @@ async function shellfie(data, config) {
33
32
  // setup terminal
34
33
  await page.evaluate(({ options, lines, mode, viewport }) => {
35
34
  const fit = new FitAddon.FitAddon();
36
- const term = new Terminal({ ...options, rendererType: 'dom' });
35
+ const term = new Terminal({ ...options });
37
36
  term.open(document.getElementById('terminal'));
38
37
  term.loadAddon(fit);
39
38
  term.writeln('');
@@ -56,13 +55,14 @@ async function shellfie(data, config) {
56
55
  document.querySelector('.xterm-screen').style.height = `${height}px`;
57
56
  fit.fit();
58
57
 
59
- }, { lines, mode, options: style ? { theme, ...style } : { theme }, viewport });
58
+ }, { lines, mode, options: style ? { theme, ...style, rendererType } : { theme, rendererType }, viewport });
60
59
 
61
60
  // inject styles
62
61
  await page.addStyleTag({ path: `${path.resolve(__dirname, 'template/template.css')}` });
63
- await page.addStyleTag({ path: `${localModules}/xterm/css/xterm.css` })
62
+ await page.addStyleTag({ path: `${localModules}/xterm/css/xterm.css` });
63
+ await page.evaluate((theme) => document.querySelector('.terminal').style.background = theme.background, theme);
64
64
  await page.evaluateHandle('document.fonts.ready');
65
-
65
+
66
66
  // crop image
67
67
  const clip = await (await page.$(".main")).boundingBox();
68
68
  clip.height = Math.min(clip.height, page.viewport().height);
package/utils/config.js CHANGED
@@ -1,43 +1,41 @@
1
-
2
1
  function generateId() {
3
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
4
- const charactersLength = characters.length;
5
- let result = '';
2
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3
+ const charactersLength = characters.length;
4
+ let result = '';
6
5
 
7
- for (var i = 0; i < 7; i++) {
8
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
9
- }
10
- return `shellfie_${result}`;
6
+ for (var i = 0; i < 7; i++) {
7
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
8
+ }
9
+ return `shellfie_${result}`;
11
10
  }
12
11
 
13
-
14
12
  function getConfig(config, localPath) {
15
- const defaultpuppeteerArgs = ['--no-sandbox', '--disable-setuid-sandbox'];
16
- const defaultViewport = { width: 700, height: 600 };
17
- const defaultTheme = { background: '#151515' };
13
+ const defaultViewport = { width: 700, height: 600 };
14
+ const defaultTheme = { background: '#151515' };
15
+
16
+ const options = {
17
+ name: generateId(),
18
+ location: `${localPath}/shellfies`,
19
+ style: {},
20
+ theme: defaultTheme,
21
+ rendererType: 'dom',
22
+ ext: 'png',
23
+ puppeteerOptions: { args: ['--no-sandbox', '--disable-setuid-sandbox'] },
24
+ viewport: defaultViewport,
25
+ mode: 'default',
26
+ };
18
27
 
19
- const options = {
20
- name: generateId(),
21
- location: `${localPath}/shellfies`,
22
- style: {},
23
- theme: defaultTheme,
24
- ext: 'png',
25
- puppeteerArgs: defaultpuppeteerArgs,
26
- viewport: defaultViewport,
27
- mode: 'default'
28
- };
28
+ if (config) {
29
+ const userConfig = Object.keys(config).reduce((acc, key) => {
30
+ if (key in options) {
31
+ acc[key] = typeof options[key] === 'object' ? Object.assign(options[key], config[key]) : config[key];
32
+ }
33
+ return acc;
34
+ }, {});
35
+ return Object.assign(options, userConfig);
36
+ }
29
37
 
30
- if (config) {
31
- const userConfig = Object.keys(config).reduce((acc, key) => {
32
- if (key in options) {
33
- acc[key] = typeof options[key] === "object" ? Object.assign(options[key], config[key]) : config[key];
34
- }
35
- return acc;
36
- }, {});
37
- return Object.assign(options, userConfig);
38
- }
39
-
40
- return options;
38
+ return options;
41
39
  }
42
40
 
43
- module.exports = getConfig;
41
+ module.exports = getConfig;