callout static method

String callout(
  1. String text, {
  2. Tone tone = Tone.info,
  3. String? title,
})

A boxed message with an icon and a coloured border, for notes, warnings and errors that should stand out.

title defaults to the tone's name, like Warning. Long text wraps to fit the screen.

AnsiTheme.say(Widgets.callout(
  'The config file is missing, so defaults are used.',
  tone: Tone.warn,
));

Implementation

static String callout(String text, {Tone tone = Tone.info, String? title}) {
  final theme = AnsiTheme.current;
  final (colour, icon, name) = switch (tone) {
    Tone.info => (theme.info, INFO, 'Note'),
    Tone.success => (theme.success, theme.tick, 'Done'),
    Tone.warn => (theme.warn, WARNING, 'Warning'),
    Tone.error => (theme.error, theme.cross, 'Error'),
  };
  final room = math.max(Terminal.current.columns - 4, 10);

  return box(
    text.wrapWidth(room).join('\n'),
    title: '$icon ${title ?? name}'.foreground(colour),
    colour: colour,
  );
}