new: implement package listing

This commit is contained in:
ngn 2024-07-18 20:10:06 +03:00
parent c92aa262a7
commit 43f93ae797
6 changed files with 81 additions and 39 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-18 19:12+0300\n" "POT-Creation-Date: 2024-07-18 20:09+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -47,28 +47,28 @@ msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
msgid "URL not specified for the pool: %s" msgid "URL not specified for the pool: %s"
msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s" msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s"
#: src/log.c:58 #: src/log.c:91
msgid "y" msgid "y"
msgstr "" msgstr ""
#: src/log.c:58 #: src/log.c:91
msgid "Y" msgid "Y"
msgstr "" msgstr ""
#: src/log.c:59 #: src/log.c:92
msgid "n" msgid "n"
msgstr "" msgstr ""
#: src/log.c:59 #: src/log.c:92
msgid "N" msgid "N"
msgstr "" msgstr ""
#: src/log.c:62 #: src/log.c:95
#, c-format #, c-format
msgid "%s [y/N] " msgid "%s [y/N] "
msgstr "" msgstr ""
#: src/log.c:82 #: src/log.c:115
msgid "Please answer with y/n" msgid "Please answer with y/n"
msgstr "" msgstr ""
@ -121,7 +121,7 @@ msgstr ""
msgid "Here is a list of available global options:" msgid "Here is a list of available global options:"
msgstr "" msgstr ""
#: src/main.c:121 src/main.c:122 src/cmd/install.c:22 src/cmd/install.c:23 #: src/main.c:121 src/main.c:122 src/cmd/install.c:23 src/cmd/install.c:24
#: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:17 src/cmd/remove.c:18 #: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:17 src/cmd/remove.c:18
#: src/cmd/update.c:23 #: src/cmd/update.c:23
#, c-format #, c-format
@ -133,82 +133,80 @@ msgid ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information" "Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
msgstr "" msgstr ""
#: src/cmd/install.c:21 #: src/cmd/install.c:22
msgid "Listing options for the install command:" msgid "Listing options for the install command:"
msgstr "" msgstr ""
#: src/cmd/install.c:28 src/cmd/update.c:28 #: src/cmd/install.c:29 src/cmd/update.c:28
msgid "There are no avaliable pools, have you synced yet?" msgid "There are no avaliable pools, have you synced yet?"
msgstr "" msgstr ""
#: src/cmd/install.c:48 src/cmd/remove.c:44 #: src/cmd/install.c:49 src/cmd/remove.c:44
#, fuzzy #, fuzzy
msgid "Failed to find " msgid "Failed to find "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:56 src/cmd/remove.c:42 #: src/cmd/install.c:57 src/cmd/remove.c:42
msgid "Package " msgid "Package "
msgstr "" msgstr ""
#: src/cmd/install.c:62 #: src/cmd/install.c:63
#, fuzzy #, fuzzy
msgid "Failed to resolve " msgid "Failed to resolve "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:68 #: src/cmd/install.c:69
msgid "Nothing to do (no packages to install)" msgid "Nothing to do (no packages to install)"
msgstr "" msgstr ""
#: src/cmd/install.c:77 src/cmd/remove.c:64 src/cmd/update.c:48 #: src/cmd/install.c:78 src/cmd/remove.c:64 src/cmd/update.c:48
#, c-format #, c-format
msgid "Following %d package will be " msgid "Following %d package will be "
msgstr "" msgstr ""
#: src/cmd/install.c:79 src/cmd/remove.c:66 src/cmd/update.c:50 #: src/cmd/install.c:80 src/cmd/remove.c:66 src/cmd/update.c:50
#, c-format #, c-format
msgid "Following %d packages will be " msgid "Following %d packages will be "
msgstr "" msgstr ""
#. list all the packages #: src/cmd/install.c:86 src/cmd/remove.c:73
#: src/cmd/install.c:83 src/cmd/remove.c:70
msgid "Total of " msgid "Total of "
msgstr "" msgstr ""
#. list all the packages #: src/cmd/install.c:87 src/cmd/remove.c:74 src/cmd/update.c:56
#: src/cmd/install.c:84 src/cmd/remove.c:71 src/cmd/update.c:54
msgid "Continue?" msgid "Continue?"
msgstr "" msgstr ""
#: src/cmd/install.c:85 src/cmd/remove.c:72 src/cmd/update.c:55 #: src/cmd/install.c:88 src/cmd/remove.c:75 src/cmd/update.c:57
msgid "Operation cancelled" msgid "Operation cancelled"
msgstr "" msgstr ""
#: src/cmd/install.c:91 src/cmd/update.c:65 #: src/cmd/install.c:94 src/cmd/update.c:67
#, c-format #, c-format
msgid "(%d/%d) Downloading " msgid "(%d/%d) Downloading "
msgstr "" msgstr ""
#: src/cmd/install.c:97 src/cmd/update.c:70 #: src/cmd/install.c:100 src/cmd/update.c:72
#, fuzzy #, fuzzy
msgid "Failed to download " msgid "Failed to download "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:106 src/cmd/update.c:83 #: src/cmd/install.c:109 src/cmd/update.c:85
#, c-format #, c-format
msgid "(%d/%d) Installing " msgid "(%d/%d) Installing "
msgstr "" msgstr ""
#: src/cmd/install.c:112 src/cmd/update.c:88 #: src/cmd/install.c:115 src/cmd/update.c:90
#, fuzzy #, fuzzy
msgid "Failed to install " msgid "Failed to install "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:118 #: src/cmd/install.c:121
#, c-format #, c-format
msgid "Installed %d package" msgid "Installed %d package"
msgstr "" msgstr ""
#: src/cmd/install.c:118 #: src/cmd/install.c:121
#, c-format #, c-format
msgid "Installed all of the %d packages" msgid "Installed all of the %d packages"
msgstr "" msgstr ""
@ -238,22 +236,22 @@ msgstr "Havuzları sekronize etmek başarısız oldu: %s"
msgid "Nothing to do (no packages to remove)" msgid "Nothing to do (no packages to remove)"
msgstr "" msgstr ""
#: src/cmd/remove.c:79 src/cmd/update.c:74 #: src/cmd/remove.c:82 src/cmd/update.c:76
#, c-format #, c-format
msgid "(%d/%d) Removing " msgid "(%d/%d) Removing "
msgstr "" msgstr ""
#: src/cmd/remove.c:85 src/cmd/update.c:79 #: src/cmd/remove.c:88 src/cmd/update.c:81
#, fuzzy #, fuzzy
msgid "Failed to remove " msgid "Failed to remove "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/remove.c:91 #: src/cmd/remove.c:94
#, c-format #, c-format
msgid "Removed %d package" msgid "Removed %d package"
msgstr "" msgstr ""
#: src/cmd/remove.c:91 #: src/cmd/remove.c:94
#, c-format #, c-format
msgid "Removed all of the %d packages" msgid "Removed all of the %d packages"
msgstr "" msgstr ""
@ -295,7 +293,7 @@ msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
msgid "All packages are up-to-date" msgid "All packages are up-to-date"
msgstr "" msgstr ""
#: src/cmd/update.c:61 #: src/cmd/update.c:63
#, fuzzy #, fuzzy
msgid "Failed to update " msgid "Failed to update "
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"

