@jlbyte/ansi
v1.2.4
Published
ANSI library collection
Maintainers
Readme
ANSI
It is core ansi library
Install:
npm i @jlbyte/ansi --prefer-offline
Usage
Basic of ansi escape is code
import {code} from '@jlbyte/ansi';
console.log(code);Icon
Terminal safe icon collection
import {icon} from '@jlbyte/ansi';
console.log(icon);Style
Use textStyle in code
import { style } from "@jlbyte/ansi";
console.log('Normal text', style.underline('Underline'), 'Not underline')
console.log(code.textStyle)Color
import { color } from '@jlbyte/ansi';
const { fg, fgBright, bg, bgBright, fg256, fgRGB, bg256, bgRGB } = color;
console.log( fg.red('Text red') );
console.log( fgBright.red('Text red') );
console.log( bg.red('Text red') );
console.log( bgBright.red('Text red') );Note: there is no gray color, use
[fg|bg]Bright.blackinstead.
HTML
Convert ansi to html tag using inline css
- Check raw output
import { color, html } from "@jlbyte/ansi";
const { fg, bg, fgRGB } = color;
const sentence = [
`Color ${fg.red('red')} and ${bg.yellow('Yellow')} background`,
`This is RGB ${fgRGB([238, 75, 43], 'Bright Red')} actually`
];
console.log(html(sentence[0]));
console.log(html(sentence[1]))- Inside HTML script
<script type="importmap">
{
"imports": {
"@jlbyte/ansi": "https://cdn.jsdelivr.net/npm/@jlbyte/[email protected]/+esm"
}
}
</script>
<pre id ="ouput"></pre>
<script type="module">
import { icon, html, color } from '@jlbyte/ansi';
const { fg, fgBright, bg, bgBright } = color;
const output = document.getElementById('output');
output.innerHTML += html(`Color ${fgBright.red('red')}`)+'<br>';
output.innerHTML += html(`And ${bg.yellow('Yellow')} background`)+'<br>';
output.innerHTML += `Icons<br> ${JSON.stringify( icon, 0, 2)}`;
</script>Tips
Another useful packages
- for box - see boxen
- for spinner - see yocto-spinner
- for table - see cli-table3
- for link - see termi-link
- for progress see progress
