Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayecue/another-ansi
Another ansi style library
https://github.com/ayecue/another-ansi
ansi
Last synced: 29 days ago
JSON representation
Another ansi style library
- Host: GitHub
- URL: https://github.com/ayecue/another-ansi
- Owner: ayecue
- License: mit
- Created: 2022-11-24T09:22:49.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-25T16:47:04.000Z (about 2 years ago)
- Last Synced: 2024-12-20T18:39:39.744Z (about 1 month ago)
- Topics: ansi
- Language: TypeScript
- Homepage:
- Size: 271 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# another-ansi
[![another-ansi](https://circleci.com/gh/ayecue/another-ansi.svg?style=svg)](https://circleci.com/gh/ayecue/another-ansi)
Inspired by [ansi-styles](https://github.com/chalk/ansi-styles).
## Install
```sh
npm install another-ansi
```## Usage
```js
import { AnotherAnsiProvider, ColorType } from 'another-ansi';const p = new AnotherAnsiProvider();
// red text color
console.log(p.color(ColorType.Red, 'test'));// red text color + green background color
console.log(p.bgColor(ColorType.Green, p.color(ColorType.Red, 'test')));// red text color via hex
console.log(p.colorWithHex('#FF0000', 'test'));// red text color via rgb
console.log(p.colorWithRgb(255, 0, 0, 'test'));// bold text
console.log(p.modify(ModifierType.Bold, 'test'));// clear console - only osx
console.log(p.command(CommandType.Clear));
```## Escape sequences
```ts
EscapeSequence.Unicode // '\u001B' by default
EscapeSequence.Hex // '\x1b'
```Can be used to define escape sequence in ansi provider:
```ts
const p = new AnotherAnsiProvider(EscapeSequence.Hex);
p.color(ColorType.Red, 'test'); // \x1b[31mtest\x1b[39m
```## Modifier + Colors
Modifier:
```ts
enum ModifierType {
Reset,
Bold,
Dim,
Italic,
Underline,
Overline,
Inverse,
Hidden,
Strikethrough
}
```Colors:
```ts
enum ColorType {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
BlackBright,
Gray,
Grey,
RedBright,
GreenBright,
YellowBright,
BlueBright,
MagentaBright,
CyanBright,
WhiteBright
}
```Commands:
```ts
enum CommandType {
Clear
}
```## Style Object
```ts
const styleObject = provider.getStyleObject();// red text color
console.log(`${styleObject.color.red.open}test${styleObject.color.close}`);// red background color
console.log(`${styleObject.bgColor.red.open}test${styleObject.bgColor.close}`);// red background color
console.log(`${styleObject.bgColorBy16m(255, 0, 0)}test${styleObject.bgColor.close}`);
```