Implement dynamic padding on size print
This commit is contained in:
parent
a514aa8b72
commit
20fa841a32
4 changed files with 44 additions and 38 deletions
|
|
@ -22,9 +22,11 @@ std::pair<double, const char*> convertN(const long int size, unsigned int n);
|
|||
|
||||
std::pair<double, const char*> 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#include "package_man.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <cstdio>
|
||||
#include <csignal>
|
||||
#include <cmath>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "print.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
#include <ztd/shell.hpp>
|
||||
|
||||
|
|
@ -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<length ; i++)
|
||||
sep += sepchar;
|
||||
std::cout << p_color(color) << sep << p_color(no_color) << std::endl;
|
||||
}
|
||||
|
||||
void print_update(repo_update& ru, ztd::color color, bool dlsize, bool nisize, bool nusize)
|
||||
{
|
||||
if(ru.packages.size() > 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 <<std::endl;
|
||||
}
|
||||
print_size(ru.net_size, !notitle, "Net Upgrade Size:", size_print_padding, color, 2, size_index, "\n", padsize);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -118,7 +116,7 @@ void print_size(long int size, bool printTitle, std::string title, int padding,
|
|||
if(sizepow == 0)
|
||||
{
|
||||
precision = 0;
|
||||
sizepad = 9;
|
||||
// sizepad = 9;
|
||||
}
|
||||
if(!printTitle)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue