withAlignment method
Change the alignment style of this string with provided alignment modifiers, just use ConsoleTextAlignment
Implementation
String withAlignment(ConsoleTextAlignment alignment) {
final terminalWidth = _getSafeTerminalColumns();
final visibleLen = _getVisibleLength(this);
switch (alignment) {
case ConsoleTextAlignment.left:
return this;
case ConsoleTextAlignment.center:
final padCount =
((terminalWidth - visibleLen) ~/ 2).clamp(0, terminalWidth);
return (' ' * padCount) + this;
case ConsoleTextAlignment.right:
final padCount = (terminalWidth - visibleLen).clamp(0, terminalWidth);
return (' ' * padCount) + this;
}
}