diff --git a/include/print.hpp b/include/print.hpp index d6a7af3..39d5583 100644 --- a/include/print.hpp +++ b/include/print.hpp @@ -22,9 +22,11 @@ std::pair convertN(const long int size, unsigned int n); std::pair convertHReadable(const long int size); +void print_separator(uint32_t length, ztd::color color, char sepchar='='); + void print_update(repo_update& ru, ztd::color color, bool dlsize=false, bool nisize=false, bool nusize=false); -void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool cisize, bool notitle); +void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool cisize, bool notitle, uint32_t padsize); 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); diff --git a/src/main.cpp b/src/main.cpp index 52d8bba..3c8e813 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/package_man.cpp b/src/package_man.cpp index 5dcd201..3a67e19 100644 --- a/src/package_man.cpp +++ b/src/package_man.cpp @@ -1,7 +1,10 @@ #include "package_man.hpp" -#include -#include +#include +#include +#include + +#include #include "fetch.hpp" #include "print.hpp" @@ -20,17 +23,35 @@ bool exec_find(const std::string& name) return which != ""; } +uint32_t req_pad_size(repo_update& ru) +{ + int pd, pi, pn; + pd=std::max(0.0, log10(ru.download_size) - 3*size_index); + pi=std::max(0.0, log10(ru.new_install_size) - 3*size_index); + pn=std::max(0.0, log10(ru.net_size) - 3*size_index + (ru.net_size<0?1:0)); + return std::ceil(std::max(std::max(pd, pi), pn)) + (size_index>0?7:2); +} + void repo_print_process(repo_update& ru, ztd::color cl, bool print_size=true) { //only if there are packages - if(ru.packages.size() > 0) + if(opt_plistraw) + print_listraw(repo); + else if(ru.packages.size() > 0) { //list if( opt_plist ) print_update(ru, cl, print_size && opt_pdownload, print_size && opt_pinstall, print_size && opt_pnet); + // raw list + + uint32_t padsize=req_pad_size(ru); + if( opt_plist && print_size ) + print_separator(padsize+22, cl); + + padsize -= size_index>0 ? 3 : 1; //sizes if( print_size ) - print_update_sizes(ru, cl, opt_pdownload, opt_pinstall, opt_pnet, opt_notitles); + print_update_sizes(ru, cl, opt_pdownload, opt_pinstall, opt_pnet, opt_notitles, padsize); } } @@ -78,11 +99,6 @@ int pacman_process(bool yay) repo_print_process(repo, ztd::color::b_white); - if(opt_plistraw) - { - print_listraw(repo); - } - if(opt_update) { signal(SIGINT, SIG_IGN); @@ -101,11 +117,6 @@ int pacman_process(bool yay) { repo_print_process(aur, ztd::color::b_cyan, false); - if(opt_plistraw) - { - print_listraw(aur); - } - if(opt_update) { signal(SIGINT, SIG_IGN); @@ -176,11 +187,6 @@ int apt_process() repo_print_process(repo, ztd::color::b_white); - if(opt_plistraw) - { - print_listraw(repo); - } - if(opt_update) { signal(SIGINT, SIG_IGN); diff --git a/src/print.cpp b/src/print.cpp index 3683389..859e4ab 100644 --- a/src/print.cpp +++ b/src/print.cpp @@ -1,7 +1,7 @@ #include "print.hpp" #include -#include +#include #include @@ -54,6 +54,14 @@ static const char* p_color(const ztd::color c) return ""; } +void print_separator(uint32_t length, ztd::color color, char sepchar) +{ + std::string sep; + for(uint32_t i=0 ; i 0) @@ -82,28 +90,18 @@ void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, b 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); - std::cout << "================================"; - std::cout << p_color(no_color); - std::cout << std::endl; } } -void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize, bool notitle) +void print_update_sizes(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize, bool notitle, uint32_t padsize) { + bool separator = !notitle && (dlsize || nisize || nusize) ; if(dlsize) - print_size(ru.download_size, !notitle, "Total Download Size:", size_print_padding, color, 2, size_index); + print_size(ru.download_size, !notitle, "Total Download Size:", size_print_padding, color, 2, size_index, "\n", padsize); if(nisize) - print_size(ru.new_install_size, !notitle, "Total Install Size:", size_print_padding, color, 2, size_index); + print_size(ru.new_install_size, !notitle, "Total Install Size:", size_print_padding, color, 2, size_index, "\n", padsize); if(nusize) - print_size(ru.net_size, !notitle, "Net Upgrade Size:", size_print_padding, color, 2, size_index); - if(!notitle && (dlsize || nisize || nusize)) - { - std::cout << p_color(color); - std::cout << "================================"; - std::cout << p_color(no_color); - std::cout <