Skip to content

Commit

Permalink
small improvements and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Apr 28, 2020
1 parent b024288 commit 7f26344
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
45 changes: 29 additions & 16 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,20 @@ public Map<String, Boolean> scripts() {
try {
List<Path> scripts = new ArrayList<>();
if (engine.hasVariable(VAR_PATH)) {
for (String pp : (List<String>) engine.get(VAR_PATH)) {
List<String> dirs = new ArrayList<>();
for (String file : (List<String>) engine.get(VAR_PATH)) {
file = file.startsWith("~") ? file.replace("~", System.getProperty("user.home")) : file;
File dir = new File(file);
if (dir.exists() && dir.isDirectory()) {
dirs.add(file);
}
}
for (String pp : dirs) {
for (String e : scriptExtensions()) {
String regex = pp + "/*." + e;
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + regex);
Files.find(Paths.get(new File(regex).getParent()), Integer.MAX_VALUE,
(path, f) -> pathMatcher.matches(path)).forEach(p -> scripts.add(p));
(path, f) -> pathMatcher.matches(path)).forEach(p -> scripts.add(p));
}
}
}
Expand Down Expand Up @@ -929,10 +937,10 @@ private void internalPrintln(Map<String, Object> options, Object object) {
options.putIfAbsent(Printer.WIDTH, terminal().getSize().getColumns());
String style = (String) options.getOrDefault(Printer.STYLE, "");
int width = (int) options.get(Printer.WIDTH);
if (style.equalsIgnoreCase("JSON")) {
highlightAndPrint(width, style, engine.toJson(object));
} else if (!style.isEmpty() && object instanceof String) {
if (!style.isEmpty() && object instanceof String) {
highlightAndPrint(width, style, (String) object);
} else if (style.equalsIgnoreCase("JSON")) {
highlightAndPrint(width, style, engine.toJson(object));
} else if (options.containsKey(Printer.SKIP_DEFAULT_OPTIONS)) {
for (AttributedString as : highlight(options, object)) {
as.println(terminal());
Expand Down Expand Up @@ -1006,7 +1014,7 @@ private void highlightAndPrint(int width, String style, String object) {
for (String s: object.split("\\r?\\n")) {
AttributedStringBuilder asb = new AttributedStringBuilder();
asb.append(s);
if (highlighter != null) {
if (highlighter != null && s.length() < 200) {
highlighter.highlight(asb).println(terminal());
} else {
asb.subSequence(0, width).println(terminal());
Expand Down Expand Up @@ -1556,7 +1564,7 @@ private void highlightMap(Map<String, Object> options
highlightList(listOptions, collection, width, depth + 1, out);
highlightValue = false;
}
}
}
}
if (highlightValue) {
AttributedString val = highlightMapValue(mapOptions, entry.getKey(), map, defaultStyle);
Expand Down Expand Up @@ -1592,7 +1600,7 @@ private Object show(CommandInput input) {
" -? --help Displays command help",
};
try {
Options opt = parseOptions(usage, input.args());
parseOptions(usage, input.args());
Map<String, Object> options = defaultPrntOptions(false);
options.put(Printer.MAX_DEPTH, 0);
internalPrintln(options, engine.find(input.args().length > 0 ? input.args()[0] : null));
Expand All @@ -1609,7 +1617,7 @@ private Object del(CommandInput input) {
" -? --help Displays command help",
};
try {
Options opt = parseOptions(usage, input.args());
parseOptions(usage, input.args());
engine.del(input.args());
} catch (Exception e) {
exception = e;
Expand Down Expand Up @@ -1640,7 +1648,7 @@ private Object prnt(CommandInput input) {
" -w --width=WIDTH Display width (default terminal width)"
};
try {
Options opt = parseOptions(usage, input.args());
Options opt = parseOptions(usage, input.xargs());
boolean skipDefault = opt.isSet(Printer.SKIP_DEFAULT_OPTIONS);
Map<String, Object> options = defaultPrntOptions(skipDefault);
if (opt.isSet(Printer.STYLE)) {
Expand Down Expand Up @@ -1829,7 +1837,7 @@ private Object doc(CommandInput input) {
" -? --help Displays command help"
};
try {
Options opt = parseOptions(usage, input.xargs());
parseOptions(usage, input.xargs());
if (input.xargs().length == 0) {
return null;
}
Expand All @@ -1842,10 +1850,15 @@ private Object doc(CommandInput input) {
if (address != null) {
done = true;
Desktop.getDesktop().browse(new URI(address));
}
}
}
if (!done) {
String name = arg.getClass().getCanonicalName();
String name = "";
if (arg instanceof String && ((String)arg).matches("([a-z]+\\.)+[A-Z][a-zA-Z]+")) {
name = (String)arg;
} else {
name = arg.getClass().getCanonicalName();
}
name = name.replaceAll("\\.", "/") + ".html";
Object doc = null;
for (Map.Entry<String,Object> entry : docs.entrySet()) {
Expand All @@ -1857,8 +1870,8 @@ private Object doc(CommandInput input) {
if (doc != null) {
if (doc instanceof Collection) {
for (Object o : (Collection<?>)doc) {
Desktop.getDesktop().browse(new URI((String)o + name));
}
Desktop.getDesktop().browse(new URI((String)o + name));
}
} else {
Desktop.getDesktop().browse(new URI((String)doc + name));
}
Expand Down Expand Up @@ -1975,7 +1988,7 @@ private List<String> docs() {
if (d.matches("\\w+")) {
out.add(d);
}
}
}
}
return out;
}
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/scripts/init.jline
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _jnanorc << 'include ' + ROOT + 'nanorc/*.nanorc\n' > null
CONSOLE_OPTIONS = [:]
CONSOLE_OPTIONS.docs = [:]
CONSOLE_OPTIONS['docs'].put('jline','https://github.com/jline/jline3/wiki')
CONSOLE_OPTIONS['docs'].put('groovy','http://groovy-lang.org/documentation.html')
CONSOLE_OPTIONS['docs'].put('.*groovy/.*','http://docs.groovy-lang.org/latest/html/gapi/')
CONSOLE_OPTIONS['docs'].put('java.*',['https://docs.oracle.com/javase/8/docs/api/',
'http://docs.groovy-lang.org/latest/html/groovy-jdk/'])
Expand Down
6 changes: 3 additions & 3 deletions groovy/src/main/java/org/jline/script/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ private CmdDesc grabCmdDesc() {
List<String> info = new ArrayList<>();
info.add("Add maven repository dependencies to classpath");
commandInfos.put(Command.GRAB, info);
mainDesc.add(new AttributedString("grap - " + info.get(0)));
mainDesc.add(new AttributedString("Usage: grap <group>:<artifact>:<version>"));
mainDesc.add(new AttributedString(" grap --list"));
mainDesc.add(new AttributedString("grab - " + info.get(0)));
mainDesc.add(new AttributedString("Usage: grab <group>:<artifact>:<version>"));
mainDesc.add(new AttributedString(" grab --list"));
out.setMainDesc(mainDesc);
return out;
}
Expand Down

0 comments on commit 7f26344

Please # to comment.