prompts 1.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

prompts #

Pub

Rich, simple, synchronous command-line prompt library for Dart.

Now with pretty colors!

GIF Demo

Example #

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;
}

1.3.1 #

1.3.0 #

  • Make choose only print options once, and instead add prompt.
  • Add names to choose.
  • conceal was true in chooseShorthand; revert to false.
  • Always use AnsiCode.wrap, to prevent "hanging colors."
  • Always heed the color flag.
  • Use VT100 codes for clearing lines, etc. (smoother, no jank)

1.2.0 #

  • Add password reading options.
  • Pin against Dart 2.

1.1.0 #

  • Add pretty colors to get.

1.0.0 #

Initial version

example/main.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!');

  var password = prompts.get('Enter a password', conceal: true);
  print('TOP-SECRET: $password');

  // ... 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}');

  // Displays an interactive selection in the terminal.
  //
  // If you pass `interactive: false`, then the standard chooser prints
  // to multiple lines, but is often
  // clearer to read, and has more obvious semantics.
  //
  // You can also optionaly pass short `names`.
  color = prompts.choose('Choose another color', rgb,
      defaultsTo: Color.blue, names: ['r', 'g', 'b']);
  print(color.about);
}

class Color {
  final String name, description;

  const Color(this.name, this.description);

  static const Color red = Color('Red', 'The color of apples.'),
      blue = Color('Blue', 'The color of the sky.'),
      green = Color('Green', 'The color of leaves.');

  String get about => '$name - $description';

  @override
  String toString() => name;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  prompts: ^1.3.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:prompts/prompts.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:prompts/prompts.dart with components: io.

Health suggestions

Fix lib/prompts.dart. (-0.50 points)

Analysis of lib/prompts.dart reported 1 hint:

line 191 col 5: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
charcode ^1.0.0 1.1.2
io ^0.3.2 0.3.3
Transitive dependencies
meta 1.1.8
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
Dev dependencies
pedantic ^1.0.0