Skip to content

Commit

Permalink
Merge pull request #540 from mattirn/console-package
Browse files Browse the repository at this point in the history
Added jline-console module
  • Loading branch information
mattirn committed Jun 2, 2020
2 parents 10c3f20 + aa84d18 commit 78b4c9f
Show file tree
Hide file tree
Showing 43 changed files with 3,316 additions and 2,914 deletions.
4 changes: 0 additions & 4 deletions builtins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<groupId>org.jline</groupId>
<artifactId>jline-style</artifactId>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-groovy</artifactId>
</dependency>

<dependency>
<groupId>com.googlecode.juniversalchardet</groupId>
Expand Down
1 change: 0 additions & 1 deletion builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.jline.builtins.Options.HelpException;
import org.jline.builtins.Source.StdInSource;
import org.jline.builtins.Source.URLSource;
import org.jline.console.ConfigurationPath;
import org.jline.keymap.KeyMap;
import org.jline.reader.Binding;
import org.jline.reader.Highlighter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.console;
package org.jline.builtins;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
19 changes: 19 additions & 0 deletions builtins/src/main/java/org/jline/builtins/ConsoleOptionGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2002-2020, 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.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.builtins;

public interface ConsoleOptionGetter {

/**
* Return console option value
* @param name the option name
* @return option value
*/
Object consoleOption(String name);
}
1 change: 0 additions & 1 deletion builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.jline.builtins.Nano.SyntaxHighlighter;
import org.jline.builtins.Source.ResourceSource;
import org.jline.builtins.Source.URLSource;
import org.jline.console.ConfigurationPath;
import org.jline.keymap.BindingReader;
import org.jline.keymap.KeyMap;
import org.jline.terminal.Attributes;
Expand Down
1 change: 0 additions & 1 deletion builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jline.console.ConfigurationPath;
import org.jline.keymap.BindingReader;
import org.jline.keymap.KeyMap;
import org.jline.reader.Editor;
Expand Down
24 changes: 14 additions & 10 deletions builtins/src/main/java/org/jline/builtins/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class Styles {
private static final String LS_COLORS = "LS_COLORS";
private static final String HELP_COLORS = "HELP_COLORS";
private static final String PRNT_COLORS = "PRNT_COLORS";

private static final String KEY = "([a-z]{2}|\\*\\.[a-zA-Z0-9]+)";
private static final String VALUE = "[0-9]*(;[0-9]+){0,2}";
private static final String VALUE = "[0-9]*(;[0-9]+){0,2}";
private static final String ANSI_STYLE_PATTERN = KEY + "=" + VALUE + "(:" + KEY + "=" + VALUE + ")*(:|)";

public static StyleResolver lsStyle() {
Expand All @@ -37,7 +37,7 @@ public static StyleResolver helpStyle() {
public static StyleResolver prntStyle() {
return style(PRNT_COLORS, DEFAULT_PRNT_COLORS);
}

private static StyleResolver style(String name, String defStyle) {
String style = consoleOption(name);
if (style == null) {
Expand All @@ -48,12 +48,16 @@ private static StyleResolver style(String name, String defStyle) {

private static String consoleOption(String name) {
String out = null;
SystemRegistry sr = SystemRegistry.get();
if (sr != null) {
out = (String)sr.consoleOption(name);
if (out != null && !out.matches(ANSI_STYLE_PATTERN)) {
out = null;
try {
ConsoleOptionGetter cog = (ConsoleOptionGetter)Class.forName("org.jline.console.SystemRegistry")
.getDeclaredMethod("get").invoke(null);
if (cog != null) {
out = (String)cog.consoleOption(name);
if (out != null && !out.matches(ANSI_STYLE_PATTERN)) {
out = null;
}
}
} catch (Exception e) {
}
if (out == null) {
out = System.getenv(name);
Expand All @@ -63,11 +67,11 @@ private static String consoleOption(String name) {
}
return out;
}

private static StyleResolver style(String style) {
Map<String, String> colors = Arrays.stream(style.split(":"))
.collect(Collectors.toMap(s -> s.substring(0, s.indexOf('=')),
s -> s.substring(s.indexOf('=') + 1)));
return new StyleResolver(colors::get);
}
}
}

0 comments on commit 78b4c9f

Please sign in to comment.