diff --git a/README.md b/README.md index 94e88f5..403a3bb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ###### Jorge Pérez Ludeña Aplicación que imita el comando tree. Pide una ruta, la cual analiza - +Hago que pinte por colores las diferentes carpetas Asi sale la consola ~~~ diff --git a/bin/jorpelu/com/Tree.class b/bin/jorpelu/com/Tree.class index c2d5386..c57a5b0 100644 Binary files a/bin/jorpelu/com/Tree.class and b/bin/jorpelu/com/Tree.class differ diff --git a/src/jorpelu/com/Tree.java b/src/jorpelu/com/Tree.java index 2f5ca91..84f474e 100644 --- a/src/jorpelu/com/Tree.java +++ b/src/jorpelu/com/Tree.java @@ -1,17 +1,36 @@ package jorpelu.com; -import java.io.File; import java.io.IOException; +import java.io.File; import java.util.Scanner; public class Tree { + static int contador = 0; + static String colores[] = new String[7]; + + public static final String ANSI_GREEN = "\u001B[32m"; + public static final String ANSI_RESET = "\u001B[0m"; /* + * public static final String ANSI_BLACK = "\u001B[30m"; public static final + * String ANSI_RED = "\u001B[31m"; + * + * public static final String ANSI_YELLOW = "\u001B[33m"; public static final + * String ANSI_BLUE = "\u001B[34m"; public static final String ANSI_PURPLE = + * "\u001B[35m"; public static final String ANSI_CYAN = "\u001B[36m"; + */ public static void main(String[] args) throws IOException { + colores[0] = "\u001B[30m"; + colores[1] = "\u001B[31m"; + colores[2] = "\u001B[32m"; + colores[3] = "\u001B[33m"; + colores[4] = "\u001B[34m"; + colores[5] = "\u001B[35m"; + colores[6] = "\u001B[36m"; printFile(pideRuta(), ""); } public static File pideRuta() { - System.out.println("Introduzca una ruta a analizar: "); + System.out.println(ANSI_GREEN.concat("Introduzca una ruta a analizar: "+ANSI_RESET)); Scanner sc = new Scanner(System.in); File f = null; try { @@ -25,13 +44,22 @@ public class Tree { } public static void printFile(File f, String spaces) { - System.out.println(spaces.concat("|____").concat(f.getName())); + + System.out.println(spaces.concat("|____").concat(f.getName())+ANSI_RESET); if (f.isDirectory() && f.canRead()) { for (File file : f.listFiles()) { - printFile(file, spaces.concat(" ")); + printFile(file, spaces.concat(" " + colores[contador])); } } + + if(contador<6) { + contador++; + }else{ + contador = 0; + } + } + }