Skip to content

Commit 85e6ebc

Browse files
committed
feat: ansi support
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 26ec30a commit 85e6ebc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4425
-5374
lines changed

.dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
attw
22
cefc
3+
chunker
34
commandoptst
45
commitlintrc
56
dedupe

.github/infrastructure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ repository:
169169
automated_security_fixes: true
170170
default_branch: main
171171
delete_branch_on_merge: true
172-
description: Wrap a string
172+
description: Wrap a string to a specified column width
173173
has_issues: true
174174
has_projects: true
175175
has_wiki: false

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Wrap a string
2828
- [`LinePadding`](#linepadding)
2929
- [`LinesInfo`](#linesinfo)
3030
- [`Options`](#options)
31+
- [`StripAnsi`](#stripansi)
3132
- [`ToString<[T]>`](#tostringt)
3233
- [Contribute](#contribute)
3334

@@ -195,13 +196,15 @@ Options for wrapping a string (`interface`).
195196
setting this to `true` will break long words.
196197
> 👉 **note**: setting this to `true` will break words.
197198
- `indent?` (`number` | `string` | `null` | `undefined`, optional)
198-
— the size of the indent, or a string used to indent each line
199+
— the size of the string to use for indenting each line (as a number or numeric), or the string itself
199200
- `padLeft?` (`number` | `string` | `null` | `undefined`, optional)
200-
— the size of the string to use for padding the left side of each line (as a number or numeric), or the string to use
201+
— the size of the string to use for padding the left side of each line (as a number or numeric), or the string itself
201202
- `padRight?` (`number` | `string` | `null` | `undefined`, optional)
202-
— the size of the string to use for padding the right side of each line (as a number or numeric), or the string to use
203+
— the size of the string to use for padding the right side of each line (as a number or numeric), or the string itself
203204
- `stringify?` ([`ToString`](#tostringt) | `null` | `undefined`, optional)
204205
— convert a value to a string
206+
- `stripAnsi?` ([`StripAnsi`](#stripansi) | `boolean` | `null` | `undefined`, optional)
207+
— whether to remove ANSI escape codes before wrapping, or a function to remove ANSI escape codes
205208
- `tabSize?` (`number` | `null` | `undefined`, optional)
206209
— the number of spaces a tab is equivalent to
207210
- default: `2`
@@ -210,6 +213,23 @@ Options for wrapping a string (`interface`).
210213
> 👉 **note**: lines are trimmed before applying indents or padding.
211214
- default: `true`
212215
216+
### `StripAnsi`
217+
218+
Remove ANSI escape codes from a string (`type`).
219+
220+
```ts
221+
type StripAnsi = (this: void, string: string) => string
222+
```
223+
224+
#### Parameters
225+
226+
- `string` (`string`)
227+
— the string containing ANSI escape codes
228+
229+
#### Returns
230+
231+
(`string`) The string with ANSI escape codes removed
232+
213233
### `ToString<[T]>`
214234
215235
Convert `value` to a string (`type`).

__fixtures__/ansi-fixture-01.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @file Fixtures - fixture01
3+
* @module fixtures/ansi/fixture01
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
import { chars } from '@flex-development/fsm-tokenizer'
8+
9+
/**
10+
* ANSI fixture #1.
11+
*
12+
* @type {string}
13+
*/
14+
export default `The ${colors.bold('quick')} brown` +
15+
chars.space +
16+
`${colors.red('fox jumped over ')}the ${colors.italic('lazy')}` +
17+
chars.space +
18+
colors.green('dog and then ran away with the unicorn.')

__fixtures__/ansi-fixture-02.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @file Fixtures - fixture2
3+
* @module fixtures/ansi/fixture2
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
import { chars } from '@flex-development/fsm-tokenizer'
8+
9+
/**
10+
* ANSI fixture #2.
11+
*
12+
* @type {string}
13+
*/
14+
export default colors.green('hello world') + chars.space + 'hey!'

__fixtures__/ansi-fixture-03.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Fixtures - fixture3
3+
* @module fixtures/ansi/fixture3
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
8+
/**
9+
* ANSI fixture #3.
10+
*
11+
* @type {string}
12+
*/
13+
export default colors.blue('hello') + '-world'

__fixtures__/ansi-fixture-04.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Fixtures - fixture4
3+
* @module fixtures/ansi/fixture4
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
8+
/**
9+
* ANSI fixture #4.
10+
*
11+
* @type {string}
12+
*/
13+
export default colors.green('helloworld')

__fixtures__/ansi-fixture-05.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Fixtures - fixture5
3+
* @module fixtures/ansi/fixture5
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
8+
/**
9+
* ANSI fixture #5.
10+
*
11+
* @type {string}
12+
*/
13+
export default colors.yellow('hello') + 'world'

__fixtures__/ansi-fixture-06.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Fixtures - fixture6
3+
* @module fixtures/ansi/fixture6
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
8+
/**
9+
* ANSI fixture #6.
10+
*
11+
* @type {string}
12+
*/
13+
export default colors.blue(' foo bar ')

__fixtures__/ansi-fixture-07.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @file Fixtures - fixture7
3+
* @module fixtures/ansi/fixture7
4+
*/
5+
6+
import colors from '@flex-development/colors'
7+
import { chars } from '@flex-development/fsm-tokenizer'
8+
9+
/**
10+
* ANSI fixture #7.
11+
*
12+
* @type {string}
13+
*/
14+
export default colors.bgGreen(chars.space + colors.black('ok') + chars.space)

0 commit comments

Comments
 (0)