messageMultiple method

String messageMultiple (
  1. String message,
  2. String label,
  3. Map<SourceSpan, String> secondarySpans,
  4. {bool color: false,
  5. String primaryColor,
  6. String secondaryColor}
)

Like SourceSpan.message, but also highlights secondarySpans to provide the user with additional context.

Each span takes a label (label for this span, and the values of the secondarySpans map for the secondary spans) that's used to indicate to the user what that particular span represents.

If color is true, ANSI terminal color escapes are used to color the resulting string. By default this span is colored red and the secondary spans are colored blue, but that can be customized by passing ANSI escape strings to primaryColor or secondaryColor.

Each span in secondarySpans must refer to the same document as this span. Throws an ArgumentError if any secondary span has a different source URL than this span.

Note that while this will work with plain SourceSpans, it will produce much more useful output with SourceSpanWithContexts (including FileSpans).

Implementation

String messageMultiple(
    String message, String label, Map<SourceSpan, String> secondarySpans,
    {bool color = false, String primaryColor, String secondaryColor}) {
  final buffer = StringBuffer()
    ..write('line ${start.line + 1}, column ${start.column + 1}');
  if (sourceUrl != null) buffer.write(' of ${p.prettyUri(sourceUrl)}');
  buffer
    ..writeln(': $message')
    ..write(highlightMultiple(label, secondarySpans,
        color: color,
        primaryColor: primaryColor,
        secondaryColor: secondaryColor));
  return buffer.toString();
}