Package org.aesh.terminal.tty.utils
Class ColorUtils
java.lang.Object
org.aesh.terminal.tty.utils.ColorUtils
Utility methods for color conversion and tmux color detection.
- Author:
- Ståle W. Pedersen
-
Method Summary
Modifier and TypeMethodDescriptionstatic int[][]Try to detect terminal colors by querying tmux options.static booleanisDarkColor(int[] rgb) Determine if an RGB color is dark based on perceived luminance.static int[]namedColorToRGB(String name) Convert a named color to RGB.static int[]palette256ToRGB(int index) Convert a 256-color palette index to RGB.static int[]parseTmuxColor(String color) Parse a tmux color value.static int[][]parseTmuxStyle(String style) Parse a tmux style string like "bg=colour235,fg=colour252" or "bg=#282828".
-
Method Details
-
isDarkColor
public static boolean isDarkColor(int[] rgb) Determine if an RGB color is dark based on perceived luminance.Uses ITU-R BT.601 coefficients: 0.299*R + 0.587*G + 0.114*B
- Parameters:
rgb- the RGB color array [r, g, b] (0-255 each)- Returns:
- true if the color is dark, false if light
-
palette256ToRGB
public static int[] palette256ToRGB(int index) Convert a 256-color palette index to RGB.- Parameters:
index- the palette index (0-255)- Returns:
- RGB array [r, g, b], or null if index is out of range
-
namedColorToRGB
Convert a named color to RGB.- Parameters:
name- the color name (e.g., "black", "red", "green")- Returns:
- RGB array [r, g, b], or null if name is not recognized
-
parseTmuxColor
Parse a tmux color value.- Parameters:
color- the color string (e.g., "#282828", "colour235", "black")- Returns:
- RGB array or null
-
parseTmuxStyle
Parse a tmux style string like "bg=colour235,fg=colour252" or "bg=#282828".- Parameters:
style- the tmux style string- Returns:
- array of two RGB arrays: [foreground, background], either may be null
-
detectColorsFromTmux
public static int[][] detectColorsFromTmux()Try to detect terminal colors by querying tmux options.Only works when running inside tmux. Queries the window-active-style option.
- Returns:
- array of two RGB arrays: [foreground, background], either may be null
-