From patchwork Tue Mar 1 05:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gustavsson X-Patchwork-Id: 2030 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.27) for (single-drop); Tue, 01 Mar 2022 05:02:34 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id 0F8OF+qoHWKJqgEAK+/4rw (envelope-from ) for ; Tue, 01 Mar 2022 05:02:34 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id E66ADD8467B; Tue, 1 Mar 2022 05:02:32 +0000 (UTC) Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id BFA14D62C72; Tue, 1 Mar 2022 05:02:32 +0000 (UTC) X-Original-To: pacman-dev@lists.archlinux.org Delivered-To: pacman-dev@lists.archlinux.org Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lists.archlinux.org (Postfix) with ESMTPS id 20DA5D62C56 for ; Tue, 1 Mar 2022 05:02:31 +0000 (UTC) Received: by mail-lj1-x230.google.com with SMTP id u11so20303265lju.4 for ; Mon, 28 Feb 2022 21:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lFDvRLk10s1kaZcb7A/Wn6bTA5Fwb8LdCOzJj64jjqw=; b=l0fisPzu9f/QMCNlE1vt70iUkjl+aZpRDyj12H7OtGAJJSBkco34SgXARKofdXtHmh O0Zmfp4TGDQA5fK+LMhpMu0Jf60YvEagUZ1Q+QJ0RLoYDFBgN4lpx7VWDOg9E5OyyP7N ffD6WLt2n1a079fXyDYbmnigPoAdEEWPon0sx4AYRnAPqih+y40+IBIMROtHiNnnDc1J QqTzB6NBBMWxpkNtIiu6C6GmRuoi8T9ecEDxYvx6O94wkm4pHRcMdfw/yJHzCuSy5zLh yTZgGDMsHcOE7RDjd4kPjHjxPLhYeyQG1vurL1pGYZG8mkR1q84mkSDjcGMIU04oCZcZ KnBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lFDvRLk10s1kaZcb7A/Wn6bTA5Fwb8LdCOzJj64jjqw=; b=O07VqoBKXkXursZZAYDWGiOVtscGM8NtWdC2ueMuyQmtJgwyMNvN5H9Zra7G/Q7Cm8 403hhjVYK3hAVR26hp5rl/yL3JGkL+aohGzG/tT8ZVUG9d42Wctq9LdEEUqGXwMBYzBR USfwSpFNDnumDPnEUHLjQe5GAEAH9cT5CLWA1Z78ql8fC4XBGMZEX3bSzUpIlNBA5ED4 +5rcVfNBr+bsTPxdyanzQ36IgbVu8Lny8ZEVNYfU52PpqWZ3Rj3oHGJMO/SSrObOn868 q7k5X+oxbyrE//iaSMQl6wWHq1V1Q7x1zX4+mbhGXKALAPIcHDI/agkD0Ms5sv9URue0 PaLA== X-Gm-Message-State: AOAM531prQzZ0QQUSTemIp9W7tY2cr+OBSLoLsq14pdMZZSlqNBX0weE lrZb+14JYvzNoukSC06B2yP/T6IvWemZtg== X-Google-Smtp-Source: ABdhPJxLQyyO7VsvBpZ8ZV9D4AofSvDpUQyMtp2uqHBrdeY4vpYGQ+uWHe+F9hw6eGe6wfkcVeappA== X-Received: by 2002:a2e:9907:0:b0:244:c04a:dd49 with SMTP id v7-20020a2e9907000000b00244c04add49mr16720585lji.327.1646110950145; Mon, 28 Feb 2022 21:02:30 -0800 (PST) Received: from localhost.localdomain (83-233-18-159.cust.bredband2.com. [83.233.18.159]) by smtp.gmail.com with ESMTPSA id s6-20020ac25fa6000000b0044313e88020sm1288441lfe.202.2022.02.28.21.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 21:02:29 -0800 (PST) From: David Gustavsson To: pacman-dev@lists.archlinux.org Cc: David Gustavsson Subject: [PATCH 1/2] Diff color version strings Date: Tue, 1 Mar 2022 06:02:11 +0100 Message-Id: <20220301050212.37576-1-david.e.gustavsson@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-dev-bounces@lists.archlinux.org Sender: "pacman-dev" X-Rspamd-Queue-Id: E66ADD8467B Authentication-Results: mail.archlinux.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=l0fisPzu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Spamd-Result: default: False [-1.41 / 15.00]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_MISSING_CHARSET(0.50)[]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; RCVD_IN_DNSWL_MED(-0.20)[2a01:4f9:c010:9eb4::1:from]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1:c]; MAILLIST(-0.20)[mailman]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TAGGED_RCPT(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; RCVD_COUNT_FIVE(0.00)[5]; NEURAL_HAM(-0.00)[-1.000]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::230:received]; ARC_NA(0.00)[]; TAGGED_FROM(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; FROM_NEQ_ENVFROM(0.00)[davidegustavsson@gmail.com,pacman-dev-bounces@lists.archlinux.org]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com]; MID_RHS_MATCH_FROM(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org In package table, with VerbosePkgLists and Color, color the part of package version strings that changes. Signed-off-by: David Gustavsson --- src/pacman/conf.c | 4 ++++ src/pacman/conf.h | 2 ++ src/pacman/util.c | 35 +++++++++++++++++++++++++++++++---- src/pacman/util.h | 1 + 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index f9edf75b..d5c598b9 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -80,6 +80,8 @@ void enable_colors(int colors) colstr->err = BOLDRED; colstr->faint = GREY46; colstr->nocolor = NOCOLOR; + colstr->diffrem = RED; + colstr->diffadd = GREEN; } else { colstr->colon = ":: "; colstr->title = ""; @@ -91,6 +93,8 @@ void enable_colors(int colors) colstr->err = ""; colstr->faint = ""; colstr->nocolor = ""; + colstr->diffrem = ""; + colstr->diffadd = ""; } } diff --git a/src/pacman/conf.h b/src/pacman/conf.h index f7916ca9..782b5758 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -33,6 +33,8 @@ typedef struct __colstr_t { const char *err; const char *faint; const char *nocolor; + const char *diffrem; + const char *diffadd; } colstr_t; typedef struct __config_repo_t { diff --git a/src/pacman/util.c b/src/pacman/util.c index 53833d6f..10d7c573 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -840,8 +840,10 @@ static alpm_list_t *create_verbose_row(pm_target_t *target) { char *str; off_t size = 0; + size_t i = 0; double human_size; const char *label; + const char *version; alpm_list_t *ret = NULL; /* a row consists of the package name, */ @@ -858,12 +860,28 @@ static alpm_list_t *create_verbose_row(pm_target_t *target) add_table_cell(&ret, str, CELL_NORMAL | CELL_FREE); /* old and new versions */ - pm_asprintf(&str, "%s", - target->remove != NULL ? alpm_pkg_get_version(target->remove) : ""); + version = alpm_pkg_get_version(target->remove); + char old_version[strlen(version) + strlen(config->colstr.diffrem) + strlen(config->colstr.nocolor) + 1]; + memcpy(old_version, (char *)version, strlen(version) + 1); + version = alpm_pkg_get_version(target->install); + char new_version[strlen(version) + strlen(config->colstr.diffadd) + strlen(config->colstr.nocolor) + 1]; + memcpy(new_version, (char *)version, strlen(version) + 1); + + i = 0; + while (old_version[i] != '\0' && new_version[i] != '\0' && old_version[i] == new_version[i]) { + i++; + } + insertstring(old_version, config->colstr.diffrem, i); + insertstring(new_version, config->colstr.diffadd, i); + snprintf(old_version + i + strlen(old_version + i), + strlen(config->colstr.nocolor) + 1, "%s", config->colstr.nocolor); + snprintf(new_version + i + strlen(new_version + i), + strlen(config->colstr.nocolor) + 1, "%s", config->colstr.nocolor); + + pm_asprintf(&str, "%s", old_version); add_table_cell(&ret, str, CELL_NORMAL | CELL_FREE); - pm_asprintf(&str, "%s", - target->install != NULL ? alpm_pkg_get_version(target->install) : ""); + pm_asprintf(&str, "%s", new_version); add_table_cell(&ret, str, CELL_NORMAL | CELL_FREE); /* and size */ @@ -1859,3 +1877,12 @@ void console_erase_line(void) { printf("\x1B[K"); } + +/* inserts string insert into string at index i, modifying string */ +void insertstring(char *string, const char *insert, size_t i) +{ + char temp[strlen(string) - i + 1]; + memcpy(temp, string + i, strlen(string + i) + 1); + memcpy(string + i, insert, strlen(insert) + 1); + memcpy(string + i + strlen(insert), temp, strlen(temp) + 1); +} diff --git a/src/pacman/util.h b/src/pacman/util.h index 52e79915..003961eb 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -88,6 +88,7 @@ void console_cursor_move_down(unsigned int lines); void console_cursor_move_end(void); /* Erases line from the current cursor position till the end of the line */ void console_erase_line(void); +void insertstring(char *string, const char *insert, size_t i); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3)));