// Path: aesh/src/main/java/org/aesh/extensions/tty/AeshPosixFilePermissions.java
// public class AeshPosixFilePermissions {
//     private AeshPosixFilePermissions() { }
// 
//     // Write string representation of permission bits to {@code sb}.
//     private static void writeBits(StringBuilder sb, boolean r, boolean w, boolean x) {
//         if (r) {
//             sb.append('r');
//         } else {
//             sb.append('-');
//         }
//         if (w) {
//             sb.append('w');
//         } else {
//             sb.append('-');
//         }
//         if (x) {
//             sb.append('x');
//         } else {
//             sb.append('-');
//         }
//     }
// 
//     /**
//      * @return  the string representation of the file
//      */
//     public static String toString(PosixFileAttributes attr) {
//         Set<PosixFilePermission> perms = attr.permissions();
//         StringBuilder sb = new StringBuilder(10);
//         if(attr.isDirectory())
//             sb.append('d');
//         else if(attr.isSymbolicLink())
//             sb.append('l');
//         else
//             sb.append('-');
// 
//         writeBits(sb, perms.contains(OWNER_READ), perms.contains(OWNER_WRITE),
//           perms.contains(OWNER_EXECUTE));
//         writeBits(sb, perms.contains(GROUP_READ), perms.contains(GROUP_WRITE),
//           perms.contains(GROUP_EXECUTE));
//         writeBits(sb, perms.contains(OTHERS_READ), perms.contains(OTHERS_WRITE),
//           perms.contains(OTHERS_EXECUTE));
//         return sb.toString();
//     }
// }


import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandResult;
import org.aesh.command.invocation.CommandInvocation;
import org.aesh.command.option.Arguments;
import org.aesh.command.option.Option;
import org.aesh.command.shell.Shell;
import org.aesh.comparators.PosixFileNameComparator;
import org.aesh.extensions.tty.AeshPosixFilePermissions;
import org.aesh.io.Resource;
import org.aesh.io.filter.NoDotNamesFilter;
import org.aesh.readline.terminal.formatting.Color;
import org.aesh.readline.terminal.formatting.TerminalColor;
import org.aesh.readline.terminal.formatting.TerminalString;
import org.aesh.readline.util.Parser;
import org.aesh.terminal.utils.Config;
import java.io.IOException;
import java.math.RoundingMode;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
    }

    private void displayFile(Resource input, Shell shell) {
        if(longListing) {
            List<Resource> resourceList = new ArrayList<>(1);
            resourceList.add(input);
            shell.write(displayLongListing(resourceList));
        }
        else {
            List<Resource> resourceList = new ArrayList<>(1);
            resourceList.add(input);
            shell.write(Parser.formatDisplayListTerminalString(
                    formatFileList(resourceList), shell.size().getHeight(), shell.size().getWidth()));
        }
    }

    private String displayLongListing(List<Resource> files) {

        StringGroup access = new StringGroup(files.size());
        StringGroup size = new StringGroup(files.size());
        StringGroup owner = new StringGroup(files.size());
        StringGroup group = new StringGroup(files.size());
        StringGroup modified = new StringGroup(files.size());

        try {
            int counter = 0;
            for(Resource file : files) {
                BasicFileAttributes attr = file.readAttributes(fileAttributes, LinkOption.NOFOLLOW_LINKS);

                if (Config.isOSPOSIXCompatible()) {
// Path: aesh/src/main/java/org/aesh/extensions/tty/AeshPosixFilePermissions.java
// public class AeshPosixFilePermissions {
//     private AeshPosixFilePermissions() { }
// 
//     // Write string representation of permission bits to {@code sb}.
//     private static void writeBits(StringBuilder sb, boolean r, boolean w, boolean x) {
//         if (r) {
//             sb.append('r');
//         } else {
//             sb.append('-');
//         }
//         if (w) {
//             sb.append('w');
//         } else {
//             sb.append('-');
//         }
//         if (x) {
//             sb.append('x');
//         } else {
//             sb.append('-');
//         }
//     }
// 
//     /**
//      * @return  the string representation of the file
//      */
//     public static String toString(PosixFileAttributes attr) {
//         Set<PosixFilePermission> perms = attr.permissions();
//         StringBuilder sb = new StringBuilder(10);
//         if(attr.isDirectory())
//             sb.append('d');
//         else if(attr.isSymbolicLink())
//             sb.append('l');
//         else
//             sb.append('-');
// 
//         writeBits(sb, perms.contains(OWNER_READ), perms.contains(OWNER_WRITE),
//           perms.contains(OWNER_EXECUTE));
//         writeBits(sb, perms.contains(GROUP_READ), perms.contains(GROUP_WRITE),
//           perms.contains(GROUP_EXECUTE));
//         writeBits(sb, perms.contains(OTHERS_READ), perms.contains(OTHERS_WRITE),
//           perms.contains(OTHERS_EXECUTE));
//         return sb.toString();
//     }
// }


// Path: aesh/src/main/java/org/aesh/extensions/ls/Ls.java
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandResult;
import org.aesh.command.invocation.CommandInvocation;
import org.aesh.command.option.Arguments;
import org.aesh.command.option.Option;
import org.aesh.command.shell.Shell;
import org.aesh.comparators.PosixFileNameComparator;
import org.aesh.extensions.tty.AeshPosixFilePermissions;
import org.aesh.io.Resource;
import org.aesh.io.filter.NoDotNamesFilter;
import org.aesh.readline.terminal.formatting.Color;
import org.aesh.readline.terminal.formatting.TerminalColor;
import org.aesh.readline.terminal.formatting.TerminalString;
import org.aesh.readline.util.Parser;
import org.aesh.terminal.utils.Config;
import java.io.IOException;
import java.math.RoundingMode;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

    }

    private void displayFile(Resource input, Shell shell) {
        if(longListing) {
            List<Resource> resourceList = new ArrayList<>(1);
            resourceList.add(input);
            shell.write(displayLongListing(resourceList));
        }
        else {
            List<Resource> resourceList = new ArrayList<>(1);
            resourceList.add(input);
            shell.write(Parser.formatDisplayListTerminalString(
                    formatFileList(resourceList), shell.size().getHeight(), shell.size().getWidth()));
        }
    }

    private String displayLongListing(List<Resource> files) {

        StringGroup access = new StringGroup(files.size());
        StringGroup size = new StringGroup(files.size());
        StringGroup owner = new StringGroup(files.size());
        StringGroup group = new StringGroup(files.size());
        StringGroup modified = new StringGroup(files.size());

        try {
            int counter = 0;
            for(Resource file : files) {
                BasicFileAttributes attr = file.readAttributes(fileAttributes, LinkOption.NOFOLLOW_LINKS);

                if (Config.isOSPOSIXCompatible()) {
                    access.addString(AeshPosixFilePermissions.toString(((PosixFileAttributes) attr)), counter);