diff --git a/packages/ansi_styles/README.md b/packages/ansi_styles/README.md index 282397f..57c20ef 100644 --- a/packages/ansi_styles/README.md +++ b/packages/ansi_styles/README.md @@ -6,12 +6,11 @@ Melos docs.page -Documentation • +DocumentationLicense --- - ## Usage Import the package: @@ -44,6 +43,23 @@ String styledText = AnsiStyles.red.underline('Underlined red text'); String cleanText = AnsiStyles.strip(styledText); ``` +### String Extension + +This package also provides a String Extension which can be imported: + +```dart +import 'package:ansi_styles/src/extension.dart'; +``` + +Styling methods are now available on Strings: + +```dart +void main() { + print('hello'.bold.red); + print('hello'.bold.red.underline.bgBlack); +} +``` + ## License - See [LICENSE](/LICENSE) @@ -58,4 +74,3 @@ String cleanText = AnsiStyles.strip(styledText); Built and maintained by Invertase.

- diff --git a/packages/ansi_styles/example/main.dart b/packages/ansi_styles/example/main.dart index 3da6806..353cbfc 100644 --- a/packages/ansi_styles/example/main.dart +++ b/packages/ansi_styles/example/main.dart @@ -1,5 +1,6 @@ // ignore_for_file: avoid_print import 'package:ansi_styles/ansi_styles.dart'; +import 'package:ansi_styles/src/extension.dart'; void main() { print(AnsiStyles.red.underline('Underlined red text')); @@ -11,4 +12,7 @@ void main() { AnsiStyles.strikethrough .bgRgb(255, 165, 0)('Strikethrough text with an orange background'), ); + // Using string extension + print('hello'.bold.red); + print('hello'.bold.red.underline.bgBlack); } diff --git a/packages/ansi_styles/lib/src/extension.dart b/packages/ansi_styles/lib/src/extension.dart new file mode 100644 index 0000000..4bb1203 --- /dev/null +++ b/packages/ansi_styles/lib/src/extension.dart @@ -0,0 +1,52 @@ +import '../ansi_styles.dart'; + +extension AnsiStylesStringExtension on String { + String get reset => AnsiStyles.reset(this); + String get bold => AnsiStyles.bold(this); + String get dim => AnsiStyles.dim(this); + String get italic => AnsiStyles.italic(this); + String get underline => AnsiStyles.underline(this); + String get blink => AnsiStyles.blink(this); + String get inverse => AnsiStyles.inverse(this); + String get hidden => AnsiStyles.hidden(this); + String get strikethrough => AnsiStyles.strikethrough(this); + String get black => AnsiStyles.black(this); + String get red => AnsiStyles.red(this); + String get green => AnsiStyles.green(this); + String get yellow => AnsiStyles.yellow(this); + String get blue => AnsiStyles.blue(this); + String get magenta => AnsiStyles.magenta(this); + String get cyan => AnsiStyles.cyan(this); + String get white => AnsiStyles.white(this); + String get blackBright => AnsiStyles.blackBright(this); + String get redBright => AnsiStyles.redBright(this); + String get greenBright => AnsiStyles.greenBright(this); + String get yellowBright => AnsiStyles.yellowBright(this); + String get blueBright => AnsiStyles.blueBright(this); + String get magentaBright => AnsiStyles.magentaBright(this); + String get cyanBright => AnsiStyles.cyanBright(this); + String get whiteBright => AnsiStyles.whiteBright(this); + String get bgBlack => AnsiStyles.bgBlack(this); + String get bgRed => AnsiStyles.bgRed(this); + String get bgGreen => AnsiStyles.bgGreen(this); + String get bgYellow => AnsiStyles.bgYellow(this); + String get bgBlue => AnsiStyles.bgBlue(this); + String get bgMagenta => AnsiStyles.bgMagenta(this); + String get bgCyan => AnsiStyles.bgCyan(this); + String get bgWhite => AnsiStyles.bgWhite(this); + String get bgBlackBright => AnsiStyles.bgBlackBright(this); + String get bgRedBright => AnsiStyles.bgRedBright(this); + String get bgGreenBright => AnsiStyles.bgGreenBright(this); + String get bgYellowBright => AnsiStyles.bgYellowBright(this); + String get bgBlueBright => AnsiStyles.bgBlueBright(this); + String get bgMagentaBright => AnsiStyles.bgMagentaBright(this); + String get bgCyanBright => AnsiStyles.bgCyanBright(this); + String get bgWhiteBright => AnsiStyles.bgWhiteBright(this); + String get grey => AnsiStyles.grey(this); + String get bgGrey => AnsiStyles.bgGrey(this); + String get gray => AnsiStyles.gray(this); + String get bgGray => AnsiStyles.bgGray(this); + String get strip => AnsiStyles.strip(this); + String rgb(num? r, num? g, num? b) => AnsiStyles.rgb(r, g, b).call(this); + String bgRgb(num? r, num? g, num? b) => AnsiStyles.bgRgb(r, g, b).call(this); +}