felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1736002 - in /felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline: Highlighter.java JLineCommands.java Posix.java
Date Mon, 21 Mar 2016 16:53:54 GMT
Author: gnodet
Date: Mon Mar 21 16:53:54 2016
New Revision: 1736002

URL: http://svn.apache.org/viewvc?rev=1736002&view=rev
Log:
Fix styling a bit

Modified:
    felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java
    felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java
    felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java

Modified: felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java?rev=1736002&r1=1736001&r2=1736002&view=diff
==============================================================================
--- felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java (original)
+++ felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Highlighter.java Mon
Mar 21 16:53:54 2016
@@ -216,10 +216,10 @@ public class Highlighter extends Default
                             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));

Modified: felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java?rev=1736002&r1=1736001&r2=1736002&view=diff
==============================================================================
--- felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java (original)
+++ felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/JLineCommands.java Mon
Mar 21 16:53:54 2016
@@ -24,6 +24,9 @@ import java.io.IOException;
 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.Candidate;
 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 @@ public class JLineCommands {
         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 @@ public class JLineCommands {
         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) {

Modified: felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java?rev=1736002&r1=1736001&r2=1736002&view=diff
==============================================================================
--- felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java (original)
+++ felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Posix.java Mon Mar 21
16:53:54 2016
@@ -77,6 +77,8 @@ import org.jline.utils.AttributedStyle;
 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 @@ public class Posix {
                 "  -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 @@ public class Posix {
                 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 @@ public class Posix {
                     } 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 @@ public class Posix {
                 }
                 sb.append('\n');
             }
-            out.print(sb.toAnsi());
+            out.print(sb.toAnsi(terminal));
         }
     }
 
@@ -1085,11 +1084,15 @@ public class Posix {
         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('=')),



Mime
View raw message