easy_print 0.4.0 copy "easy_print: ^0.4.0" to clipboard
easy_print: ^0.4.0 copied to clipboard

Just use print in your project without worrying about the console nor the context.

example/easy_print_example.dart

import 'dart:io';
import 'package:easy_print/easy_print.dart';

void main() async {
  final ep = EasyPrint(stdout.writeln);
  Future<void> zone2() async {
    print('Con esta adición así van a ser los logs');
    ep.wrapInPrintZone(
      () {
        print('Anidados uno adentro del otro (para poder meter contexto)');
        ep.wrapInPrintZone(
          () {
            print('Y quedando como un semáforo 🤡');
            try {
              throw Exception('Las excepciones catcheadas no debieras verlas.');
            } catch (e) {
              throw StateError(
                'Pero igual te tiro un error para que veas como se ve',
              );
            }
          },
          PrintZone3(zoneName: 'PrintZone3'),
        );
      },
      PrintZone2(zoneName: 'PrintZone2'),
    );
  }

  void zone1() {
    ep.wrapInPrintZone(
      zone2,
      PrintZone1(zoneName: 'PrintZone1'),
    );
  }

  ep.setUp(
    () async {
      print('print sin PrintZones');
      print('asi se imprime actualmente');
      print('sin dar mucho detalle');
      print('y dificultando la lectura');
      zone1();
    },
  );
}

sealed class TestPrintZone extends PrintZone {
  TestPrintZone({required super.zoneName, super.penColor});
}

final class PrintZone1 extends TestPrintZone {
  PrintZone1({required super.zoneName}) : super(penColor: _penColor);

  static AnsiPen _penColor({required bool isBold}) =>
      AnsiPen()..green(bold: isBold);

  @override
  LogLevel get logLevel => LogLevel.debug;
}

final class PrintZone2 extends TestPrintZone {
  PrintZone2({required super.zoneName}) : super(penColor: _penColor);

  static AnsiPen _penColor({required bool isBold}) =>
      AnsiPen()..yellow(bold: isBold);

  @override
  LogLevel get logLevel => LogLevel.debug;
}

final class PrintZone3 extends TestPrintZone {
  PrintZone3({required super.zoneName}) : super(penColor: _penColor);

  static AnsiPen _penColor({required bool isBold}) =>
      AnsiPen()..red(bold: isBold);

  @override
  LogLevel get logLevel => LogLevel.debug;
}
1
likes
130
points
112
downloads

Publisher

unverified uploader

Weekly Downloads

Just use print in your project without worrying about the console nor the context.

Documentation

API reference

License

MIT (license)

Dependencies

ansi_strip, meta, talker

More

Packages that depend on easy_print