easy_tui 1.0.2 easy_tui: ^1.0.2 copied to clipboard
Very simple tool to generate menus for gathering user input.
import 'dart:io';
import 'package:easy_tui/cli/io/out/TerminalOut.dart';
import 'package:easy_tui/tui/TextFormUI.dart';
import 'package:easy_tui/tui/TextOptionUI.dart';
import 'package:easy_tui/tui/MenuModifiers.dart';
void main() {
// Create the UI class
final TextOptionUI main = new TextOptionUI(
/// The [modifier] parameter is a list of modifiers
/// In this case, `MenuModifiers.MAIN_MENU` is the modifier.
modifiers: [MenuModifiers.MAIN_MENU]);
/// Add content to a `TextUI` through the [lines] property
main.lines.addAll([
/* 1 */ "Say hello",
/* 2 */ "Go to a submenu",
/* 3 */ "Enter some data",
/* 4 */ "Exit"
]);
/// `TextUI`s with the `MenuModifiers.MAIN_MENU` property __should loop__
while (true) {
/// `switch` statements are a good way to handle [present]'s return value
switch (main.present()) {
case 1:
print("\nHello, user!\n");
break;
case 2:
TerminalOut.enterToContinue("I didn't feel like demoing this, " +
"but you can put as many menus into menus as your feel like.");
break;
case 3:
TextFormUI dataEntry = new TextFormUI();
dataEntry.lines.addAll(["name?", "age?", "date of birth?"]);
/// [present()] has an __optional named parameter__
/// that prepends the questions with the `String` provided.
///
/// So, the questions would be "_What is your_ name?",
/// "_What is your_ age?", and "_What is your_ date of birth"?
List<String> answers = dataEntry.present(prepend: "What is your ");
print("\nYour name is: ${answers[0]}, " +
"\nYour age is: ${answers[1]}, " +
"\nYour DOB is: ${answers[2]}");
break;
case 4:
exit(0);
break;
}
TerminalOut.enterToClear("Returning to main menu...");
}
}