This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=95cfaf475cfcf2c7efe754fdbb644cbd30527655 commit 95cfaf475cfcf2c7efe754fdbb644cbd30527655 Author: Guillem Jover <[email protected]> AuthorDate: Sat Jan 4 23:12:50 2025 +0100 libdpkg: Add support for hint printing This will make it possible to provide hints for the user so that they can perform some action prompted by diagnostics printed by dpkg tools. We already have some hints printed, but they do not use a unified interface and dedicated formatting and color. --- lib/dpkg/color.h | 1 + lib/dpkg/libdpkg.map | 2 ++ lib/dpkg/report.c | 28 ++++++++++++++++++++++++++++ lib/dpkg/report.h | 4 ++++ 4 files changed, 35 insertions(+) diff --git a/lib/dpkg/color.h b/lib/dpkg/color.h index 29f535950..9a8d0d219 100644 --- a/lib/dpkg/color.h +++ b/lib/dpkg/color.h @@ -56,6 +56,7 @@ DPKG_BEGIN_DECLS /* Current defaults. These might become configurable in the future. */ #define COLOR_PROG COLOR_BOLD +#define COLOR_HINT COLOR_BOLD_BLUE #define COLOR_INFO COLOR_GREEN #define COLOR_NOTICE COLOR_YELLOW #define COLOR_WARN COLOR_BOLD_YELLOW diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index 78f65636c..6185377ed 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -68,6 +68,8 @@ LIBDPKG_PRIVATE { warning; notice; info; + dpkg_set_hints_enable; + hint; debug_set_output; debug_set_mask; diff --git a/lib/dpkg/report.c b/lib/dpkg/report.c index f7763b362..3b67329cc 100644 --- a/lib/dpkg/report.c +++ b/lib/dpkg/report.c @@ -130,3 +130,31 @@ info(const char *fmt, ...) free(buf); } + +static bool hints_enabled = true; + +void +dpkg_set_hints_enable(bool enable) +{ + hints_enabled = enable; +} + +void +hint(const char *fmt, ...) +{ + char *buf = NULL; + va_list args; + + if (!hints_enabled) + return; + + va_start(args, fmt); + m_vasprintf(&buf, fmt, args); + va_end(args); + + printf("%s%s:%s %s%s:%s %s\n", + color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), + color_get(COLOR_HINT), _("hint"), color_reset(), buf); + + free(buf); +} diff --git a/lib/dpkg/report.h b/lib/dpkg/report.h index 862a8429a..fecc41ee0 100644 --- a/lib/dpkg/report.h +++ b/lib/dpkg/report.h @@ -22,6 +22,7 @@ #ifndef LIBDPKG_REPORT_H #define LIBDPKG_REPORT_H +#include <stdbool.h> #include <stdarg.h> #include <stdio.h> @@ -51,6 +52,9 @@ void notice(const char *fmt, ...) DPKG_ATTR_PRINTF(1); void info(const char *fmt, ...) DPKG_ATTR_PRINTF(1); +void dpkg_set_hints_enable(bool enable); +void hint(const char *fmt, ...) DPKG_ATTR_PRINTF(1); + /** @} */ DPKG_END_DECLS -- Dpkg.Org's dpkg

