@syncify/ansi
Version:
ANSI Colors, Symbols and TUI related terminal enchancements for Syncify.
241 lines (186 loc) ⢠6.79 kB
Markdown
for the [Syncify CLI](https://syncify.sh) Shopify theme development tool. This module provides CLI enhancements, helpers and various other TUI logic which are used in console logging and reporting for Syncify.
The module should be included within distributed builds. Given the way the minification algorithms work in most build tools and the hard depedencies this package requires, failure to include within your builds will likely result in headaches.
```bash
$ pnpm add @syncify/ansi -D
```
Terminal colors are exposed and made available using [Ansis](https://github.com/webdiscus/ansis). There are custom colors and raw access to `Ansis` is available.

























There are various symbols (characters) available as named exports. Symbols in the CLI are color wrapped and injected into strings when composing logs and messaged etc.
### Character Helpers
Character are `const` exports, they are output in `darkGray` by default.
```js
import {
PIP // |
HSH // #
PLS // +
MIN // -
COM // ,
CHK // ā
BAD // š
COL // :
ARR // ā
CHV // āø
ARL // ā„
TLD // ~
DSH // ā
} from '@syncify/ansi'
```
Infix wrappers are `const` exports, they are output in `darkGray` by default.
```js
import {
LPR // (
RPR // )
LCB // {
RCB // }
LSB // [
RSB // ]
LAN // <
RAN // >
} from '@syncify/ansi'
```
Tree characters available on the `Tree` named export and are output in `darkGray` by default. Characters are also available in `red` and `yellow` colors.
<!-- prettier-ignore-->
```js
import { Tree } from '@syncify/ansi';
Tree.open // āā
Tree.stub // ā
Tree.dash // āā
Tree.line // ā
Tree.base // āā
Tree.next // \nā
Tree.after // ā\n
Tree.wrap // \nā\n
Tree.indent.edge // āāāā¬ā
Tree.indent.line // ā ā
Tree.indent.stub // ā ā
Tree.indent.dash // ā āā
Tree.indent.base // ā āā
Tree.indent.fall // āāāā
```
Log message generator instance which can be used to compose a complex output log.
```js
import { Create } from '@syncify/ansi';
const message = Create();
message.BR;
message.NL;
message.Break();
message.Template();
message.Update();
message.Context();
message.Dash();
message.End();
message.Error();
message.Get();
message.Inline();
message.Insert();
message.Line();
message.Newline();
message.Pop();
message.Remove();
message.Ruler();
message.Top();
message.Warn();
message.Wrap();
message.toLine();
message.toRaw();
message.toString();
message.Log();
```
Symbol Spinner utility which will persist a terminal animation.
```js
import { spinner } from '@syncify/ansi';
spinner('loading', {
line: true,
action: {},
color: 'pink',
style: 'spinning'
});
spinner.update('');
spinner.stop();
```
Regular expression replacers, which capture various text sequences or characters, excluding any ansi occurrences.
<!-- prettier-ignore-->
```js
import { capture } from '@syncify/ansi'
capture(/(regex)/, '', match => {}) // sugar matching
capture.punctuation('', match => {}) // [$<[\]>{}:,-]
capture.quoted('', match => {}) // "double" and "single"
capture.brackets('', match => {}) // [ and ]
capture.braces('', match => {}) // { and }
capture.angles('', match => {}) // < and >
capture.colons('', match => {}) // :
capture.dollar('', match => {}) // $
capture.dash('', match => {}) // -
capture.commas('', match => {}) // ,
```
Progress bar utility is available on the `progress` named export. This function returns an instance with methods.
```bash
ā°ā°ā°ā°ā°ā°ā°ā°ā°ā°ā±ā±ā±ā±ā±ā±ā±ā±ā±ā± 50%
```
<!-- prettier-ignore-->
```js
import { progress } from '@syncify/ansi';
const loading = progress(25, {
showPercentage: true,
barColor: 'neonGreen',
percentColor: 'whiteBright',
barSize: 40,
clearOnComplete: false
});
loading.increment(1); // Increment progress
loading.decrement(1); // Decrement progress
loading.render() // Render the progress bar, returns string
loading.stop() // Stop progress
loading.percent // Returns loading percentage
```
The module also exposes a helper utility for obtaining the developers terminal size and will return some information about the terminal dimensions.
```js
import { tsize } from '@syncify/ansi';
const {
wrap, // number
cols, // number
row // number
} = tsize();
```
This package is designed for usage within [Syncify](https://syncify.sh). Contributions are not accepted unless they pertain to the core Syncify module. If contributions fall into that category, fork the Syncify project.
Terminal utilities