Skip to content

Commit

Permalink
Ubuntu xterm supports the 24bit color sequences but JLine uses only 2…
Browse files Browse the repository at this point in the history
…56 color palette, fixes #633
  • Loading branch information
mattirn committed Jan 1, 2021
1 parent ae2ff29 commit 4366205
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2019, the original author or authors.
* Copyright (c) 2002-2021, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -40,6 +40,7 @@
public abstract class AttributedCharSequence implements CharSequence {

public static final int TRUE_COLORS = 0x1000000;
private static final int HIGH_COLORS = 0x7FFF;

public enum ForceMode {
None,
Expand Down Expand Up @@ -174,7 +175,7 @@ public String toAnsi(int colors, ForceMode force, ColorPalette palette, String a
int r = (int)(fg >> (FG_COLOR_EXP + 16)) & 0xFF;
int g = (int)(fg >> (FG_COLOR_EXP + 8)) & 0xFF;
int b = (int)(fg >> FG_COLOR_EXP) & 0xFF;
if (colors == TRUE_COLORS) {
if (colors >= HIGH_COLORS) {
first = attr(sb, "38;2;" + r + ";" + g + ";" + b, first);
} else {
rounded = palette.round(r, g, b);
Expand All @@ -183,7 +184,7 @@ public String toAnsi(int colors, ForceMode force, ColorPalette palette, String a
rounded = palette.round((int)(fg >> FG_COLOR_EXP) & 0xFF);
}
if (rounded >= 0) {
if (colors == TRUE_COLORS && force == ForceMode.ForceTrueColors) {
if (colors >= HIGH_COLORS && force == ForceMode.ForceTrueColors) {
int col = palette.getColor(rounded);
int r = (col >> 16) & 0xFF;
int g = (col >> 8) & 0xFF;
Expand Down Expand Up @@ -213,7 +214,7 @@ public String toAnsi(int colors, ForceMode force, ColorPalette palette, String a
int r = (int)(bg >> (BG_COLOR_EXP + 16)) & 0xFF;
int g = (int)(bg >> (BG_COLOR_EXP + 8)) & 0xFF;
int b = (int)(bg >> BG_COLOR_EXP) & 0xFF;
if (colors == TRUE_COLORS) {
if (colors >= HIGH_COLORS) {
first = attr(sb, "48;2;" + r + ";" + g + ";" + b, first);
} else {
rounded = palette.round(r, g, b);
Expand All @@ -222,7 +223,7 @@ public String toAnsi(int colors, ForceMode force, ColorPalette palette, String a
rounded = palette.round((int)(bg >> BG_COLOR_EXP) & 0xFF);
}
if (rounded >= 0) {
if (colors == TRUE_COLORS && force == ForceMode.ForceTrueColors) {
if (colors >= HIGH_COLORS && force == ForceMode.ForceTrueColors) {
int col = palette.getColor(rounded);
int r = (col >> 16) & 0xFF;
int g = (col >> 8) & 0xFF;
Expand Down

0 comments on commit 4366205

Please sign in to comment.