diff --git a/Entry.h b/Entry.h index 9ef68ba..972103f 100644 --- a/Entry.h +++ b/Entry.h @@ -3,10 +3,16 @@ #include #include +namespace C +{ + constexpr int filePadding= 3; +} + struct Entry { std::string name; std::string perms; + std::size_t size; bool is_dir; bool is_exe; }; diff --git a/Makefile b/Makefile index 04acc88..539a044 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,32 @@ CXXFLAGS+= -std=c++23 -O3 +TARGET=cudir CPPFLAGS+= -I /usr/local/include 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: - rm -f cudir *.o + rm -f $(TARGET) $(OBJECTS) + rm -fR build_alepha libalepha.so + +__program: $(TARGET) diff --git a/cudir.cc b/cudir.cc index a65a3e6..5f5ef1f 100644 --- a/cudir.cc +++ b/cudir.cc @@ -12,7 +12,7 @@ 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(), 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; } ); @@ -20,6 +20,11 @@ getEntries( const std::filesystem::path where ) return entries; } +namespace C +{ + constexpr int dirwidth= 9; +} + int main() { @@ -30,7 +35,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 + 8 + 5 + 3 + 10 + 2; + const int rowWidth= widest + C::filePadding + C::dirwidth + 3 + 10 + 2; std::cout << ""; for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500"; @@ -44,13 +49,15 @@ main() std::cout << format_entry( entry, widest ) << " "; if( entry.is_dir ) { - std::cout << ""; + std::cout << ""; + std::cout << std::setw( C::dirwidth - 2 ) << std::right << "" << ' '; } else { - std::cout << " "; + //std::cout << " "; + std::cout << "\e[1;33;93m" << std::setw( C::dirwidth - 1 ) << entry.size; } - std::cout << " "; + std::cout << " "; std::cout << "" << entry.perms << ""; std::cout << " "; if( side == false ) diff --git a/format.cc b/format.cc index 1c17deb..e7dd35a 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 + 8 ) << std::left << entry.name; + oss << 'm' << std::setw( widest + C::filePadding ) << std::left << entry.name; return std::move( oss ).str(); }