wrapWith static method

String wrapWith(
  1. String text, {
  2. AnsiColor? background,
  3. AnsiColor? foreground,
  4. AnsiColor? bright,
  5. bool? reverse,
  6. bool? underline,
})

Wraps text with provided styles.

Implementation

static String wrapWith(String text,
    {AnsiColor? background,
    AnsiColor? foreground,
    AnsiColor? bright,
    bool? reverse,
    bool? underline}) {
  var retString = text;
  if (reverse ?? false) {
    // if reverse and background/foreground are specified we should reverse their colors
    if (background != null || foreground != null || bright != null) {
      var tmp = background;
      background = foreground ?? bright;
      foreground = tmp;
    } else {
      retString = _wrapAnsi(retString, _reverseType);
    }
  }
  if (underline ?? false) {
    retString = _wrapAnsi(retString, _underlineType);
  }
  if (foreground != null) {
    retString = _wrapSingle(retString, foreground: foreground);
  }
  if (background != null) {
    retString = _wrapSingle(retString, background: background);
  }
  if (bright != null) {
    retString = _wrapSingle(retString, bright: bright);
  }
  return retString;
}