Skip to content

Commit

Permalink
Fix for #328
Browse files Browse the repository at this point in the history
Properly register dumb-color terminal caps file
  • Loading branch information
Bartosz Jablonski-Adamczyk authored and Bartosz Jablonski-Adamczyk committed Aug 12, 2019
1 parent bd6bbb1 commit 742b0cb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
10 changes: 5 additions & 5 deletions terminal/src/main/java/org/jline/utils/InfoCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public static Capability byName(String name) {
return getCapabilitiesByName().get(name);
}
}

public static Map<String, Capability> getCapabilitiesByName() {
Map<String, Capability> capabilities = new LinkedHashMap<>();
try (InputStream is = InfoCmp.class.getResourceAsStream("capabilities.txt");
Expand Down Expand Up @@ -550,7 +550,7 @@ public static String getInfoCmp(
}
return caps;
}

public static String getLoadedInfoCmp(String terminal) {
Object caps = CAPS.get(terminal);
if (caps instanceof Supplier) {
Expand Down Expand Up @@ -615,9 +615,9 @@ static String loadDefaultInfoCmp(String name) {
}

static {
for (String s : Arrays.asList("dumb", "ansi", "xterm", "xterm-256color",
"windows", "windows-256color", "windows-conemu", "windows-vtp",
"screen", "screen-256color")) {
for (String s : Arrays.asList("dumb", "dumb-color", "ansi", "xterm", "xterm-256color",
"windows", "windows-256color", "windows-conemu", "windows-vtp",
"screen", "screen-256color")) {
setDefaultInfoCmp(s, () -> loadDefaultInfoCmp(s));
}
}
Expand Down
48 changes: 45 additions & 3 deletions terminal/src/test/java/org/jline/utils/InfoCmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@
*/
package org.jline.utils;

import org.jline.utils.InfoCmp.Capability;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jline.utils.InfoCmp.Capability;
import org.junit.Test;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -60,4 +76,30 @@ public void testClrEos() {
InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
assertEquals("\\E[J", strings.get(Capability.clr_eos));
}

@Test
public void testAllCapsFile() throws IOException {
String packagePath = InfoCmp.class.getPackage().getName().replace(".", "/");
ArrayList<URL> packageLocations = Collections.list(Thread.currentThread().getContextClassLoader().getResources(packagePath));
List<String> allCaps = packageLocations.stream().map(url -> {
try {
Path capsLocation = Paths.get(url.toURI());
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:**.caps");
List<String> s = Files.walk(capsLocation)
.filter(pathMatcher::matches)
.map(Path::getFileName)
.map(Path::toString)
.map(fileName -> fileName.split("\\.")[0])
.collect(Collectors.toList());
return s.stream();
} catch (URISyntaxException | IOException e) {
throw new RuntimeException(e);
}
}).flatMap(Function.identity())
.collect(Collectors.toList());

allCaps.forEach(
(capsName) -> assertNotNull(String.format("%s.caps was not registered in InfoCmp class", capsName), InfoCmp.getLoadedInfoCmp(capsName))
);
}
}

0 comments on commit 742b0cb

Please sign in to comment.