Fix styling a bit
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1736002 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java
index 1d91d46..7617f7b 100644
--- a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java
+++ b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java
@@ -216,10 +216,10 @@
sb.style(sb.style().foreground(AttributedStyle.CYAN));
break;
case Function:
- sb.style(sb.style().foreground(AttributedStyle.BLUE));
+ sb.style(sb.style().foreground(AttributedStyle.BLUE + AttributedStyle.BRIGHT));
break;
case BadFunction:
- sb.style(sb.style().foreground(AttributedStyle.RED));
+ sb.style(sb.style().foreground(AttributedStyle.RED + AttributedStyle.BRIGHT));
break;
case Repair:
sb.style(sb.style().foreground(AttributedStyle.BLACK + AttributedStyle.BRIGHT));
diff --git a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java
index 47784cd..807c319 100644
--- a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java
+++ b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java
@@ -24,6 +24,9 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -45,6 +48,7 @@
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
import org.jline.reader.Widget;
+import org.jline.reader.impl.completer.completer.FileNameCompleter;
import org.jline.terminal.Attributes;
import org.jline.terminal.Terminal;
import org.jline.utils.InfoCmp.Capability;
@@ -209,7 +213,12 @@
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
- new FilesCompleter(session.currentDir()).complete(reader, line, candidates);
+ new FilesCompleter(session.currentDir()) {
+ @Override
+ protected String getDisplay(Path p) {
+ return getFileDisplay(session, p);
+ }
+ }.complete(reader, line, candidates);
return candidates;
}
@@ -217,10 +226,43 @@
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
- new DirectoriesCompleter(session.currentDir()).complete(reader, line, candidates);
+ new DirectoriesCompleter(session.currentDir()) {
+ @Override
+ protected String getDisplay(Path p) {
+ return getFileDisplay(session, p);
+ }
+ }.complete(reader, line, candidates);
return candidates;
}
+ private String getFileDisplay(CommandSession session, Path path) {
+ String type;
+ String suffix;
+ if (Files.isSymbolicLink(path)) {
+ type = "sl";
+ suffix = "@";
+ } else if (Files.isDirectory(path)) {
+ type = "dr";
+ suffix = "/";
+ } else if (Files.isExecutable(path)) {
+ type = "ex";
+ suffix = "*";
+ } else if (!Files.isRegularFile(path)) {
+ type = "ot";
+ suffix = "";
+ } else {
+ type = "";
+ suffix = "";
+ }
+ String col = Posix.getColorMap(session, "LS").get(type);
+ if (col != null && !col.isEmpty()) {
+ return "\033[" + col + "m" + path.getFileName().toString() + "\033[m" + suffix;
+ } else {
+ return path.getFileName().toString() + suffix;
+ }
+
+ }
+
public void __usage_completion(CommandSession session, String command) throws Exception {
Object func = session.get(command.contains(":") ? command : "*:" + command);
if (func instanceof Function) {
diff --git a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java
index e40c2ef..d523a32 100644
--- a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java
+++ b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java
@@ -77,6 +77,8 @@
public class Posix {
static final String[] functions = {"cat", "echo", "grep", "sort", "sleep", "cd", "pwd", "ls"};
+ public static final String DEFAULT_LS_COLORS = "dr=1;91:ex=1;92:sl=1;96:ot=34;43";
+
public void _main(CommandSession session, String[] argv) {
if (argv == null || argv.length < 1) {
throw new IllegalArgumentException();
@@ -227,7 +229,7 @@
" -h print sizes in human readable form"
};
Options opt = parseOptions(session, usage, argv);
- Map<String, String> colors = getColorMap(session, "LS", "dr=34:ex=31:sl=35:ot=34;43");
+ Map<String, String> colors = getColorMap(session, "LS");
class PathEntry implements Comparable<PathEntry> {
final Path abs;
@@ -280,13 +282,7 @@
String type;
String suffix;
String link = "";
- if (is("isDirectory")) {
- type = "dr";
- suffix = "/";
- } else if (is("isExecutable")) {
- type = "ex";
- suffix = "*";
- } else if (is("isSymbolicLink")) {
+ if (is("isSymbolicLink")) {
type = "sl";
suffix = "@";
try {
@@ -295,9 +291,12 @@
} catch (IOException e) {
// ignore
}
- } else if (is("isRegularFile")) {
- type = "rg";
- suffix = "";
+ } else if (is("isDirectory")) {
+ type = "dr";
+ suffix = "/";
+ } else if (is("isExecutable")) {
+ type = "ex";
+ suffix = "*";
} else if (is("isOther")) {
type = "ot";
suffix = "";
@@ -511,7 +510,7 @@
}
sb.append('\n');
}
- out.print(sb.toAnsi());
+ out.print(sb.toAnsi(terminal));
}
}
@@ -1085,11 +1084,15 @@
return params.toArray(new String[params.size()]);
}
- private Map<String, String> getColorMap(CommandSession session, String name, String def) {
+ public static Map<String, String> getColorMap(CommandSession session, String name) {
Object obj = session.get(name + "_COLORS");
String str = obj != null ? obj.toString() : null;
if (str == null || !str.matches("[a-z]{2}=[0-9]+(;[0-9]+)*(:[a-z]{2}=[0-9]+(;[0-9]+)*)*")) {
- str = def;
+ if ("LS".equals(name)) {
+ str = DEFAULT_LS_COLORS;
+ } else {
+ str = "";
+ }
}
return Arrays.stream(str.split(":"))
.collect(Collectors.toMap(s -> s.substring(0, s.indexOf('=')),