搜尋套件、儲存庫與 APP 分類

colorize 封面
套件詳情v3.0.0

colorize

為控制台輸出著色

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
19萬
喜歡數
29
Pub 分數
90

安裝套件

flutter pub add colorize

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Colorize 是一個 Flutter/Dart 套件,讓開發者能在命令列應用程式中為終端輸出加入色彩與樣式。它提供簡單的 API,可直接在終端機中印出各種顏色、背景與樣式(例如粗體或底線)的文字。非常適合用於除錯、記錄日誌或提升 CLI 工具的可讀性,支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。此套件輕量且能與 Dart 的標準輸出無縫整合。

適用情境

  • 除錯 CLI 應用程式
  • 增強日誌訊息
  • 建立互動式命令列工具
  • 提高終端輸出的可讀性
  • 開發面向開發者的腳本

主要特色

  • 支援 ANSI 顏色代碼
  • 簡單直覺的 API
  • 跨平台相容性
  • 可自定義的文字樣式
  • 與 stdout 和 stderr 相容

適合對象

  • CLI 工具開發者
  • 使用主控台應用程式的 Dart 開發人員
  • 團隊提升除錯輸出可見性
  • 涉及終端互動的教育專案

使用建議

  • 不適用於UI渲染
  • 顏色輸出可能因終端模擬器而異
  • 僅限主控台環境
  • 不支援非 ANSI 終端
  • 在某些情況下需要手動處理轉義序列

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Colorize

Colorize console output in dart console apps!

Install

Add dependency to your pubspec.yaml:

colorize: any

Run

pub get

Usage

Import package:

import 'package:colorize/colorize.dart';

You have two way to colorize your string:

  • use class Colorize
  • use top-level function color()
Use Colorize

For colorize string with Colorize class you should create object of type Colorize:

Colorize string = new Colorize("This is my string!");

Then you can call methods of Colorize.

Text color

  • default()
  • black()
  • red()
  • green()
  • yellow()
  • blue()
  • magenta()
  • cyan()
  • lightGray()
  • darkGray()
  • lightRed()
  • lightGreen()
  • lightYellow()
  • lightBlue()
  • lightMagenta()
  • lightCyan()
  • white()

Background color

  • bgDefault()
  • bgBlack()
  • bgRed()
  • bgGreen()
  • bgYellow()
  • bgBlue()
  • bgMagenta()
  • bgCyan()
  • bgLightGray()
  • bgDarkGray()
  • bgLightRed()
  • bgLightGreen()
  • bgLightYellow()
  • bgLightBlue()
  • bgLightMagenta()
  • bgLightCyan()
  • bgWhite()

Formatting

  • reset()
  • bold()
  • dark()
  • italic()
  • underline()
  • blink()
  • reverse()
  • concealed()

After apply styles to string you can print it to console:

print(string);
Use top-level function color()

Top-level function color apply one required parameter - String text. It is text, that would be print on console.

Also top-level function color has seven named parameters:

  • Styles front - name of front color (you can also use the constants of class Styles). Default value is ''.
  • Styles back: name of background color (you can also use the constants of class Styles). Default value is ''.
  • bool isUnderline - default value is false.
  • bool isBold - default value is false.
  • bool isDark - default value is false.
  • bool isItalic - default value is false.
  • bool isReverse - default value is false.

Example of usage

color("Bold Italic Underline", front: Styles.RED, isBold: true, isItalic: true, isUnderline: true);
Enum Styles

Enum Styles contains all styles which you can pass to Colorize.applyState method;

所屬分類

原始碼儲存庫

使用此套件的專案