Removed global maxcols - it is looked up on the fly now, so the progress bar is
resized. Also used ioctl in place of the COLUMNS env variable
This commit is contained in:
parent
3c7f616805
commit
5469177183
4 changed files with 25 additions and 7 deletions
|
@ -47,8 +47,6 @@ struct timeval initial_time;
|
||||||
/* pacman options */
|
/* pacman options */
|
||||||
extern config_t *config;
|
extern config_t *config;
|
||||||
|
|
||||||
extern unsigned int maxcols;
|
|
||||||
|
|
||||||
#define FILENAME_TRIM_LEN 21
|
#define FILENAME_TRIM_LEN 21
|
||||||
#define UPDATE_SPEED_SEC 0.1
|
#define UPDATE_SPEED_SEC 0.1
|
||||||
|
|
||||||
|
@ -58,6 +56,7 @@ void log_progress(const char *filename, int xfered, int total)
|
||||||
int i, hash;
|
int i, hash;
|
||||||
long chomp = 0;
|
long chomp = 0;
|
||||||
char *fname, *p;
|
char *fname, *p;
|
||||||
|
unsigned int maxcols = getcols();
|
||||||
unsigned int progresslen = maxcols - 57;
|
unsigned int progresslen = maxcols - 57;
|
||||||
int percent = ((float)xfered) / ((float)total) * 100;
|
int percent = ((float)xfered) / ((float)total) * 100;
|
||||||
struct timeval current_time;
|
struct timeval current_time;
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
extern int maxcols;
|
|
||||||
|
|
||||||
static list_t *list_last(list_t *list);
|
static list_t *list_last(list_t *list);
|
||||||
|
|
||||||
list_t *list_new()
|
list_t *list_new()
|
||||||
|
@ -127,6 +125,7 @@ void list_display(const char *title, list_t *list)
|
||||||
if(list) {
|
if(list) {
|
||||||
for(lp = list, cols = len; lp; lp = lp->next) {
|
for(lp = list, cols = len; lp; lp = lp->next) {
|
||||||
int s = strlen((char *)lp->data)+1;
|
int s = strlen((char *)lp->data)+1;
|
||||||
|
unsigned int maxcols = getcols();
|
||||||
if(s+cols >= maxcols) {
|
if(s+cols >= maxcols) {
|
||||||
int i;
|
int i;
|
||||||
cols = len;
|
cols = len;
|
||||||
|
@ -155,6 +154,7 @@ void pmlist_display(const char *title, pmlist_t *list)
|
||||||
if(list) {
|
if(list) {
|
||||||
for(lp = list, cols = len; lp; lp = alpm_list_next(lp)) {
|
for(lp = list, cols = len; lp; lp = alpm_list_next(lp)) {
|
||||||
int s = strlen(alpm_list_getdata(lp))+1;
|
int s = strlen(alpm_list_getdata(lp))+1;
|
||||||
|
unsigned int maxcols = getcols();
|
||||||
if(s+cols >= maxcols) {
|
if(s+cols >= maxcols) {
|
||||||
int i;
|
int i;
|
||||||
cols = len;
|
cols = len;
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#define LOG_STR_LEN 256
|
#define LOG_STR_LEN 256
|
||||||
|
|
||||||
extern config_t *config;
|
extern config_t *config;
|
||||||
extern unsigned int maxcols;
|
|
||||||
|
|
||||||
int prevpercent=0; /* for less progressbar output */
|
int prevpercent=0; /* for less progressbar output */
|
||||||
|
|
||||||
|
@ -154,6 +153,7 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2)
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_EVT_RETRIEVE_LOCAL:
|
case PM_TRANS_EVT_RETRIEVE_LOCAL:
|
||||||
MSG(NL, " %s [", (char*)data1);
|
MSG(NL, " %s [", (char*)data1);
|
||||||
|
unsigned int maxcols = getcols();
|
||||||
STRNCPY(out, (char*)data2, maxcols-42);
|
STRNCPY(out, (char*)data2, maxcols-42);
|
||||||
MSG(CL, "%s", out);
|
MSG(CL, "%s", out);
|
||||||
for(i = strlen(out); i < maxcols-43; i++) {
|
for(i = strlen(out); i < maxcols-43; i++) {
|
||||||
|
@ -287,6 +287,7 @@ void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howm
|
||||||
static int lasthash = 0, mouth = 0;
|
static int lasthash = 0, mouth = 0;
|
||||||
int i, hash;
|
int i, hash;
|
||||||
long chomp = 0;
|
long chomp = 0;
|
||||||
|
unsigned int maxcols = getcols();
|
||||||
unsigned int maxpkglen, progresslen = maxcols - 57;
|
unsigned int maxpkglen, progresslen = maxcols - 57;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -45,18 +48,33 @@
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
extern int maxcols;
|
|
||||||
extern config_t *config;
|
extern config_t *config;
|
||||||
extern int neednl;
|
extern int neednl;
|
||||||
|
|
||||||
/* gets the current screen column width */
|
/* gets the current screen column width */
|
||||||
int getcols()
|
int getcols()
|
||||||
{
|
{
|
||||||
|
#ifdef TIOCGSIZE
|
||||||
|
struct ttysize win;
|
||||||
|
if(ioctl(1, TIOCGSIZE, &win) == 0) {
|
||||||
|
return win.ts_cols;
|
||||||
|
}
|
||||||
|
#elif defined(TIOCGWINSZ)
|
||||||
|
struct winsize win;
|
||||||
|
if(ioctl(1, TIOCGWINSZ, &win) == 0) {
|
||||||
|
return win.ws_col;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* Original envvar way - prone to display issues
|
||||||
const char *cenv = getenv("COLUMNS");
|
const char *cenv = getenv("COLUMNS");
|
||||||
if(cenv != NULL) {
|
if(cenv != NULL) {
|
||||||
return atoi(cenv);
|
return atoi(cenv);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* does the same thing as 'mkdir -p' */
|
/* does the same thing as 'mkdir -p' */
|
||||||
|
@ -152,7 +170,7 @@ void indentprint(const char *str, int indent)
|
||||||
next = p + strlen(p);
|
next = p + strlen(p);
|
||||||
}
|
}
|
||||||
len = next - p;
|
len = next - p;
|
||||||
if(len > (maxcols-cidx-1)) {
|
if(len > (getcols()-cidx-1)) {
|
||||||
/* newline */
|
/* newline */
|
||||||
int i;
|
int i;
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue