A bit of visual sketch for where I want to go.
I'm looking to emulate a lot of the `HotDir 2.1` look that I used to use.
This commit is contained in:
@@ -6,3 +6,6 @@ CPPFLAGS+= -I.
|
|||||||
LDFLAGS+= -Wl,-rpath,'$$ORIGIN/'
|
LDFLAGS+= -Wl,-rpath,'$$ORIGIN/'
|
||||||
|
|
||||||
all: cudir
|
all: cudir
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f cudir
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
#include <filesystem>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_exe( const std::filesystem::directory_entry entry )
|
||||||
|
{
|
||||||
|
using std::filesystem::perms;
|
||||||
|
auto p= status( entry.path() ).permissions();
|
||||||
|
|
||||||
|
return ( perms::none != ( p & ( perms::owner_exec | perms::group_exec | perms::others_exec ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
drwx( const std::filesystem::perms p )
|
drwx( const std::filesystem::directory_entry entry )
|
||||||
{
|
{
|
||||||
|
auto p= status( entry.path() ).permissions();
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
using std::filesystem::perms;
|
using std::filesystem::perms;
|
||||||
auto show = [&](const char op, const perms perm)
|
auto show = [&](const char op, const perms perm)
|
||||||
{
|
{
|
||||||
oss << (perms::none == (perm bitand p) ? '-' : op);
|
oss << (perms::none == (perm bitand p) ? '-' : op);
|
||||||
};
|
};
|
||||||
|
oss << ( entry.is_directory() ? 'd' : '-' );
|
||||||
show('r', perms::owner_read);
|
show('r', perms::owner_read);
|
||||||
show('w', perms::owner_write);
|
show('w', perms::owner_write);
|
||||||
show('x', perms::owner_exec);
|
show('x', perms::owner_exec);
|
||||||
@@ -23,13 +37,63 @@ drwx( const std::filesystem::perms p )
|
|||||||
return std::move( oss ).str();
|
return std::move( oss ).str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Entry
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string perms;
|
||||||
|
bool is_dir;
|
||||||
|
bool is_exe;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string
|
||||||
|
format_entry( const Entry &entry, const std::size_t widest )
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "[";
|
||||||
|
|
||||||
|
if( entry.is_dir )
|
||||||
|
{
|
||||||
|
oss << "1;35;95";
|
||||||
|
}
|
||||||
|
else if( entry.is_exe )
|
||||||
|
{
|
||||||
|
oss << "1;36;96";
|
||||||
|
}
|
||||||
|
oss << 'm' << std::setw( widest + 8 ) << std::left << entry.name;
|
||||||
|
|
||||||
|
return std::move( oss ).str();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
std::filesystem::path where="./";
|
std::filesystem::path where="./";
|
||||||
|
|
||||||
|
std::vector< Entry > entries;
|
||||||
|
|
||||||
for( const auto &entry: std::filesystem::directory_iterator{ where } )
|
for( const auto &entry: std::filesystem::directory_iterator{ where } )
|
||||||
{
|
{
|
||||||
std::cout << entry.path().string() << " " << drwx( status( entry.path() ).permissions() ) << std::endl;
|
entries.emplace_back( entry.path().filename(), drwx( entry ), entry.is_directory(), is_exe( entry ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
for( const auto &entry: entries )
|
||||||
|
{
|
||||||
|
std::cout << format_entry( entry, widest ) << "[m ";
|
||||||
|
if( entry.is_dir )
|
||||||
|
{
|
||||||
|
std::cout << "[1;35;95m<dir>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << " ";
|
||||||
|
}
|
||||||
|
std::cout << "[m ";
|
||||||
|
std::cout << "[1;34;94m" << entry.perms << "[m";
|
||||||
|
std::cout << " [1;36;96m|[m" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user