Skip to content

Commit df00d69

Browse files
author
Frantisek Gejdos
committed
created
0 parents  commit df00d69

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<h1 align="center">cli-gradient</h1>
2+
3+
<p align="center">
4+
<strong>Add smooth gradient effects to your command line text, without any external dependencies.</strong>
5+
</p>
6+
7+
<p align="center">
8+
<a href="https://www.npmjs.com/package/cli-gradient"><img src="https://img.shields.io/npm/v/cli-gradient.svg" alt="NPM Version"></a>
9+
<a href="https://www.npmjs.com/package/cli-gradient"><img src="https://img.shields.io/npm/dt/cli-gradient.svg" alt="NPM Downloads"></a>
10+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
11+
</p>
12+
13+
## Features
14+
15+
- **Gradient Text**: Easily apply custom color gradients to your terminal output.
16+
- **Pure JavaScript**: No external dependencies, just a lightweight, self-contained solution.
17+
- **Configurable Gradients**: Specify your own start and end colors to create unique gradients.
18+
- **Cross-Platform**: Works seamlessly on Windows, macOS, and Linux terminals.
19+
20+
## Installation
21+
22+
Install the package using npm:
23+
24+
```
25+
npm install cli-gradient-pure
26+
```
27+
28+
## Usage
29+
30+
Import the `gradientText` function and use it to apply gradient effects to your text:
31+
32+
```javascript
33+
const { gradientText } = require('cli-gradient-pure');
34+
35+
console.log(gradientText('Hello, World!', { from: '#ff0000', to: '#0000ff' }));
36+
```
37+
38+
This will output the text "Hello, World!" with a smooth red-to-blue gradient.
39+
40+
## Options
41+
42+
The `gradientText` function accepts the following options:
43+
44+
| Option | Type | Description |
45+
| --- | --- | --- |
46+
| `from` | string | The starting color of the gradient (hex, rgb, or named color) |
47+
| `to` | string | The ending color of the gradient (hex, rgb, or named color) |
48+
49+
50+
## Contributing
51+
52+
If you find any issues or have suggestions for improvement, feel free to open a new issue or submit a pull request.
53+
## Note
54+
55+
- This project is just for my personal usage, if you want to support me you can give it a star on github
56+
- If you want something to add or fix you can contact me on twitter (@ddosntfcion)

index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function getGradientColor(percent, startColor, endColor) {
2+
const startR = parseInt(startColor.substring(1, 3), 16);
3+
const startG = parseInt(startColor.substring(3, 5), 16);
4+
const startB = parseInt(startColor.substring(5, 7), 16);
5+
6+
const endR = parseInt(endColor.substring(1, 3), 16);
7+
const endG = parseInt(endColor.substring(3, 5), 16);
8+
const endB = parseInt(endColor.substring(5, 7), 16);
9+
10+
const diffR = endR - startR;
11+
const diffG = endG - startG;
12+
const diffB = endB - startB;
13+
14+
const percentR = Math.floor(startR + (diffR * percent));
15+
const percentG = Math.floor(startG + (diffG * percent));
16+
const percentB = Math.floor(startB + (diffB * percent));
17+
18+
return `#${percentR.toString(16).padStart(2, '0')}${percentG.toString(16).padStart(2, '0')}${percentB.toString(16).padStart(2, '0')}`;
19+
}
20+
21+
function gradientText(text, options) {
22+
const { from, to, direction = 'right' } = options;
23+
let result = '';
24+
25+
for (let i = 0; i < text.length; i++) {
26+
const percent = direction === 'right' ? i / (text.length - 1) : (text.length - 1 - i) / (text.length - 1);
27+
const color = getGradientColor(percent, from, to);
28+
result += `\x1b[38;2;${parseInt(color.substring(1, 3), 16)};${parseInt(color.substring(3, 5), 16)};${parseInt(color.substring(5, 7), 16)}m${text[i]}\x1b[0m`;
29+
}
30+
31+
return result;
32+
}
33+
34+
module.exports = { gradientText };

package.json

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "cli-gradient",
3+
"version": "1.0.0",
4+
"description": "Add smooth gradient effects to your command line text, without any external dependencies.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/ddosnotification/cli-gradient.git"
12+
},
13+
"author": "ddosnotification",
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/ddosnotification/cli-gradient/issues"
17+
},
18+
"homepage": "https://github.com/ddosnotification/cli-gradient#readme",
19+
"keywords": [
20+
"cli",
21+
"gradient",
22+
"terminal",
23+
"text",
24+
"color",
25+
"console",
26+
"command-line",
27+
"ansi",
28+
"shell",
29+
"node",
30+
"javascript",
31+
"pure",
32+
"dependency-free",
33+
"utility",
34+
"effect",
35+
"style",
36+
"formatting",
37+
"visualization",
38+
"terminal-output",
39+
"text-styling",
40+
"cross-platform",
41+
"windows",
42+
"macos",
43+
"linux",
44+
"npm",
45+
"package",
46+
"tool",
47+
"text-effects",
48+
"color-gradient",
49+
"dynamic-text",
50+
"text-formatting",
51+
"terminal-customization",
52+
"console-logging",
53+
"command-prompt",
54+
"bash",
55+
"zsh",
56+
"powershell",
57+
"cmd",
58+
"terminal-ui",
59+
"text-decoration",
60+
"visual-enhancement",
61+
"terminal-aesthetics",
62+
"command-line-tools",
63+
"text-manipulation",
64+
"colorful-output",
65+
"terminal-styling",
66+
"console-text",
67+
"node-package",
68+
"node-module",
69+
"javascript-utilities",
70+
"dependency-minimalist",
71+
"lightweight-solution",
72+
"terminal-customizer",
73+
"console-beautifier",
74+
"text-gradient",
75+
"command-line-gradient",
76+
"terminal-text-effects"
77+
]
78+
}

0 commit comments

Comments
 (0)