搜索插件、代码仓与 APP 分类

ansicolor 封面
插件详情v2.0.3

ansicolor

想为你的终端日志增添一些色彩吗?`ansicolor` 是一个支持 xterm-256 颜色的库,可让你更改文本的前景色和背景色。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
327万
喜欢数
171
Pub 分数
160

安装插件

flutter pub add ansicolor

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

ansicolor 是一个 Dart 库,为终端输出提供 xterm-256 颜色支持,使开发者能够自定义控制台日志中的文本前景色和背景色。它可无缝集成到跨平台的 Flutter 应用中,提升调试可见性和日志可读性。该包非常适合希望在不依赖外部工具的情况下为终端输出添加视觉区分的开发者。通过简洁的语法,它直接在终端中支持广泛的颜色和格式选项。

适合场景

  • 增强终端调试输出
  • 颜色编码日志消息
  • 提高 CLI 工具的可读性
  • 在控制台应用程序中添加视觉反馈
  • 自定义命令行界面外观

主要特点

  • 支持 xterm-256 颜色
  • 易于使用的颜色格式化
  • 跨平台终端支持
  • 前景/背景颜色的简单API
  • 轻量且无依赖

适合对象

  • 开发 CLI 工具的开发者
  • 带有控制台日志记录的 Flutter 应用
  • 需要视觉提示的调试环境
  • 团队改进日志清晰度
  • 教育或教程项目

使用建议

  • 仅限终端输出
  • 不适用于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

alt tag

所属分类

源码仓库

使用此插件的项目

所在榜单