diff --git a/cudir.cc b/cudir.cc index 6bc9c8f..2538f66 100644 --- a/cudir.cc +++ b/cudir.cc @@ -5,8 +5,13 @@ #include #include +#include + +#include + #include "Entry.h" + auto getEntries( const std::filesystem::path where ) { @@ -31,26 +36,48 @@ getEntries( const std::filesystem::path where ) return entries; } - using namespace std::literals::string_literals; +using namespace std::literals::string_literals; namespace C { constexpr int sizeWidth= 14; constexpr int dateWidth= "1982-12-21"s.size(); + constexpr int shortDateWidth= "82-12-21"s.size(); constexpr int timeWidth= "12:34"s.size(); + constexpr int modeBitsWidth= "drwxrwxrwx"s.size(); +} + +namespace O +{ + bool twoDigitDate= false; + + auto init= Alepha::Utility::enroll <=[] + { + using namespace Alepha::ProgramOptions_m; + + --"short-date"_option << twoDigitDate << "Use short 2-digit years in date stamps"; + }; +} + +inline int +trimYear( const int year ) +{ + if( O::twoDigitDate ) return year % 100; + else return year; } int -main() +main( const int argcnt, const char *const argvec[] ) { std::filesystem::path where="./"; + const auto args= Alepha::handleOptions( argcnt, argvec ); const auto entries= getEntries( where ); const auto widest= std::max_element( begin( entries ), end( entries ), []( const auto &lhs, const auto &rhs ) { return lhs.name.size() < rhs.name.size(); } )->name.size(); - const int rowWidth= widest + C::filePadding + C::sizeWidth + 2 + 10 + 2 + C::dateWidth + 1 + C::timeWidth; + const int rowWidth= widest + C::filePadding + C::sizeWidth + 1 + C::modeBitsWidth + 2 + ( O::twoDigitDate ? C::shortDateWidth : C::dateWidth )+ 1 + C::timeWidth; std::cout << ""; for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500"; @@ -83,7 +110,7 @@ main() // Date std::cout << "\e[1;31;91m"; - std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.year % 10000 << '-'; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << trimYear( entry.year % 10000 ) << '-'; std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.month << '-'; std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.day; std::cout << "\e[m";