ansicolor는 터미널 출력을 위한 xterm-256 색상 지원을 제공하는 Dart 라이브러리로, 개발자가 콘솔 로그에서 텍스트의 전경 및 배경 색상을 사용자 정의할 수 있게 해줍니다. 다양한 플랫폼에서 Flutter 애플리케이션과 원활하게 통합되어 디버그 시각화와 로그 가독성을 향상시킵니다. 외부 도구에 의존하지 않고도 터미널 출력에 시각적 구분을 추가하고 싶은 개발자에게 이상적인 패키지입니다. 간단한 문법으로 터미널 내에서 다양한 색상과 포맷팅 옵션을 직접 지원합니다.
사용 사례
터미널 디버그 출력 개선
색상 코드화된 로그 메시지
CLI 도구의 가독성 향상
콘솔 앱에서 시각적 피드백 추가
명령줄 인터페이스 외관 맞춤 설정
주요 기능
xterm-256 색상 지원
사용하기 쉬운 색상 서식
크로스 플랫폼 터미널 지원
전경/배경 색상에 대한 간단한 API
가볍고 종속성 없음
적합한 대상
CLI 도구를 개발하는 개발자
콘솔 로깅이 있는 플러터 앱
시각적 신호가 필요한 디버깅 환경
팀이 로그 명확성 향상 중
교육 또는 튜토리얼 프로젝트
고려 사항
터미널 출력만 제한
UI 렌더링에 적합하지 않습니다
ANSI 색상을 지원하는 터미널이 필요합니다
모든 터미널에서 일관되게 렌더링되지 않을 수 있습니다
코드 외에 런타임 색상 사용자 정의 없음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
ANSI / Xterm 256 color library for Dart
Feel like you're missing some color in your terminal programs? Use AnsiPen to add ANSI color codes to your log messages.
Easy to disable for production, just set color_disabled = true and all codes will be empty - no re-writing debug messages.
Note: color_disabled is a global variable for all pen colors.
Example
Note: Be mindful of contrasting colors. If you set "bright white" foreground and don't adjust the background, you'll have a bad time with lighter terminals.
Foreground to bright white with default background:
AnsiPen pen = AnsiPen()..white(bold: true);
print(pen("Bright white foreground") + " this text is default fg/bg");
Background as a peach, foreground as white:
AnsiPen pen = AnsiPen()..white()..rgb(r: 1.0, g: 0.8, b: 0.2, bg: true);
print(pen("White foreground with a peach background"));
Note
If color isn't working for you; try setting ansiColorDisabled = false;. We're relying on the stdio object to inform us of ANSI terminal support. Sometimes this is wrong.
Prior versions of this library just turned on color by default.
Rainbow Demo
If you want a specific color, you can call the xterm() with the index listed in the rainbow below. To show the rainbow on your own terminal, pub run examples/ansicolor.dart