writeHelpModern method
The writeHelpModern method is used to write the help of the application in a modern way.
The myControllers is a list of controllers that you want to show in the
help. If it is null it will show all controllers.
you can call this method from the controller to write the help of the application in a modern way.
This method uses ANSI escape codes to color the output and make it more readable.
Implementation
CappConsole writeHelpModern([List<CappController>? myControllers]) {
var selectedControllers = myControllers ?? [...controllers, main];
var maxNameLen = 0;
for (var controller in selectedControllers) {
for (var option in controller.options) {
if (option.name.length > maxNameLen) {
maxNameLen = option.name.length;
}
}
}
for (var controller in selectedControllers) {
if (controller.name.isNotEmpty) {
cprint("\x1B[1m✔ ${controller.name}\x1B[22m", CappColors.success);
if (controller.description.isNotEmpty) {
cprint("\t${controller.description}", CappColors.warning);
}
} else {
cprint(controller.description, CappColors.info);
}
for (var option in controller.options) {
var nameCol = '--${option.name}'.padRight(maxNameLen + 2);
cprint("\t-${option.shortName}, $nameCol ${option.description}");
}
}
return CappConsole('');
}