multiline static method
Reads ordinary lines until a line containing only . submits.
A line containing only :cancel cancels the prompt.
Implementation
static String? multiline({
required String title,
int maxLines = 200,
bool allowEmpty = true,
}) {
TerminalContext.output.writeln(
'${terminalSafeLineText(title)} (enter . to submit, :cancel to cancel)',
);
final lines = <String>[];
while (lines.length < maxLines) {
final line = TerminalContext.input.readLineSync();
if (line == null) {
if (lines.any((value) => value.isNotEmpty)) return lines.join('\n');
return allowEmpty ? '' : null;
}
if (line == ':cancel') return null;
if (line == '.') {
if (allowEmpty || lines.any((value) => value.isNotEmpty)) {
return lines.join('\n');
}
_writeError('Input cannot be empty.');
continue;
}
lines.add(line);
}
if (lines.any((value) => value.isNotEmpty)) return lines.join('\n');
return allowEmpty ? '' : null;
}