codeErrorFragment function
Implementation
String codeErrorFragment(String input, int linePos, int columnPos,
[Settings? settings]) {
final splitter = new RegExp(r"\r\n?|\n|\f");
final lines = input.split(splitter);
settings = settings != null ? settings : new Settings();
final startLinePos = max(1, linePos - settings.extraLines) - 1;
final endLinePos = min(linePos + settings.extraLines, lines.length);
final maxNumLength = endLinePos.toString().length;
final prevLines =
printLines(lines, startLinePos, linePos, maxNumLength, settings);
final targetLineBeforeCursor = printLine(
lines[linePos - 1].substring(0, columnPos - 1),
linePos,
maxNumLength,
settings);
final cursorLine = repeatString(' ', targetLineBeforeCursor.length) + '^';
final nextLines =
printLines(lines, linePos, endLinePos, maxNumLength, settings);
return [prevLines, cursorLine, nextLines]
.where((c) => c != null && c != 0)
.join('\n');
}