diff --git a/include/print.hpp b/include/print.hpp index ea46dcb..5b2b1b2 100644 --- a/include/print.hpp +++ b/include/print.hpp @@ -23,7 +23,7 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize=false, bool nis void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool cisize, bool notitle); -void print_size(long int size, bool printTitle=false, std::string title="", int padding=0, ztd::color color=ztd::color::none, unsigned int precision=2, unsigned int sizepow=2, const char* line_end="\n"); +void print_size(long int size, bool printTitle=false, std::string title="", int padding=0, ztd::color color=ztd::color::none, unsigned int precision=2, unsigned int sizepow=2, const char* line_end="\n", int sizepad=-1); void print_listraw(repo_update& ru); diff --git a/include/repos.hpp b/include/repos.hpp index 7a3e7e7..38349c3 100644 --- a/include/repos.hpp +++ b/include/repos.hpp @@ -29,6 +29,10 @@ typedef struct repo_update long unsigned int new_install_size; long unsigned int current_install_size; long int net_size; + + long unsigned int max_download_size; + long unsigned int max_net_size; + } repo_update; extern repo_update repo, aur; diff --git a/src/fetch.cpp b/src/fetch.cpp index 5bd600c..f7bdb36 100644 --- a/src/fetch.cpp +++ b/src/fetch.cpp @@ -17,6 +17,8 @@ int fetch_update(repo_update* r, const std::string& name, const std::string& com r->name_max_length=0; r->vcur_max_length=0; r->vnew_max_length=0; + r->max_download_size=0; + r->max_net_size=0; std::pair cp = ztd::shp(command); if(cp.second != 0) return cp.second; @@ -103,6 +105,9 @@ int import_sizes(repo_update* ru, const char* ext_info_command, const char* loc_ ru->current_install_size = 0; for(auto pkg : ru->packages) { + ru->max_download_size=std::max(ru->max_download_size, pkg.download_size); + ru->max_net_size=std::max(ru->max_net_size, (long unsigned int) labs(pkg.net_size)); + ru->download_size += pkg.download_size; ru->new_install_size += pkg.new_install_size; ru->current_install_size += pkg.current_install_size; diff --git a/src/print.cpp b/src/print.cpp index e3aec3b..7ff5908 100644 --- a/src/print.cpp +++ b/src/print.cpp @@ -65,9 +65,9 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b int c_padsize = (opt_nocolor ? 0 : 20) ; printf(" %*s %*s -> %*s | ", -1*(ru.name_max_length + 2), it.name.c_str(), -1*(ru.vcur_max_length + c_padsize) , v1.c_str(), -1*(ru.vnew_max_length + c_padsize) , v2.c_str()); if(dlsize) - print_size(it.download_size, true, "", 0, ztd::color::none, 2, size_index, " : "); + print_size(it.download_size, true, "", 0, ztd::color::none, 2, size_index, " : ", (int) std::max(log10(ru.max_download_size) - 3*size_index + 0 , 0.0) + 5 ); if(nusize) - print_size(it.net_size, true, "", 0, ztd::color::none, 2, size_index, ""); + print_size(it.net_size, true, "", 0, ztd::color::none, 2, size_index, "", (int) std::max(log10(ru.max_net_size) - 3*size_index + 0 , 0.0) + 5 ); printf("\n"); } std::cout << p_color(color); @@ -94,14 +94,15 @@ void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nis } } -void print_size(long int size, bool printTitle, std::string title, int padding, ztd::color color, unsigned int precision, unsigned int sizepow, const char* line_end) +void print_size(long int size, bool printTitle, std::string title, int padding, ztd::color color, unsigned int precision, unsigned int sizepow, const char* line_end, int sizepad) { auto tpair = convertN(size, sizepow); if( printTitle ) { printf("%s%*s%s", p_color(color), padding, title.c_str(), p_color(no_color) ); } - unsigned int sizepad=precision+5; + if(sizepad<0) + sizepad=precision+5; if(sizepow == 0) { precision = 0;