| 
 | 1 | +# Terminal Color Parser  | 
 | 2 | + | 
 | 3 | +This package is an ANSI/xterm256 color parser. You can get the list of colored segments by creating  | 
 | 4 | +a `ColorParser` instance and calling `parse()` method.  | 
 | 5 | + | 
 | 6 | +```dart  | 
 | 7 | +import 'package:terminal_color_parser/terminal_color_parser.dart';  | 
 | 8 | +
  | 
 | 9 | +final coloredText = ColorParser('Hello, \x1B[32mworld\x1B[0m!').parse();  | 
 | 10 | +
  | 
 | 11 | +print(coloredText);  | 
 | 12 | +// ==> ColoredText("Hello, ", 0:0, , ()), ColoredText("world", 32:0, , ()), ColoredText("!", 0:0, , ())]  | 
 | 13 | +
  | 
 | 14 | +var i = 0;  | 
 | 15 | +for (final token in coloredText) {  | 
 | 16 | +  print('Token #$i: ${token.formatted}');  | 
 | 17 | +  print('  - Text: ${token.text}');  | 
 | 18 | +  print('  - Foreground: ${token.fgColor}');  | 
 | 19 | +  print('  - Background: ${token.bgColor}');  | 
 | 20 | +  print('  - Bold: ${token.bold}');  | 
 | 21 | +  print('  - Italic: ${token.italic}');  | 
 | 22 | +  print('  - Underline: ${token.underline}');  | 
 | 23 | +  print('  - Styles: ${token.styles}');  | 
 | 24 | +  i++;  | 
 | 25 | +}  | 
 | 26 | +```  | 
 | 27 | + | 
 | 28 | +You can also re-format the ANSI codes by using the `formatted` property on each token.  | 
 | 29 | + | 
 | 30 | +```dart  | 
 | 31 | +final tokens = [  | 
 | 32 | +  ColorToken(text: 'Hello, ', fgColor: 0, bgColor: 0),  | 
 | 33 | +  ColorToken(  | 
 | 34 | +    text: 'world',  | 
 | 35 | +    fgColor: 32,  | 
 | 36 | +    bgColor: 0,  | 
 | 37 | +    styles: {StyleByte.underline},  | 
 | 38 | +  ),  | 
 | 39 | +  ColorToken(text: '!', fgColor: 0, bgColor: 0),  | 
 | 40 | +];  | 
 | 41 | +
  | 
 | 42 | +var i = 0;  | 
 | 43 | +for (final token in coloredText) {  | 
 | 44 | +  print('Token #$i: ${token.formatted}');  | 
 | 45 | +  print('  - Text: ${token.text}');  | 
 | 46 | +  print('  - Foreground: ${token.fgColor}');  | 
 | 47 | +  print('  - Background: ${token.bgColor}');  | 
 | 48 | +  print('  - Bold: ${token.bold}');  | 
 | 49 | +  print('  - Italic: ${token.italic}');  | 
 | 50 | +  print('  - Underline: ${token.underline}');  | 
 | 51 | +  print('  - Styles: ${token.styles}');  | 
 | 52 | +  i++;  | 
 | 53 | +}  | 
 | 54 | +```  | 
 | 55 | + | 
 | 56 | +## Contributing  | 
 | 57 | + | 
 | 58 | +I am developing this package on my free time, so any support, whether code, issues, or just stars is  | 
 | 59 | +very helpful to sustaining its life. If you are feeling incredibly generous and would like to donate  | 
 | 60 | +just a small amount to help sustain this project, I would be very very thankful!  | 
 | 61 | + | 
 | 62 | +<a href='https://ko-fi.com/casraf' target='_blank'>  | 
 | 63 | +  <img height='36' style='border:0px;height:36px;'  | 
 | 64 | +    src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3'  | 
 | 65 | +    alt='Buy Me a Coffee at ko-fi.com' />  | 
 | 66 | +</a>  | 
 | 67 | + | 
 | 68 | +I welcome any issues or pull requests on GitHub. If you find a bug, or would like a new feature,  | 
 | 69 | +don't hesitate to open an appropriate issue and I will do my best to reply promptly.  | 
0 commit comments