diff options
author | Scrotadamus <scrotadamus@insiberia.net> | 2025-03-07 10:28:30 +0100 |
---|---|---|
committer | Scrotadamus <scrotadamus@insiberia.net> | 2025-03-07 10:28:30 +0100 |
commit | 7e25e46a37d39ba546889c7e5056257ba2364c2e (patch) | |
tree | 89a541a4a8fd88d6c4858c099f1593b7e33c6215 | |
parent | eb5f9e3485f47bcd1b527b4bd5c7864acea04096 (diff) |
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
-rw-r--r-- | cmd/root.go | 13 | ||||
-rw-r--r-- | 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 <glib.h> // #include <unistd.h> // #include <stdlib.h> +// +//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() +} |