Skip to content

Commit

Permalink
Renamed stripAnsi to removeAnsi
Browse files Browse the repository at this point in the history
  • Loading branch information
simphotonics committed Sep 8, 2023
1 parent 447d44e commit 324c36a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Use the String extension functions [`modify`][modify] to add new modifiers or
to replace existing ones. The replacement method can be adjusted by setting the
optional argument `method`.

Use the function [`stripAnsi`][stripAnsi] to remove
Use the function [`removeAnsi`][removeAnsi] to remove
all Ansi modifier from a string.

```Dart
Expand Down Expand Up @@ -47,7 +47,7 @@ void main(List<String> args) {
yellowGreen.modify(Ansi.magenta, method: Replace.clearPrevious);
/// Strip all Ansi modifiers.
print('$yellowGreen, $magenta, ${magenta.stripAnsi()}');
print('$yellowGreen, $magenta, ${magenta.removeAnsi()}');
}
```

Expand Down Expand Up @@ -81,4 +81,4 @@ at the [issue tracker][tracker].

[modify]: https://pub.dev/documentation/ansi_modifier/doc/api/ansi_modifier/AnsiModifier/modify.html

[clearAnsi]: https://pub.dev/documentation/ansi_modifier/doc/api/ansi_modifier/AnsiModifier/asyncGroup.html
[removeAnsi]: https://pub.dev/documentation/ansi_modifier/doc/api/ansi_modifier/AnsiModifier/removeAnsi.html
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main(List<String> args) {
yellowGreen.modify(Ansi.magenta, method: Replace.clearPrevious);
/// Strip all Ansi modifiers.
print('$yellowGreen, $magenta, ${magenta.stripAnsi()}');
print('$yellowGreen, $magenta, ${magenta.removeAnsi()}');
}
```

Expand Down
2 changes: 1 addition & 1 deletion example/bin/color_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ void main(List<String> args) {
yellowGreen.modify(Ansi.magenta, method: Replace.clearPrevious);

/// Strip all Ansi modifiers.
print('$yellowGreen, $magenta, ${magenta.stripAnsi()}');
print('$yellowGreen, $magenta, ${magenta.removeAnsi()}');
}
4 changes: 2 additions & 2 deletions lib/src/ansi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ extension AnsiModifier on String {
(AnsiOutput.enabled, Replace.none) =>
(modifier.code + this)._appendReset,
(AnsiOutput.enabled, Replace.clearPrevious) =>
modifier.code + stripAnsi() + resetSeq,
modifier.code + removeAnsi() + resetSeq,
};

/// Returns the string unmofified if `this` ends with [resetSeq]. Otherwise
Expand All @@ -222,7 +222,7 @@ extension AnsiModifier on String {
static final matchAnsi = RegExp(r'\u001B\[(\d+|;)+m', unicode: true);

/// Removes all Ansi modifiers and returns the resulting string.
String stripAnsi() {
String removeAnsi() {
return isEmpty ? this : replaceAll(matchAnsi, '');
}
}
6 changes: 3 additions & 3 deletions test/ansi_modifier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ void main() {
final redMoon = moon.modify(Ansi.red);
final greenPlanet = planet.modify(Ansi.green);
test('simple string', () {
expect(redMoon.stripAnsi(), moon);
expect((' ' + redMoon).stripAnsi(), ' ' + moon);
expect(redMoon.removeAnsi(), moon);
expect((' ' + redMoon).removeAnsi(), ' ' + moon);
});
test('complex string', () {
expect((redMoon + greenPlanet).stripAnsi(), moon + planet);
expect((redMoon + greenPlanet).removeAnsi(), moon + planet);
});
});
group('Replace:', () {
Expand Down

0 comments on commit 324c36a

Please sign in to comment.