{"id":18521773,"url":"https://github.com/simphotonics/ansi_modifier","last_synced_at":"2026-01-05T02:54:39.323Z","repository":{"id":193524251,"uuid":"688918856","full_name":"simphotonics/ansi_modifier","owner":"simphotonics","description":"Ansi modifiers for Dart.","archived":false,"fork":false,"pushed_at":"2024-09-16T11:11:25.000Z","size":332,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T04:43:25.762Z","etag":null,"topics":["ansi","color","console","escape","modifier"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/ansi_modifier","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simphotonics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-08T11:37:21.000Z","updated_at":"2024-11-07T12:24:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"d3645e41-73dd-4c43-9011-e71de56e99e6","html_url":"https://github.com/simphotonics/ansi_modifier","commit_stats":null,"previous_names":["simphotonics/ansi_modifier"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fansi_modifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fansi_modifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fansi_modifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fansi_modifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simphotonics","download_url":"https://codeload.github.com/simphotonics/ansi_modifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248012864,"owners_count":21033254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi","color","console","escape","modifier"],"created_at":"2024-11-06T17:27:34.161Z","updated_at":"2026-01-05T02:54:39.278Z","avatar_url":"https://github.com/simphotonics.png","language":"Dart","readme":"# Ansi Modifier\n[![Dart](https://github.com/simphotonics/ansi_modifier/actions/workflows/dart.yml/badge.svg)](https://github.com/simphotonics/ansi_modifier/actions/workflows/dart.yml)\n\n## Introduction\n\nThe package provides the class [`Ansi`][Ansi] holding ANSI modifier codes and\nthe String extension methods [`style`][style] and [`clearStyle`][clearStyle]\nfor adding, replacing, and removing ANSI modifiers.\nIt provides Ansi codes for changing the current cursor position.\n\n## Usage\n\nInclude [`ansi_modifier`][ansi_modifier] as a dependency\n in your `pubspec.yaml` file.\n\n\n### 1. Changing the Font Style and Colour of Console Output\nUse the String extension function [`style`][style] to add new modifiers or\nto replace existing ones. Use the function [`clearStyle`][clearStyle] to remove\nall Ansi modifier from a string.\n\n```Dart\nimport 'package:ansi_modifier/src/ansi.dart';\n\nvoid main(List\u003cString\u003e args) {\n  // Create colorized strings.\n  print('\\nCreate colorized strings:');\n  final blue = 'blueberry'.style(Ansi.blue + Ansi.italic);\n  final green = 'green apple'.style(Ansi.green);\n  final blueGreen = blue +\n      ' and ' +\n      green.style(\n        Ansi.bold,\n        method: Replace.none,\n      );\n  print('$blue, $green, $blueGreen');\n\n  // Modify a previously colorized string.\n  print('\\nModify previously colorized strings:');\n\n  // Create custom Ansi modifier.\n  final customModifier = Ansi.combine({Ansi.yellow, Ansi.bold, Ansi.underline});\n\n  // Replace first modifier:\n  final yellowGreen = blueGreen.style(customModifier, method: Replace.first);\n\n  // Replace all modifiers.\n  final magenta =\n      yellowGreen.style(Ansi.magenta, method: Replace.clearPrevious);\n\n  // Strip all Ansi modifiers.\n  print('$yellowGreen, $magenta, ${magenta.clearStyle()}\\n');\n}\n```\n\nRunnig the program above produces the following output:\n![Console Output](https://raw.githubusercontent.com/simphotonics/ansi_modifier/main/images/console_output.gif)\n\n\n### 2. Moving the Current Cursor Position\n\nAnsi codes for moving the current cursor position can be constructed using the\nconstructors `.cursorUp`, `.cursorDown`,\n`.cursorForward`,\n`.cursorBack`,\n`.cursorNextLine`,\n`.cursorPreviousLine`, and\n`.cursorToColumn`.\n\nThe example below shows how to change the cursor position\nusing Dart's `stdout` function `write` in order to display a\nprogress indicator:\n\n```Dart\nimport 'dart:io';\n\nimport 'package:ansi_modifier/src/ansi.dart';\n\nvoid main(List\u003cString\u003e args) async {\n\n  // Emit a periodic stream\n  final stream = Stream\u003cString\u003e.periodic(\n      const Duration(milliseconds: 500),\n      (i) =\u003e\n          'Progress timer: '.style(Ansi.grey) +\n          ((i * 500 / 1000).toString() + ' s').style(Ansi.green));\n\n  // Listen to the stream and output progress indicator\n  final subscription = stream.listen((event) {\n    // Place cursor to first column to overwrite previous string.\n    stdout.write(Ansi.cursorToColumn(1));\n    stdout.write(event);\n  });\n\n  /// Add delay ...\n  await Future.delayed(Duration(seconds: 5), () {\n    print('\\n');\n    print('After 5 seconds.'.style(Ansi.green));\n  });\n\n  await subscription.cancel();\n}\n```\nThe program above produces the following console output:\n![Progress Indicator](https://raw.githubusercontent.com/simphotonics/ansi_modifier/main/images/progress_indicator.gif)\n\n\n## Tips and Tricks\n\n* The String extension method [`style`][style] supports different\nreplacement modes that can be adjusted using the optional argument `method`.\n\n* Ansi codes can be combined using the addition operator `Anis.red + Ansi.bold`,\nor by using the factory constructor `Ansi.combine`.\n\n* Ansi output can be globally disabled by setting\n`Ansi.status = AnsiOutput.disabled` or by using the option:\n  ```Console\n  $ dart --define=isMonochrome=true example/bin/color_example.dart\n\n  ```\n\n## Features and bugs\n\nIf some Ansi modifiers are missing please file an enhancement request\nat the [issue tracker][tracker].\n\n[tracker]: https://github.com/simphotonics/ansi_modifier/issues\n\n[ansi_modifier]: https://pub.dev/packages/ansi_modifier\n\n[Ansi]: https://pub.dev/packages/ansi_modifier/latest/ansi_modifier/Ansi-class.html\n\n[style]: https://pub.dev/documentation/ansi_modifier/latest/ansi_modifier/AnsiModifier/style.html\n\n[clearStyle]: https://pub.dev/documentation/ansi_modifier/latest/ansi_modifier/AnsiModifier/clearStyle.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fansi_modifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimphotonics%2Fansi_modifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fansi_modifier/lists"}