Building support and size support.
This commit is contained in:
@@ -3,10 +3,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
namespace C
|
||||||
|
{
|
||||||
|
constexpr int filePadding= 3;
|
||||||
|
}
|
||||||
|
|
||||||
struct Entry
|
struct Entry
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string perms;
|
std::string perms;
|
||||||
|
std::size_t size;
|
||||||
bool is_dir;
|
bool is_dir;
|
||||||
bool is_exe;
|
bool is_exe;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,32 @@
|
|||||||
CXXFLAGS+= -std=c++23 -O3
|
CXXFLAGS+= -std=c++23 -O3
|
||||||
|
TARGET=cudir
|
||||||
|
|
||||||
CPPFLAGS+= -I /usr/local/include
|
CPPFLAGS+= -I /usr/local/include
|
||||||
CPPFLAGS+= -I.
|
CPPFLAGS+= -I.
|
||||||
|
|
||||||
LDFLAGS+= -Wl,-rpath,'$$ORIGIN/'
|
LD=$(CXX)
|
||||||
|
|
||||||
OBJECTS= helpers.o format.o cudir.o
|
LDFLAGS+= -Wl,-rpath,'$$ORIGIN/' -L .
|
||||||
|
LDLIBS+= -lalepha
|
||||||
|
|
||||||
all: cudir
|
OBJECTS= helpers.o format.o
|
||||||
|
OBJECTS+= $(TARGET).o
|
||||||
|
|
||||||
|
all: __program
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$(TARGET): $(OBJECTS) libalepha.so
|
||||||
|
$(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
|
||||||
|
|
||||||
|
libalepha.so:
|
||||||
|
mkdir -p build_alepha
|
||||||
|
cd build_alepha; cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../Alepha; cp ../Alepha/helpful-things/Makefile .; make
|
||||||
|
cp build_alepha/libalepha.so .
|
||||||
|
|
||||||
cudir: $(OBJECTS)
|
|
||||||
$(CXX) -o $@ $(OBJECTS)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f cudir *.o
|
rm -f $(TARGET) $(OBJECTS)
|
||||||
|
rm -fR build_alepha libalepha.so
|
||||||
|
|
||||||
|
__program: $(TARGET)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ getEntries( const std::filesystem::path where )
|
|||||||
|
|
||||||
for( const auto &entry: std::filesystem::directory_iterator{ where } )
|
for( const auto &entry: std::filesystem::directory_iterator{ where } )
|
||||||
{
|
{
|
||||||
entries.emplace_back( entry.path().filename(), drwx( entry ), entry.is_directory(), is_exe( entry ) );
|
entries.emplace_back( entry.path().filename(), drwx( entry ), entry.is_directory() ? 0 : file_size( entry.path() ), entry.is_directory(), is_exe( entry ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort( begin( entries ), end( entries ), []( const auto &lhs, const auto &rhs ) { return lhs.name < rhs.name; } );
|
std::sort( begin( entries ), end( entries ), []( const auto &lhs, const auto &rhs ) { return lhs.name < rhs.name; } );
|
||||||
@@ -20,6 +20,11 @@ getEntries( const std::filesystem::path where )
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace C
|
||||||
|
{
|
||||||
|
constexpr int dirwidth= 9;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@@ -30,7 +35,7 @@ main()
|
|||||||
const auto widest= std::max_element( begin( entries ), end( entries ),
|
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 auto &lhs, const auto &rhs ) { return lhs.name.size() < rhs.name.size(); } )->name.size();
|
||||||
|
|
||||||
const int rowWidth= widest + 8 + 5 + 3 + 10 + 2;
|
const int rowWidth= widest + C::filePadding + C::dirwidth + 3 + 10 + 2;
|
||||||
|
|
||||||
std::cout << "[1;36;96m";
|
std::cout << "[1;36;96m";
|
||||||
for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500";
|
for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500";
|
||||||
@@ -44,13 +49,15 @@ main()
|
|||||||
std::cout << format_entry( entry, widest ) << "[m ";
|
std::cout << format_entry( entry, widest ) << "[m ";
|
||||||
if( entry.is_dir )
|
if( entry.is_dir )
|
||||||
{
|
{
|
||||||
std::cout << "[1;35;95m<dir>";
|
std::cout << "[1;35;95m";
|
||||||
|
std::cout << std::setw( C::dirwidth - 2 ) << std::right << "<DIR>" << ' ';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << " ";
|
//std::cout << " ";
|
||||||
|
std::cout << "\e[1;33;93m" << std::setw( C::dirwidth - 1 ) << entry.size;
|
||||||
}
|
}
|
||||||
std::cout << "[m ";
|
std::cout << "[m ";
|
||||||
std::cout << "[1;34;94m" << entry.perms << "[m";
|
std::cout << "[1;34;94m" << entry.perms << "[m";
|
||||||
std::cout << " ";
|
std::cout << " ";
|
||||||
if( side == false )
|
if( side == false )
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ format_entry( const Entry &entry, const std::size_t widest )
|
|||||||
{
|
{
|
||||||
oss << "1;36;96";
|
oss << "1;36;96";
|
||||||
}
|
}
|
||||||
oss << 'm' << std::setw( widest + 8 ) << std::left << entry.name;
|
oss << 'm' << std::setw( widest + C::filePadding ) << std::left << entry.name;
|
||||||
|
|
||||||
return std::move( oss ).str();
|
return std::move( oss ).str();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user