Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hexadecimal triple support in Jansi #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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