prompter 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

Prompter #

Advanced and customizable prompt library to build interactive command-line applications.

1.0.0 #

  • readString, readInt, readDouble, readYesOrNo
  • readMultiLineText
  • select, multiSelect

example/main.dart

import 'package:ansicolor/ansicolor.dart';
import 'package:prompter/io.dart';

class Person {
  String username;

  int age;

  double weight;

  Person({this.username, this.age, this.weight});

  @override
  String toString() {
    return {
      "username": username,
      "age": age,
      "weight": weight,
    }.toString();
  }
}

final greenPen = AnsiPen()..green();

final redPen = AnsiPen()..red();

final redBoldPen = AnsiPen()..red(bold: true);

String usernameValidator(String input) {
  if (input.contains(' ')) return 'Cannot contain spaces!';
  return null;
}

String prompt(String label, input, String error) {
  final sb = StringBuffer(' ');

  // Validity
  if (error != null) {
    sb.write(redPen('\u2717'));
  } else {
    sb.write(greenPen('\u2714'));
  }

  sb.write(' ');

  sb.write(label);

  sb.write(': ');

  return sb.toString();
}

String postfix(String label, input, String error) {
  final sb = StringBuffer();

  if (error != null) {
    sb.write(' ');
    sb.write(redBoldPen(error));
  }

  return sb.toString();
}

main(List<String> arguments) async {
  stdinBytes;

  final name = await readString(
      label: "\u{1F464} Username",
      default_: "Teja",
      promptTemplate: prompt,
      validator: usernameValidator,
      suffixTemplate: postfix,
      success: suffixTemplate);
  final age = await readInt(
    label: 'Age',
    promptTemplate: prompt,
    suffixTemplate: postfix,
  );
  final weight = await readDouble(
    label: 'Weight',
    promptTemplate: prompt,
    suffixTemplate: postfix,
  );

  final person = Person(username: name, age: age, weight: weight);

  print(person);
}

Use this package as a library

1. Depend on it

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


dependencies:
  prompter: ^1.0.0

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:prompter/prompter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21

Health issues and suggestions

Document public APIs. (-0.80 points)

150 out of 151 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

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

Analysis of lib/src/prompts/double.dart reported 1 hint:

line 17 col 10: This function has a return type of 'String', but doesn't end with a return statement.

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

Analysis of lib/src/prompts/int.dart reported 1 hint:

line 17 col 10: This function has a return type of 'String', but doesn't end with a return statement.

Fix lib/src/prompts/select/multiple.dart. (-0.50 points)

Analysis of lib/src/prompts/select/multiple.dart reported 1 hint:

line 1 col 8: Unused import: 'package:meta/meta.dart'.

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

Analysis of lib/src/prompts/select/select.dart reported 1 hint:

line 1 col 8: Unused import: 'package:meta/meta.dart'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
meta ^1.1.7 1.1.8
Dev dependencies
ansicolor any
pedantic ^1.0.0
test ^1.0.0