diff --git a/Entry.h b/Entry.h index 87b5193..43f1fa5 100644 --- a/Entry.h +++ b/Entry.h @@ -18,12 +18,13 @@ struct Entry unsigned day; long int hour; long int minute; - bool is_dir; + enum Type { Directory, Symlink, Normal }; + Type type; bool is_exe; }; bool is_exe( std::filesystem::directory_entry entry ); -std::string drwx( std::filesystem::directory_entry entry ); +std::string drwx( std::filesystem::directory_entry entry, Entry::Type t ); std::string format_entry( const Entry &entry, std::size_t widest ); diff --git a/cudir.cc b/cudir.cc index 1a74dcc..e8ac1d8 100644 --- a/cudir.cc +++ b/cudir.cc @@ -50,10 +50,16 @@ getEntries( const std::filesystem::path where ) } }; - entries.push_back( Entry{ entry.path().filename(), drwx( entry ), entry.is_directory() ? 0 : get_file_size( entry.path() ), + const auto type= Alepha::Utility::evaluate <=[&] + { + if( entry.is_symlink() ) return Entry::Symlink; + if( entry.is_directory() ) return Entry::Directory; + return Entry::Normal; + }; + entries.push_back( Entry{ entry.path().filename(), drwx( entry, type ), type == Entry::Normal ? get_file_size( entry.path() ) : 0, static_cast< int >( ymd.year() ), static_cast< unsigned >( ymd.month() ), static_cast< unsigned >( ymd.day() ), time_of_day.hours().count(), time_of_day.minutes().count(), - entry.is_directory(), is_exe( entry ) } ); + type, is_exe( entry ) } ); } std::sort( begin( entries ), end( entries ), []( const auto &lhs, const auto &rhs ) { return lhs.name < rhs.name; } ); @@ -124,12 +130,17 @@ main( const int argcnt, const char *const argvec[] ) { ++fileCount; totalSize+= entry.size; - std::cout << format_entry( entry, widest ) << "[m "; - if( entry.is_dir ) + std::cout << format_entry( entry, widest ) << "[m"; + if( entry.type == Entry::Directory ) { std::cout << "[1;35;95m"; std::cout << std::setw( C::sizeWidth - 1 ) << std::setfill( ' ' ) << std::right << "