Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thosakwe/prompts
Rich, simple, synchronous command-line prompt library for Dart.
https://github.com/thosakwe/prompts
dart prompt terminal
Last synced: 8 days ago
JSON representation
Rich, simple, synchronous command-line prompt library for Dart.
- Host: GitHub
- URL: https://github.com/thosakwe/prompts
- Owner: thosakwe
- License: mit
- Created: 2018-05-25T09:22:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-31T06:36:34.000Z (almost 2 years ago)
- Last Synced: 2024-10-22T09:50:04.146Z (17 days ago)
- Topics: dart, prompt, terminal
- Language: Dart
- Homepage: https://pub.dartlang.org/packages/prompts
- Size: 5.35 MB
- Stars: 37
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# prompts
[![Pub](https://img.shields.io/pub/v/prompts.svg?c=b)](https://pub.dartlang.org/packages/prompts)Rich, simple, synchronous command-line prompt library for Dart.
**Now with pretty colors!**
![GIF Demo](usage.gif)
# Example
```dart
import 'package:io/ansi.dart';
import 'package:prompts/prompts.dart' as prompts;void main() {
// Easily get a single line.
var name = prompts.get('Enter your name');
print('Hello, $name!');// ... Or many lines.
print('Tell me about yourself.');
var bio = prompts.get(
"Enter some lines, using '\\' to escape line breaks",
allowMultiline: true,
inputColor: resetAll,
);
print('About $name:\n$bio');// Supports default values.
name = prompts.get('Enter your REAL name', defaultsTo: name);
print('Hello, $name!');// "High-level" prompts are built upon [get].
// For example, we can prompt for confirmation trivially.
bool shouldDownload = prompts.getBool('Really download this package?');if (!shouldDownload)
print('Not downloading.');
else
print('Downloading...!');// Or, get an integer, WITH validation.
int age = prompts.getInt('How old are you?', defaultsTo: 23, chevron: false);
print('$name, you\'re $age? Cool!');// We can choose from various values.
// There are two methods - shorthand and regular.
var rgb = [Color.red, Color.green, Color.blue];
Color color = prompts.chooseShorthand('Tell me your favorite color', rgb);
print('You chose: ${color.about}');// The standard chooser prints to multiple lines, but is often
// clearer to read, and has more obvious semantics.
color = prompts.choose('Choose another color', rgb, defaultsTo: Color.blue);
print(color.about);
}class Color {
final String name, description;const Color(this.name, this.description);
static const Color red = const Color('Red', 'The color of apples.'),
blue = const Color('Blue', 'The color of the sky.'),
green = const Color('Green', 'The color of leaves.');String get about => '$name - $description';
@override
String toString() => name;
}
```