View File

@ -1,4 +1,5 @@
#include <libmp/all.h> #include <libmp/all.h>
#include <libmp/ctx.h>
#include <stdio.h> #include <stdio.h>
#include "../util.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){ if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
error(_("There are no avaliable pools, have you synced yet?")); error(_("There are no avaliable pools, have you synced yet?"));
goto end; return false;
} }
lm_ctx_resolve_list_t *list = NULL; lm_ctx_resolve_list_t *list = NULL;
ssize_t current = 0, size = 0, save = 0;
bool ret = false, r = false; bool ret = false, r = false;
ssize_t current = 0, size = 0;
char ssize[LONGSTR_MAX+3]; char ssize[LONGSTR_MAX+3];
lm_pkg_t *pkg = NULL; lm_pkg_t *pkg = NULL;
char *name = NULL; char *name = NULL;
@ -78,7 +79,9 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
else else
info(_("Following %d packages will be "FG_BOLD"INSTALLED:"FG_RESET), list->count); 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); info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be used"), ssize);
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){ if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){

View File

@ -19,7 +19,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
return true; 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; bool ret = false, r = false;
char ssize[LONGSTR_MAX+3]; char ssize[LONGSTR_MAX+3];
lm_pkg_t *pkgs = NULL; 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); info(_("Following %d packages will be "FG_BOLD"REMOVED:"FG_RESET), count);
// list all the packages // 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); info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be freed"), ssize);
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){ if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){

View File

@ -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){ if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
error(_("There are no avaliable pools, have you synced yet?")); error(_("There are no avaliable pools, have you synced yet?"));
goto end; return false;
} }
lm_pkg_t *old = NULL, *new = NULL; lm_pkg_t *old = NULL, *new = NULL;
lm_ctx_update_list_t *list = NULL; lm_ctx_update_list_t *list = NULL;
ssize_t current = 0, save = 0;
bool ret = false, r = false; bool ret = false, r = false;
ssize_t current = 0;
if((list = lm_ctx_update_list(ctx)) == NULL){ if((list = lm_ctx_update_list(ctx)) == NULL){
error(_("Failed to get the package update list: %s"), lm_strerror()); 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 else
info(_("Following %d packages will be "FG_BOLD"UPDATED:"FG_RESET), list->count); 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?"))){ if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled")); error(_("Operation cancelled"));

View File

@ -1,3 +1,4 @@
#include <libmp/all.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -10,6 +11,38 @@
#include "intl.h" #include "intl.h"
#include "log.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, ...) { void info(const char *msg, ...) {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <libmp/all.h>
#include <stdbool.h> #include <stdbool.h>
#include <sys/types.h>
#define FG_RED "\x1b[31m" #define FG_RED "\x1b[31m"
#define FG_BOLD "\x1b[1m" #define FG_BOLD "\x1b[1m"
@ -10,6 +12,7 @@
#define FG_MAGENTA "\x1b[35m" #define FG_MAGENTA "\x1b[35m"
#define FG_RESET "\x1b[0m" #define FG_RESET "\x1b[0m"
void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max);
void info(const char *msg, ...); void info(const char *msg, ...);
void error(const char *msg, ...); void error(const char *msg, ...);
void success(const char *msg, ...); void success(const char *msg, ...);