{"id":15066379,"url":"https://github.com/tienisto/consola","last_synced_at":"2025-04-10T14:21:56.961Z","repository":{"id":221607946,"uuid":"754663921","full_name":"Tienisto/consola","owner":"Tienisto","description":"A utility library to help developing command-line applications in Dart. Provides screen manipulation, ANSI escape codes, and more.","archived":false,"fork":false,"pushed_at":"2024-02-15T21:32:55.000Z","size":30,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T13:04:07.217Z","etag":null,"topics":["cli","dart"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tienisto.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":"2024-02-08T14:30:29.000Z","updated_at":"2024-08-20T01:53:53.000Z","dependencies_parsed_at":"2024-02-15T22:33:53.478Z","dependency_job_id":null,"html_url":"https://github.com/Tienisto/consola","commit_stats":null,"previous_names":["tienisto/consola"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tienisto%2Fconsola","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tienisto%2Fconsola/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tienisto%2Fconsola/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tienisto%2Fconsola/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tienisto","download_url":"https://codeload.github.com/Tienisto/consola/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233935,"owners_count":21069493,"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":["cli","dart"],"created_at":"2024-09-25T01:06:49.597Z","updated_at":"2025-04-10T14:21:56.944Z","avatar_url":"https://github.com/Tienisto.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consola\n\n[![pub package](https://img.shields.io/pub/v/consola.svg)](https://pub.dev/packages/consola)\n![ci](https://github.com/Tienisto/consola/actions/workflows/ci.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA utility library to help developing command-line applications in Dart. Provides screen manipulation, ANSI escape codes, and more.\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n- [Cursor Manipulation](#cursor-manipulation)\n- [Screen Manipulation](#screen-manipulation)\n- [Colors](#colors)\n- [Dimensions](#dimensions)\n- [User Input](#user-input)\n- [Components](#components)\n  - [Progress Bar](#-progress-bar)\n- [ANSI Escape Codes](#ansi-escape-codes)\n- [Mocking](#mocking)\n- [Examples](#examples)\n  - [Rerender a section of the screen](#-rerender-a-section-of-the-screen)\n\n## Getting Started\n\n```yaml\n# pubspec.yaml\ndependencies:\n  consola: \u003cversion\u003e\n```\n\n## Cursor Manipulation\n\nYou can move the cursor around.\n\n```dart\nvoid main() {\n  Console.moveUp();\n  Console.moveTo(22, 41);\n  Console.moveToTopLeft();\n}\n```\n\n## Screen Manipulation\n\nYou can clear a section of the screen.\n\n```dart\nvoid main() {\n  Console.clearScreen();\n  Console.clearLine();\n  Console.clearCurrentToScreenEnd();\n}\n```\n\n## Colors\n\nYou can colorize the text.\n\n```dart\nvoid main() {\n  Console.write('Hello ', foregroundColor: SimpleColor.green);\n  Console.write('World', backgroundColor: SimpleColor.red);\n}\n```\n\n## Dimensions\n\nYou can get the dimensions of the terminal.\n\n```dart\nvoid main() {\n  int width = Console.getWindowWidth();\n  int height = Console.getWindowHeight();\n}\n```\n\n## User Input\n\nYou can read the user input in a type-safe way.\n\n```dart\nvoid main() {\n  int? age = Console.readInt(prompt: 'Enter your age: ');\n  Console.writeLine('You are $age years old.');\n}\n```\n\n## Components\n\nThere is a set of components that you can use to speed up the development of your command-line applications.\n\nThe state is stored in the component. You can draw the component by calling `Console.draw(component)`.\n\n### ➤ Progress Bar\n\nA horizontal progress bar.\n\n```text\nProgress A: [##################              ] 58%\nProgress B: [=================\u003e--------------] 58%\nProgress C: |##################..............| 12 MB/s 58%\n```\n\n```dart\nvoid main() {\n  Console.clearScreen();\n\n  final progressBar = ProgressBar.atPosition(\n    total: 50,\n    width: 100,\n    position: ConsoleCoordinate(1, 2),\n    head: 'Progress A: ',\n    barFillCharacter: '#',\n    tailBuilder: (_, __, percent) =\u003e ' ${percent.toStringAsFixed(0)}%',\n  );\n\n  for (var i = 0; i \u003c= 50; i++) {\n    progressBar.current = i;\n    Console.draw(progressBar);\n    sleep(Duration(milliseconds: 50));\n  }\n}\n```\n\n## ANSI Escape Codes\n\nYou can access the underlying ANSI escape codes by accessing the `ConsoleStrings` class.\n\n```dart\nvoid main() {\n  String eraseScreen = ConsoleStrings.eraseScreen;\n  String esc = ConsoleStrings.escape;\n  String csi = ConsoleStrings.csi;\n}\n```\n\n## Mocking\n\nYou can also mock the `Console` by setting `Console.instance` to a mocked object.\n\n```dart\nimport 'package:your_package/gen/env.g.dart';\n\nclass MockConsoleExecutor extends ConsoleExecutor {\n  @override\n  void clearScreen({bool resetCursor = true}) {\n    print('Screen cleared');\n  }\n}\n\nvoid main() {\n  Console.clearScreen(); // clears the screen\n  Console.instance = MockConsoleExecutor();\n  Console.clearScreen(); // prints \"Screen cleared\"\n}\n```\n\n## Examples\n\n### ➤ Rerender a section of the screen\n\nTo rerender a section of the screen, you need to save and restore the cursor position.\n\n```dart\nvoid main() {\n  // Saving and restoring cursor position is relative.\n  // It doesn't work if the cursor is already at the bottom so\n  // we need to add some empty lines to make sure it works.\n  Console.addEmptyLinesToBottom(2);\n  Console.saveCursorPosition();\n\n  Console.writeLine('Survey (1/2)');\n  final name = Console.readLine(prompt: 'Enter name: ');\n\n  Console.restoreCursorPosition();\n  Console.clearCurrentToScreenEnd();\n\n  Console.writeLine('Survey (2/2)');\n  final age = Console.readInt(prompt: 'Enter age: ');\n  Console.writeLine('Hello, $name! You are $age years old.');\n}\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2024 Tien Do Nam\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftienisto%2Fconsola","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftienisto%2Fconsola","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftienisto%2Fconsola/lists"}