diff --git a/Entry.h b/Entry.h index 972103f..87b5193 100644 --- a/Entry.h +++ b/Entry.h @@ -13,6 +13,11 @@ struct Entry std::string name; std::string perms; std::size_t size; + int year; + unsigned month; + unsigned day; + long int hour; + long int minute; bool is_dir; bool is_exe; }; diff --git a/cudir.cc b/cudir.cc index 5f5ef1f..d1ac35c 100644 --- a/cudir.cc +++ b/cudir.cc @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include @@ -12,7 +14,16 @@ getEntries( const std::filesystem::path where ) for( const auto &entry: std::filesystem::directory_iterator{ where } ) { - entries.emplace_back( entry.path().filename(), drwx( entry ), entry.is_directory() ? 0 : file_size( entry.path() ), entry.is_directory(), is_exe( entry ) ); + const auto time= std::filesystem::file_time_type::clock::to_sys( last_write_time( entry.path() ) ); + const auto day= std::chrono::floor< std::chrono::days >( time ); + const std::chrono::year_month_day ymd{ day }; + const auto time_since_midnight= day - time; + const std::chrono::hh_mm_ss time_of_day{ std::chrono::floor< std::chrono::minutes >( time_since_midnight ) }; + + entries.push_back( Entry{ entry.path().filename(), drwx( entry ), entry.is_directory() ? 0 : file_size( entry.path() ), + 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 ) } ); } std::sort( begin( entries ), end( entries ), []( const auto &lhs, const auto &rhs ) { return lhs.name < rhs.name; } ); @@ -20,9 +31,13 @@ getEntries( const std::filesystem::path where ) return entries; } + using namespace std::literals::string_literals; + namespace C { constexpr int dirwidth= 9; + constexpr int dateWidth= "82-12-21"s.size(); + constexpr int timeWidth= "12:34"s.size(); } int @@ -35,7 +50,7 @@ main() 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::dirwidth + 3 + 10 + 2; + const int rowWidth= widest + C::filePadding + C::dirwidth + 3 + 10 + 2 + C::dateWidth + 1 + C::timeWidth; std::cout << ""; for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500"; @@ -50,16 +65,32 @@ main() if( entry.is_dir ) { std::cout << ""; - std::cout << std::setw( C::dirwidth - 2 ) << std::right << "" << ' '; + std::cout << std::setw( C::dirwidth - 2 ) << std::setfill( ' ' ) << std::right << "" << ' '; } else { //std::cout << " "; - std::cout << "\e[1;33;93m" << std::setw( C::dirwidth - 1 ) << entry.size; + std::cout << "\e[1;33;93m" << std::setw( C::dirwidth - 1 ) << std::setfill( ' ' ) << entry.size; } std::cout << " "; std::cout << "" << entry.perms << ""; std::cout << " "; + + // Date + std::cout << "\e[1;31;91m"; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.year % 100 << '-'; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.month << '-'; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.day; + std::cout << "\e[m"; + + std::cout << ' '; + + // Time + std::cout << "\e[1;32;92m"; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.hour << ':'; + std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.minute; + std::cout << "\e[m"; + if( side == false ) { std::cout << "\u2502"; diff --git a/format.cc b/format.cc index e7dd35a..84b34fd 100644 --- a/format.cc +++ b/format.cc @@ -17,7 +17,7 @@ format_entry( const Entry &entry, const std::size_t widest ) { oss << "1;36;96"; } - oss << 'm' << std::setw( widest + C::filePadding ) << std::left << entry.name; + oss << 'm' << std::setw( widest + C::filePadding ) << std::setfill( ' ' ) << std::left << entry.name; return std::move( oss ).str(); }