dart_inquirer 1.0.0  dart_inquirer: ^1.0.0 copied to clipboard
dart_inquirer: ^1.0.0 copied to clipboard
This library makes developing interacive Prompts in Dart easy and fun
Dart Inquirer #
This library makes developing interacive Prompts in Dart easy π and pretty π
!WARNING! : This project is still under development, tips and tricks are always appreaciated
Usage #
A simple usage example:
import 'package:dart_inquirer/dart_inquirer.dart';
main() {
  List questions = [
    InputQuestion('name', 'Whats your beautiful name ?')
  ];
  Prompt prompt = Prompt(questions);
  prompt.execute().then((Map answers) => print('π Hello ${(answers["name"] as String).isNotEmpty ? answers["name"] : 'World'} π'));
}
Prompt types #
Dart Inquirer is my first Project so I didn't implement a lot of Question Types, but the most important ones
InputQuestion #
The InputQuestion can handle simple Inputs and returns a String
import 'package:dart_inquirer/dart_inquirer.dart';
main() async {
  List<Question> questions = [
    InputQuestion('name', 'Whats your beautiful name ?')
  ];
  Prompt prompt = Prompt(questions);
  var name = (await prompt.execute())["name"];
  print("β Hello $name π");
}
ConfirmQuestion #
Every project needs some kind of user confirmation, so for that reason we have the ConfirmQuestion
import 'package:dart_inquirer/dart_inquirer.dart';
main() {
  List<Question> questions = [
    ConfirmQuestion('alien', 'Are you a citizen of Earth ?')
  ];
  Prompt prompt = Prompt(questions);
  if (!(await prompt.execute())["alien"]){
    print("π½π Please don't experiment with us πΎπ");
  }else {
    print("π Earthlings are always welcome π");
  }
}
Also you can change either if the Y or N is preffered
import 'package:dart_inquirer/dart_inquirer.dart';
main() async{
  List<Question> questions = [
    // β¬β¬β¬ CHANGED THIS LINE β¬β¬β¬
    ConfirmQuestion('alien', 'Are you a citizen of Earth ?', preferN: true)
  //ConfirmQuestion('alien', 'Are you a citizen of Earth ?') β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬
  ];
  Prompt prompt = Prompt(questions);
  if (!(await prompt.execute())["alien"]){
    print("π½π Please don't experiment with us πΎπ");
  }else {
    print("π Earthlings are always welcome π");
  }
}
PasswordQuestion #
Sometimes your users will need to specify some super secret thing π so for that purpose we have the password question. It will protect others from just seeing the Input
!Warning! : This is not very secure
import 'package:dart_inquirer/dart_inquirer.dart';
main() async {
  List<Question> questions = [
    PasswordQuestion('secret', 'Whats your biggest fear ?')
  ];
  Prompt prompt = Prompt(questions);
  String fear = (await prompt.execute())["secret"];
  print("π» Man this ${'*'*fear.length} is very scary β ");
}
ListQuestion #
If you want your users to select an option you can do that by simply using a ListQuestion
import 'package:dart_inquirer/dart_inquirer.dart';
main() async {
  List<Question> questions = [
    ListQuestion('hate', 'What do you like least on your Pizza', ['Pineapple', 'Ham', 'Tomatoes'])
  ];
  Prompt prompt = Prompt(questions);
  String hate = (await prompt.execute())["hate"];
  print("π I wouldn't eat $hate as well π°");
}
Helpers #
I have implemented some helpers
Pretty json formatting #
import 'package:dart_inquirer/dart_inquirer.dart';
main() async {
  List<Question> questions = [
    ListQuestion('first', 'Select a letter', ['A', 'B', 'C']),
    ConfirmQuestion('second', 'Is this the letter you want ?')
  ];
  Map answers = {};
  Prompt prompt = Prompt(questions);
  while (answers["second"] != true) {
    answers = await prompt.execute();
  }
  prettyPrintJson(answers);
}
[1] A
[2] B
[3] C
[β] Select a letter : 2
[β] Is this the letter you want ?  (Y/n) y
{
	first : B
	second : true
}
Skipping Questions #
You can skip a question if you don't want to let it execute, just specify a conditional function
import 'package:dart_inquirer/dart_inquirer.dart';
main() async{
  List<Question> questions = [
    ConfirmQuestion('confirm', 'Do you want to type your name ?'),
    InputQuestion('name', 'Username:', skipIf: (Map ctx) => ctx["confirm"] == false)
  ];
  Map answers = await Prompt(questions).execute();
  print("πΈ Hello ${(answers["name"] as String).isNotEmpty ? answers["name"] : 'World'} π");
}
Sepperator #
Maybe you want to put down a nice Sepperator ... then this here is for you
import 'package:dart_inquirer/dart_inquirer.dart';
main() {
  print(Seperator());
  print(Seperator('='));
}
Features and bugs #
Please file feature requests and bugs at the issue tracker.