GhosttyTerminalResolvedStyle.fromNativeStyleWithRenderColors constructor
- required VtStyle style,
- required VtRenderColors colors,
Resolves a native VtStyle using shared VtRenderColors palette data.
This keeps Flutter's native render path aligned with the VT package's palette and default-color resolution rules instead of re-implementing them locally.
Implementation
factory GhosttyTerminalResolvedStyle.fromNativeStyleWithRenderColors({
required VtStyle style,
required VtRenderColors colors,
}) {
Color toColor(VtRgbColor color) =>
Color.fromARGB(0xFF, color.r, color.g, color.b);
final hasExplicitForeground = style.foreground.isSet;
final hasExplicitBackground = style.background.isSet;
final hasExplicitUnderlineColor = style.underlineColor.isSet;
const transparent = Color(0x00000000);
var foreground = hasExplicitForeground
? toColor(colors.resolveForeground(style)!)
: transparent;
var background = hasExplicitBackground
? toColor(colors.resolveBackground(style)!)
: transparent;
if (style.inverse) {
final swappedForeground = background;
background = hasExplicitForeground
? foreground
: (foreground == transparent
? toColor(colors.foreground)
: foreground);
foreground = hasExplicitBackground
? swappedForeground
: (swappedForeground == transparent
? toColor(colors.background)
: swappedForeground);
}
if (style.invisible) {
foreground = background == transparent
? toColor(colors.background)
: background;
}
if (style.faint) {
foreground = foreground.withValues(alpha: 0.72);
}
if (foreground == transparent) {
foreground = toColor(colors.foreground);
}
return GhosttyTerminalResolvedStyle(
foreground: foreground,
background: background,
underlineColor: hasExplicitUnderlineColor
? toColor(colors.resolveUnderlineColor(style)!)
: transparent,
foregroundToken: _toTerminalColor(style.foreground),
backgroundToken: _toTerminalColor(style.background),
underlineColorToken: _toTerminalColor(style.underlineColor),
hasExplicitUnderlineColor: hasExplicitUnderlineColor,
hasExplicitForeground: hasExplicitForeground,
hasExplicitBackground: hasExplicitBackground,
inverse: style.inverse,
invisible: style.invisible,
faint: style.faint,
blink: style.blink,
bold: style.bold,
italic: style.italic,
overline: style.overline,
strikethrough: style.strikethrough,
underline: style.underline,
);
}