Time & date support.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
@@ -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 << "[1;36;96m";
|
||||
for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500";
|
||||
@@ -50,16 +65,32 @@ main()
|
||||
if( entry.is_dir )
|
||||
{
|
||||
std::cout << "[1;35;95m";
|
||||
std::cout << std::setw( C::dirwidth - 2 ) << std::right << "<DIR>" << ' ';
|
||||
std::cout << std::setw( C::dirwidth - 2 ) << std::setfill( ' ' ) << std::right << "<DIR>" << ' ';
|
||||
}
|
||||
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 << "[m ";
|
||||
std::cout << "[1;34;94m" << entry.perms << "[m";
|
||||
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 << "[1;36;96m\u2502[m";
|
||||
|
||||
Reference in New Issue
Block a user