updateThemeFromBackground function
Updates theme based on background hex color (e.g., '#1a1a1a').
Automatically determines if the background is dark based on luminance.
Implementation
void updateThemeFromBackground(String? hex) {
if (hex == null || hex.isEmpty) return;
final h = hex.startsWith('#') ? hex.substring(1) : hex;
if (h.length != 6) return;
final r = int.tryParse(h.substring(0, 2), radix: 16);
final g = int.tryParse(h.substring(2, 4), radix: 16);
final b = int.tryParse(h.substring(4, 6), radix: 16);
if (r == null || g == null || b == null) return;
// Perceived luminance; threshold tuned for terminals
final lum = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255.0;
_hasDarkBackground = lum < 0.5;
}