textToAnsi function

String textToAnsi(
  1. dynamic text, {
  2. LogStyle style = const LogStyle(),
  3. bool enableAnsi = true,
})

Implementation

String textToAnsi(text,
    {LogStyle style = const LogStyle(), bool enableAnsi = true}) {
  if (!enableAnsi) {
    return text;
  }
  final fg = style.textColor == null ? '' : ';${style.textColor}';
  final bg = style.backgroundColor == null ? '' : ';${style.backgroundColor}';
  return '\x1B[${style.attr.index}$fg${bg}m$text\x1B[0m';
}