Skip to content

Commit

Permalink
Move 256 color names inside a file
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 29, 2018
1 parent 18c1acc commit eaea6f9
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 1 deletion.
2 changes: 2 additions & 0 deletions style/src/main/java/org/jline/style/StyleColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
* Style colors.
*
* @since 3.4
* @deprecated use {@link org.jline.utils.Colors#rgbColor(String)}
*/
@Deprecated
public enum StyleColor {
black(0), // #000000
maroon(1), // #800000
Expand Down
8 changes: 7 additions & 1 deletion style/src/test/java/org/jline/style/StyleResolverTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.jline.style

import org.jline.utils.Colors
import org.junit.Before
import org.junit.Test

Expand Down Expand Up @@ -121,7 +122,7 @@ class StyleResolverTest
@Test
void 'resolve fg:~olive'() {
def style = underTest.resolve('fg:~olive')
assert style == DEFAULT.foreground(StyleColor.olive.code)
assert style == DEFAULT.foreground(Colors.rgbColor("olive"))
}

@Test
Expand All @@ -135,4 +136,9 @@ class StyleResolverTest
def style = underTest.resolve('fg:~foo')
assert style == DEFAULT
}

@Test
void 'check color ordinal'() {
assert 86 == Colors.rgbColor("aquamarine1")
}
}
28 changes: 28 additions & 0 deletions terminal/src/main/java/org/jline/utils/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/
package org.jline.utils;

import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;

public class Colors {
Expand Down Expand Up @@ -73,6 +80,8 @@ public class Colors {

private static int[] COLORS_256 = DEFAULT_COLORS_256;

private static Map<String, Integer> COLOR_NAMES;

public static void setRgbColors(int[] colors) {
if (colors == null || colors.length != 256) {
throw new IllegalArgumentException();
Expand All @@ -84,6 +93,25 @@ public static int rgbColor(int col) {
return COLORS_256[col];
}

public static Integer rgbColor(String name) {
if (COLOR_NAMES == null) {
Map<String, Integer> colors = new LinkedHashMap<>();
try (InputStream is = InfoCmp.class.getResourceAsStream("colors.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
br.lines().map(String::trim)
.filter(s -> !s.startsWith("#"))
.filter(s -> !s.isEmpty())
.forEachOrdered(s -> {
colors.put(s, colors.size());
});
COLOR_NAMES = colors;
} catch (IOException e) {
throw new IOError(e);
}
}
return COLOR_NAMES.get(name);
}

public static int roundColor(int col, int max) {
return roundColor(col, max, null);
}
Expand Down
265 changes: 265 additions & 0 deletions terminal/src/main/resources/org/jline/utils/colors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
#
# Copyright (c) 2002-2018, 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.
#
# http://www.opensource.org/licenses/bsd-license.php
#

black
maroon
green
olive
navy
purple
teal
silver
grey
red
lime
yellow
blue
fuchsia
aqua
white
grey0
navyblue
darkblue
blue3
blue3a
blue1
darkgreen
deepskyblue4
deepskyblue4a
deepskyblue4b
dodgerblue3
dodgerblue2
green4
springgreen4
turquoise4
deepskyblue3
deepskyblue3a
dodgerblue1
green3
springgreen3
darkcyan
lightseagreen
deepskyblue2
deepskyblue1
green3a
springgreen3a
springgreen2
cyan3
darkturquoise
turquoise2
green1
springgreen2a
springgreen1
mediumspringgreen
cyan2
cyan1
darkred
deeppink4
purple4
purple4a
purple3
blueviolet
orange4
grey37
mediumpurple4
slateblue3
slateblue3a
royalblue1
chartreuse4
darkseagreen4
paleturquoise4
steelblue
steelblue3
cornflowerblue
chartreuse3
darkseagreen4a
cadetblue
cadetbluea
skyblue3
steelblue1
chartreuse3a
palegreen3
seagreen3
aquamarine3
mediumturquoise
steelblue1a
chartreuse2
seagreen2
seagreen1
seagreen1a
aquamarine1
darkslategray2
darkreda
deeppink4a
darkmagenta
darkmagentaa
darkviolet
purplea
orange4a
lightpink4
plum4
mediumpurple3
mediumpurple3a
slateblue1
yellow4
wheat4
grey53
lightslategrey
mediumpurple
lightslateblue
yellow4a
darkolivegreen3
darkseagreen
lightskyblue3
lightskyblue3a
skyblue2
chartreuse2a
darkolivegreen3a
palegreen3a
darkseagreen3
darkslategray3
skyblue1
chartreuse1
lightgreen
lightgreena
palegreen1
aquamarine1a
darkslategray1
red3
deeppink4b
mediumvioletred
magenta3
darkvioleta
purpleb
darkorange3
indianred
hotpink3
mediumorchid3
mediumorchid
mediumpurple2
darkgoldenrod
lightsalmon3
rosybrown
grey63
mediumpurple2a
mediumpurple1
gold3
darkkhaki
navajowhite3
grey69
lightsteelblue3
lightsteelblue
yellow3
darkolivegreen3b
darkseagreen3a
darkseagreen2
lightcyan3
lightskyblue1
greenyellow
darkolivegreen2
palegreen1a
darkseagreen2a
darkseagreen1
paleturquoise1
red3a
deeppink3
deeppink3a
magenta3a
magenta3b
magenta2
darkorange3a
indianreda
hotpink3a
hotpink2
orchid
mediumorchid1
orange3
lightsalmon3a
lightpink3
pink3
plum3
violet
gold3a
lightgoldenrod3
tan
mistyrose3
thistle3
plum2
yellow3a
khaki3
lightgoldenrod2
lightyellow3
grey84
lightsteelblue1
yellow2
darkolivegreen1
darkolivegreen1a
darkseagreen1a
honeydew2
lightcyan1
red1
deeppink2
deeppink1
deeppink1a
magenta2a
magenta1
orangered1
indianred1
indianred1a
hotpink
hotpinka
mediumorchid1a
darkorange
salmon1
lightcoral
palevioletred1
orchid2
orchid1
orange1
sandybrown
lightsalmon1
lightpink1
pink1
plum1
gold1
lightgoldenrod2a
lightgoldenrod2b
navajowhite1
mistyrose1
thistle1
yellow1
lightgoldenrod1
khaki1
wheat1
cornsilk1
grey100
grey3
grey7
grey11
grey15
grey19
grey23
grey27
grey30
grey35
grey39
grey42
grey46
grey50
grey54
grey58
grey62
grey66
grey70
grey74
grey78
grey82
grey85
grey89
grey93

0 comments on commit eaea6f9

Please sign in to comment.