new: implement package listing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <libmp/all.h>
|
||||
#include <libmp/ctx.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../util.h"
|
||||
@@ -26,12 +27,12 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
|
||||
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
|
||||
error(_("There are no avaliable pools, have you synced yet?"));
|
||||
goto end;
|
||||
return false;
|
||||
}
|
||||
|
||||
lm_ctx_resolve_list_t *list = NULL;
|
||||
ssize_t current = 0, size = 0, save = 0;
|
||||
bool ret = false, r = false;
|
||||
ssize_t current = 0, size = 0;
|
||||
char ssize[LONGSTR_MAX+3];
|
||||
lm_pkg_t *pkg = NULL;
|
||||
char *name = NULL;
|
||||
@@ -78,7 +79,9 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
else
|
||||
info(_("Following %d packages will be "FG_BOLD"INSTALLED:"FG_RESET), list->count);
|
||||
|
||||
// list all the packages
|
||||
while((pkg = lm_ctx_resolve_next(list)) != NULL)
|
||||
package_list(pkg, &save, 0);
|
||||
printf("\n");
|
||||
|
||||
info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be used"), ssize);
|
||||
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
|
||||
|
@@ -19,7 +19,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
return true;
|
||||
}
|
||||
|
||||
ssize_t count = 0, size = 0, current = 0;
|
||||
ssize_t count = 0, size = 0, current = 0, save = 0;
|
||||
bool ret = false, r = false;
|
||||
char ssize[LONGSTR_MAX+3];
|
||||
lm_pkg_t *pkgs = NULL;
|
||||
@@ -66,6 +66,9 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
info(_("Following %d packages will be "FG_BOLD"REMOVED:"FG_RESET), count);
|
||||
|
||||
// list all the packages
|
||||
for(int i = 0; i < count; i++)
|
||||
package_list(&pkgs[i], &save, 0);
|
||||
printf("\n");
|
||||
|
||||
info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be freed"), ssize);
|
||||
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
|
||||
|
@@ -26,13 +26,13 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
|
||||
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
|
||||
error(_("There are no avaliable pools, have you synced yet?"));
|
||||
goto end;
|
||||
return false;
|
||||
}
|
||||
|
||||
lm_pkg_t *old = NULL, *new = NULL;
|
||||
lm_ctx_update_list_t *list = NULL;
|
||||
ssize_t current = 0, save = 0;
|
||||
bool ret = false, r = false;
|
||||
ssize_t current = 0;
|
||||
|
||||
if((list = lm_ctx_update_list(ctx)) == NULL){
|
||||
error(_("Failed to get the package update list: %s"), lm_strerror());
|
||||
@@ -49,7 +49,9 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
else
|
||||
info(_("Following %d packages will be "FG_BOLD"UPDATED:"FG_RESET), list->count);
|
||||
|
||||
// list all the packages
|
||||
while((old = lm_ctx_update_list_next(list)) != NULL)
|
||||
package_list(old, &save, 0);
|
||||
printf("\n");
|
||||
|
||||
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
|
||||
error(_("Operation cancelled"));
|
||||
|
33
src/log.c
33
src/log.c
@@ -1,3 +1,4 @@
|
||||
#include <libmp/all.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -10,6 +11,38 @@
|
||||
#include "intl.h"
|
||||
#include "log.h"
|
||||
|
||||
void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max) {
|
||||
ssize_t cur = 0;
|
||||
|
||||
if (*save == 0) {
|
||||
printf(" ");
|
||||
*save = 4;
|
||||
}
|
||||
|
||||
if (max == 0) {
|
||||
struct winsize barwin = {0};
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &barwin);
|
||||
max = barwin.ws_col;
|
||||
}
|
||||
|
||||
cur += strlen(pkg->name);
|
||||
cur += strlen(pkg->version);
|
||||
*save += cur += 3;
|
||||
|
||||
if (cur > max)
|
||||
goto end;
|
||||
|
||||
if (*save > max) {
|
||||
printf("\n");
|
||||
*save = 0;
|
||||
return package_list(pkg, save, max);
|
||||
}
|
||||
|
||||
end:
|
||||
printf(FG_BOLD "%s " FG_BLUE "%s" FG_RESET, pkg->name, pkg->version);
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
void info(const char *msg, ...) {
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <libmp/all.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define FG_RED "\x1b[31m"
|
||||
#define FG_BOLD "\x1b[1m"
|
||||
@@ -10,6 +12,7 @@
|
||||
#define FG_MAGENTA "\x1b[35m"
|
||||
#define FG_RESET "\x1b[0m"
|
||||
|
||||
void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max);
|
||||
void info(const char *msg, ...);
|
||||
void error(const char *msg, ...);
|
||||
void success(const char *msg, ...);
|
||||
|
Reference in New Issue
Block a user