Adapt colors to the terminal
Not every terminal can display the same colors. Color-profile detection lets you choose an appropriate palette and downsample ANSI output instead of showing broken or unreadable styling.
Quick Start
import 'dart:io';
import 'package:ultraviolet/colorprofile.dart' as cp;
void main() {
final profile = cp.detect(
isTty: stdout.hasTerminal,
env: Platform.environment,
isWindows: Platform.isWindows,
);
print('profile: $profile');
final red = cp.sgrColor(
profile: profile,
rgb: const cp.Rgb(255, 0, 0),
);
final text = '${red}Hello\x1B[0m';
print('styled: ${cp.downsampleSgr(text, profile)}');
final ascii = cp.downsampleSgr(text, cp.Profile.ascii);
print('ascii: $ascii');
}
Environment Variables
Detection respects common env vars:
NO_COLORCLICOLOR/CLICOLOR_FORCECOLORTERMTERM
Things to keep in mind
downsampleSgronly processes SGR sequences; other escapes are untouched.Profile.asciistrips color parameters but preserves bold/underline.NO_COLORonly reduces output when stdout is a TTY.
Where to go next
- docs_index.md - Full documentation index
- style.md
- renderer.md