Skip to content

Commit

Permalink
Add tripleto hexadecimal color support (#1082)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel <[email protected]>
  • Loading branch information
gnodet and gabriel4ndr4d3 authored Sep 30, 2024
1 parent 8aa618e commit f79eeb2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions jansi-core/src/main/java/org/jline/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public int value() {
/**
* ED (Erase in Display) / EL (Erase in Line) parameter (see
* <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences">CSI sequence J and K</a>)
*
* @see Ansi#eraseScreen(Erase)
* @see Ansi#eraseLine(Erase)
*/
Expand Down Expand Up @@ -389,6 +390,15 @@ public Ansi fg(int color) {
return this;
}

public Ansi fgRgb(String hex) {

if (hex.startsWith("#")) {
hex = hex.substring(1);
}

return fgRgb(Integer.parseInt(hex, 16));
}

public Ansi fgRgb(int color) {
return fgRgb(color >> 16, color >> 8, color);
}
Expand Down Expand Up @@ -446,6 +456,15 @@ public Ansi bg(int color) {
return this;
}

public Ansi bgRgb(String hex) {

if (hex.startsWith("#")) {
hex = hex.substring(1);
}

return bgRgb(Integer.parseInt(hex, 16));
}

public Ansi bgRgb(int color) {
return bgRgb(color >> 16, color >> 8, color);
}
Expand Down

0 comments on commit f79eeb2

Please sign in to comment.