Dynamic padding for size display
This commit is contained in:
parent
2dd6756409
commit
410789b479
4 changed files with 15 additions and 5 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<std::string, int> 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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue