terminalSafeLineText function
Makes untrusted text safe for one line of plain terminal output.
After terminal controls are escaped, whitespace (including newlines and tabs) is collapsed to one ASCII space and surrounding whitespace is removed.
Implementation
String terminalSafeLineText(String value) {
final withoutStructuralWhitespace =
value.replaceAll('\n', ' ').replaceAll('\t', ' ');
return terminalSafeBlockText(withoutStructuralWhitespace)
.replaceAll(RegExp(r'\s+'), ' ')
.trim();
}