From 7e25e46a37d39ba546889c7e5056257ba2364c2e Mon Sep 17 00:00:00 2001 From: Scrotadamus Date: Fri, 7 Mar 2025 10:28:30 +0100 Subject: disable poppler warnings by default user can enable poppler warnings by doing using the `--warnigs` flag Changes to be committed: modified: root.go modified: ../go-poppler/utils.go --- cmd/root.go | 13 +++++++++++++ go-poppler/utils.go | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 321253c..e93a4e7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,14 +7,26 @@ import ( "os" "github.com/scrotadamus/ghligh/cmd/tag" + "github.com/scrotadamus/ghligh/go-poppler" "github.com/spf13/cobra" ) +var warnings bool + var rootCmd = &cobra.Command{ Use: "ghligh", Short: "pdf highlights swiss knife", Long: `ghligh can be used to manipulate pdf files in various ways.`, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + + if !warnings { + poppler.DisablePopplerWarnings() + } + + return nil + }, + Run: func(cmd *cobra.Command, args []string) { cmd.Help() return @@ -33,4 +45,5 @@ func Execute() { func init() { //rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.AddCommand(tag.TagCmd) + rootCmd.PersistentFlags().BoolVar(&warnings, "warnings", false, "show poppler warnings") } diff --git a/go-poppler/utils.go b/go-poppler/utils.go index 4bda53a..d5b6170 100644 --- a/go-poppler/utils.go +++ b/go-poppler/utils.go @@ -5,6 +5,13 @@ package poppler // #include // #include // #include +// +//static void ignorePopplerWarnings(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) { +//} +// +//static void disablePopplerWarnings() { +// g_log_set_handler("Poppler", G_LOG_LEVEL_WARNING, ignorePopplerWarnings, NULL); +//} import "C" import "unsafe" @@ -14,7 +21,7 @@ func toString(in *C.gchar) string { } func toBool(in C.gboolean) bool { - return int(in) > 0 + return int(in) > 0 } /* convert a Quad struct to a GArray */ @@ -41,7 +48,7 @@ func quadsToGArray(quads []Quad) *C.GArray { }, } - C.g_array_append_vals(garray, C.gconstpointer(&item),1) + C.g_array_append_vals(garray, C.gconstpointer(&item), 1) } return garray @@ -66,7 +73,7 @@ func gArrayToQuads(q *C.GArray) []Quad { return quads } -func rectangleToPopplerRectangle (r Rectangle) C.PopplerRectangle { +func rectangleToPopplerRectangle(r Rectangle) C.PopplerRectangle { var pRect C.PopplerRectangle pRect.x1 = C.double(r.X1) @@ -83,3 +90,7 @@ func rectEq(r1 Rectangle, r2 Rectangle) bool { r1.Y1 == r2.Y1 && r1.Y2 == r2.Y2 } + +func DisablePopplerWarnings() { + C.disablePopplerWarnings() +} -- cgit v1.2.3