Skip to content

Commit

Permalink
Merge branch 'master' into tailtip-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Oct 27, 2019
2 parents 3911e26 + da89fc4 commit 8e47654
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 18 deletions.
2 changes: 1 addition & 1 deletion builtins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-builtins</artifactId>
Expand Down
74 changes: 71 additions & 3 deletions builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -1419,16 +1419,16 @@ void replaceFromCursor(int chars, String string) {
}
}

protected static class SyntaxHighlighter {
public static class SyntaxHighlighter {
private List<HighlightRule> rules = new ArrayList<>();
private int ruleStartId = 0;

private SyntaxHighlighter() {}

public static SyntaxHighlighter build(List<Path> syntaxFiles, String file, String syntaxName) {
protected static SyntaxHighlighter build(List<Path> syntaxFiles, String file, String syntaxName) {
SyntaxHighlighter out = new SyntaxHighlighter();
List<HighlightRule> defaultRules = new ArrayList<>();
if (file != null && (syntaxName == null || (syntaxName != null && !syntaxName.equals("none")))) {
if (syntaxName == null || (syntaxName != null && !syntaxName.equals("none"))) {
for (Path p: syntaxFiles) {
NanorcParser parser = new NanorcParser(p, syntaxName, file);
try {
Expand All @@ -1447,6 +1447,46 @@ public static SyntaxHighlighter build(List<Path> syntaxFiles, String file, Strin
return out;
}

/**
* Build SyntaxHighlighter
*
* @param nanorc Path of nano config file jnanorc
* @param syntaxName syntax name e.g 'Java'
* @return SyntaxHighlighter
*/
public static SyntaxHighlighter build(Path nanorc, String syntaxName) {
SyntaxHighlighter out = new SyntaxHighlighter();
List<Path> syntaxFiles = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(nanorc.toFile()));
String line = reader.readLine();
while (line != null) {
line = line.trim();
if (line.length() > 0 && !line.startsWith("#")) {
List<String> parts = Parser.split(line);
if (parts.get(0).equals("include")) {
if (parts.get(1).contains("*") || parts.get(1).contains("?")) {
PathMatcher pathMatcher = FileSystems
.getDefault().getPathMatcher("glob:" + parts.get(1));
Files.find(
Paths.get(new File(parts.get(1)).getParent()),
Integer.MAX_VALUE,
(path, f) -> pathMatcher.matches(path))
.forEach(p -> syntaxFiles.add(p));
} else {
syntaxFiles.add(Paths.get(parts.get(1)));
}
}
}
line = reader.readLine();
}
reader.close();
out = build(syntaxFiles, null, syntaxName);
} catch (Exception e) {
}
return out;
}

private void addRules(List<HighlightRule> rules) {
this.rules.addAll(rules);
}
Expand All @@ -1455,6 +1495,10 @@ public void reset() {
ruleStartId = 0;
}

public AttributedString highlight(String string) {
return highlight(new AttributedString(string));
}

public AttributedString highlight(AttributedStringBuilder asb) {
return highlight(asb.toAttributedString());
}
Expand Down Expand Up @@ -1584,6 +1628,10 @@ private static class NanorcParser {
private List<HighlightRule> highlightRules = new ArrayList<>();
private String syntaxName;

public NanorcParser(Path file, String name) {
this(file, name, null);
}

public NanorcParser(Path file, String name, String target) {
this.file = file.toFile();
this.name = name;
Expand Down Expand Up @@ -1686,6 +1734,26 @@ private void addHighlightRule(List<String> parts, boolean caseInsensitive) {
if (bcolor != null) {
style = style.background(bcolor);
}
// extended nanorc..
if (styleStrings.length > 2) {
if (styleStrings[2].equals("blink")) {
style = style.blink();
} else if (styleStrings[2].equals("bold")) {
style = style.bold();
} else if (styleStrings[2].equals("conceal")) {
style = style.conceal();
} else if (styleStrings[2].equals("faint")) {
style = style.faint();
} else if (styleStrings[2].equals("hidden")) {
style = style.hidden();
} else if (styleStrings[2].equals("inverse")) {
style = style.inverse();
} else if (styleStrings[2].equals("italic")) {
style = style.italic();
} else if (styleStrings[2].equals("underline")) {
style = style.underline();
}
}

if (HighlightRule.evalRuleType(parts) == HighlightRule.RuleType.PATTERN) {
for (int i = 2; i < parts.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-demo</artifactId>
Expand Down
42 changes: 41 additions & 1 deletion jline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline</artifactId>
Expand Down Expand Up @@ -58,6 +58,46 @@
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jna</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-builtins</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-remote-ssh</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-remote-telnet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-style</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<artifactId>jline-parent</artifactId>
<name>JLine Parent</name>
<description>JLine</description>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
<packaging>pom</packaging>

<licenses>
Expand Down Expand Up @@ -420,7 +420,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.1</version>
<configuration>
<additionalparam>-Xdoclint:none </additionalparam>
<additionalparam>-notimestamp </additionalparam>
Expand Down
2 changes: 1 addition & 1 deletion reader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-reader</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ private String format(Entry entry) {
}

public String get(final int index) {
return items.get(index - offset).line();
int idx = index - offset;
if (idx >= items.size() || idx < 0) {
throw new IllegalArgumentException("IndexOutOfBounds: Index:" + idx +", Size:" + items.size());
}
return items.get(idx).line();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion remote-ssh/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-remote-ssh</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion remote-telnet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-remote-telnet</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion style/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-style</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion terminal-jansi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-terminal-jansi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion terminal-jna/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-terminal-jna</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion terminal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.jline</groupId>
<artifactId>jline-parent</artifactId>
<version>3.13.1-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
</parent>

<artifactId>jline-terminal</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion terminal/src/main/java/org/jline/utils/InfoCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ public static void parseInfoCmp(
String key = cap.substring(0, index);
String val = cap.substring(index + 1);
int iVal;
if (val.startsWith("0x")) {
if ("0".equals(val)) {
iVal = 0;
} else if (val.startsWith("0x")) {
iVal = Integer.parseInt(val.substring(2), 16);
} else if (val.startsWith("0")) {
iVal = Integer.parseInt(val.substring(1), 8);
Expand Down
3 changes: 2 additions & 1 deletion terminal/src/test/java/org/jline/utils/InfoCmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public void testInfoCmpWithHexa() {
Map<Capability, String> strings = new HashMap<>();
String infocmp = "xterm-256color|xterm with 256 colors,\n" +
"\tam, bce, ccc, km, mc5i, mir, msgr, npc, xenl,\n" +
"\tcolors#0x100, cols#80, it#8, lines#24, pairs#0x7fff,\n" +
"\tcolors#0x100, cols#010, it#0, lines#24, pairs#0x7fff,\n" +
"\tacsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,\n" +
"\tbel=^G, blink=\\E[5m, bold=\\E[1m, cbt=\\E[Z, civis=\\E[?25l\n";
InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
assertEquals(8, (int) ints.get(Capability.columns));
assertEquals(0x100, (int) ints.get(Capability.max_colors));
assertEquals(0x7fff, (int) ints.get(Capability.max_pairs));
}
Expand Down

0 comments on commit 8e47654

Please sign in to comment.