{"id":15008397,"url":"https://github.com/leadcodedev/commander","last_synced_at":"2025-05-08T03:51:40.040Z","repository":{"id":244309227,"uuid":"814863370","full_name":"LeadcodeDev/commander","owner":"LeadcodeDev","description":"🛠️ Commander is a Dart library for creating user command line interfaces within the terminal thank to tui components.","archived":false,"fork":false,"pushed_at":"2024-11-07T00:36:59.000Z","size":180,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-06T11:11:11.075Z","etag":null,"topics":["cli","components","dartlang"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/commander_ui","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/LeadcodeDev.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-06-13T21:44:06.000Z","updated_at":"2024-12-31T07:19:58.000Z","dependencies_parsed_at":"2024-11-07T01:24:57.912Z","dependency_job_id":"bc1d5d26-e93e-4f26-b24c-1c89d5bc21ed","html_url":"https://github.com/LeadcodeDev/commander","commit_stats":null,"previous_names":["leadcodedev/commander"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeadcodeDev%2Fcommander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeadcodeDev%2Fcommander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeadcodeDev%2Fcommander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeadcodeDev%2Fcommander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeadcodeDev","download_url":"https://codeload.github.com/LeadcodeDev/commander/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252996228,"owners_count":21837618,"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","components","dartlang"],"created_at":"2024-09-24T19:18:19.848Z","updated_at":"2025-05-08T03:51:40.013Z","avatar_url":"https://github.com/LeadcodeDev.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Commander\n\nCommander is a Dart library for creating user interfaces within the terminal.\n\nIt provides interactive components such as option selection and text input with advanced management of\nuser input.\n\n## Installation\n\nTo use Commander in your Dart project, add this to your `pubspec.yaml` file :\n```yaml\ndependencies:\n  commander_ui: ^2.0.0\n```\n\nThen run `pub get` to install the dependencies.\n\n## Usage\n\n### Ask component\n\nA simple example of using Commander to create an ask component :\n\n- ✅ Secure\n- ✅ Integrated or custom validators\n- ✅ Default value\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.ask('What is your email ?',\n    validate: (validator) =\u003e validator\n      ..notEmpty(message: 'Name cannot be empty :)')\n      ..email(message: 'Please enter a valid email'));\n\n  // Custom validator\n  final value = await commander.ask('What is your name ?',\n    validate: (validator) =\u003e validator\n      ..validate((value) =\u003e value == 'Bob' \n          ? 'Bob is not allowed' \n          : null));\n\n  print(value);\n}\n```\n\n### Number component\n\nA simple example of using Commander to create a number component :\n\n- ✅ Integrated or custom validators\n- ✅ Default value\n- ✅ Custom rendering\n- ✅ `double` or `int` (`num` by default)\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.number('What is your age ?',\n      interval: 1,\n      onDisplay: (value) =\u003e value?.toStringAsFixed(2),\n      validate: (validator) =\u003e validator\n        ..greaterThan(18, message: 'You must be at least 18 years old')\n        ..lowerThan(99, message: 'You must be at most 99 years old'));\n\n  print(value);\n}\n```\n\n### Select component\nA simple example of using Commander to create an option selection component :\n\n- ✅ Placeholder\n- ✅ Default selected\n- ✅ Searchable values\n- ✅ Display transformer\n- ✅ Max display count (default as 5)\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.select('What is your name ?',\n      onDisplay: (value) =\u003e value,\n      placeholder: 'Type to search',\n      defaultValue: 'Charlie',\n      options: ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'John']);\n\n  print(value);\n}\n```\n\n### Swap component\nA simple example of using Commander to create a swap component :\n\n- ✅ Select value with directional arrows\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.swap('Do you love cats', \n    defaultValue: true, \n    placeholder: '🐈'\n  );\n  \n  final str = switch (value) {\n    true =\u003e 'I love cats 😍',\n    false =\u003e 'I prefer dogs 😕',\n  };\n\n  print(str);\n}\n```\n\n### Task component\nA simple example of using Commander to create a task component :\n\n- ✅ Multiple steps per task\n- ✅ Success, warn and error results\n- ✅ Sync and async action supports\n\n```dart\nFuture\u003cvoid\u003e sleep() =\u003e Future.delayed(Duration(seconds: 1));\n\nFuture\u003cString\u003e sleepWithValue() =\u003e\n    Future.delayed(Duration(seconds: 1), () =\u003e 'Hello World !');\n\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final successTask = await commander.task();\n  await successTask.step('Success step 1', callback: sleepWithValue);\n  await successTask.step('Success step 2', callback: sleep);\n  successTask.success('Success task data are available !');\n\n  final warnTask = await commander.task();\n  await warnTask.step('Warn step 1', callback: sleepWithValue);\n  await warnTask.step('Warn step 2', callback: sleep);\n  await warnTask.step('Warn step 3', callback: sleep);\n  warnTask.warn('Warn task !');\n\n  final errorTask = await commander.task();\n  await errorTask.step('Error step 1', callback: sleepWithValue);\n  await errorTask.step('Error step 2', callback: sleep);\n  await errorTask.step('Error step 3', callback: sleep);\n  errorTask.error('Error task !');\n}\n```\n\n### Checkbox component\nA simple example of using Commander to create a checkbox component :\n\n- ✅ Placeholder\n- ✅ Default checked\n- ✅ Single or multiple selection\n- ✅ Display transforme\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.checkbox(\n    'What is your favorite pet ?',\n    defaultValue: 'Charlie',\n    options: ['cat', 'dog', 'bird'],\n  );\n\n  print(value);\n}\n```\n\n### Table component\nA simple example of using Commander to create a table component :\n\n- ✅ Without column and line borders\n- ✅ With column and line borders\n- ✅ With column borders and without line borders\n- ✅ With line borders and without column borders\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n  commander.table(\n    columns: ['Name', 'Age', 'Country', 'City'],\n    lineSeparator: false,\n    columnSeparator: false,\n    data: [\n      ['Alice', '20', 'USA', 'New York'],\n      ['Bob', '25', 'Canada', 'Toronto'],\n      ['Charlie', '30', 'France', 'Paris'],\n      ['David', '35', 'Germany', 'Berlin'],\n      ['Eve', '40', 'Italy', 'Rome'],\n      ['Frank', '45', 'Japan', 'Tokyo'],\n      ['John', '50', 'China', 'Beijing'],\n    ],\n  );\n}\n```\n\n### Alternative screen component\nA simple example of using Commander to create an alternative screen component :\n\n- ✅ Set title\n- ✅ Clear screen on start\n- ✅ Restore screen on stop\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final screen = commander.screen(title: 'First screen');\n  screen.enter();\n\n  await sleep();\n  print('Hello screen !');\n  await sleep();\n\n  screen.leave();\n\n  print('Goodbye screen !');\n}\n\n\nFuture\u003cvoid\u003e wait() =\u003e\n    Future.delayed(Duration(seconds: Random().nextInt(3) + 1));\n```\n\n## Theming\n\nCommander provides a theming system to customize the appearance of the components.\nIt is possible to define a global theme for all components or a specific theme for each component.\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(\n    level: Level.verbose,\n    componentTheme: ComponentTheme(\n      askTheme: DefaultAskTheme.copyWith(askPrefix: '🤖')\n    ));\n\n  final value = await commander.ask('What is your email ?',\n    validate: (validator) =\u003e validator\n      ..notEmpty(message: 'Name cannot be empty :)')\n      ..email(message: 'Please enter a valid email'));\n\n  print(value);\n}\n```\n\nEach component that interacts with the user has a `theme` property that allows the appearance to be customised.\n\n```dart\nFuture\u003cvoid\u003e main() async {\n  final commander = Commander(level: Level.verbose);\n\n  final value = await commander.ask('What is your email ?',\n    theme: DefaultAskTheme.copyWith(askPrefix: '🤖'),\n    validate: (validator) =\u003e validator\n      ..notEmpty(message: 'Name cannot be empty :)')\n      ..email(message: 'Please enter a valid email'));\n\n  print(value);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleadcodedev%2Fcommander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleadcodedev%2Fcommander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleadcodedev%2Fcommander/lists"}