diff --git a/CHANGELOG.md b/CHANGELOG.md index 322c6151..6ee19188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 12.83.1 + +* `[protip]` Disabling tips using environment vairable (`PROTIP=0`) + ### 12.83.0 * `[protip]` Added new package for showing usage tips diff --git a/ek.go b/ek.go index e2617cc3..4b7de9f7 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.83.0" +const VERSION = "12.83.1" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/protip/protip.go b/protip/protip.go index 8e1c8f8d..dcb3bf2d 100644 --- a/protip/protip.go +++ b/protip/protip.go @@ -3,6 +3,7 @@ package protip import ( "math/rand" + "os" "github.com/essentialkaos/ek/v12/fmtc" "github.com/essentialkaos/ek/v12/fmtutil/panel" @@ -40,6 +41,8 @@ var Options = panel.Options{panel.TOP_LINE, panel.BOTTOM_LINE} // ////////////////////////////////////////////////////////////////////////////////// // +var disabled = os.Getenv("PROTIP") == "0" + var collection *Tips // ////////////////////////////////////////////////////////////////////////////////// // @@ -50,6 +53,11 @@ func Add(tips ...*Tip) { collection = &Tips{} } + // Don't add if tips are disabled by env vars + if disabled { + return + } + for _, tip := range tips { if tip == nil || tip.Title == "" || tip.Message == "" || !fmtc.IsTag(tip.ColorTag) { @@ -66,7 +74,7 @@ func Add(tips ...*Tip) { // Show shows random tip if required func Show(force bool) bool { - if collection == nil || len(collection.data) == 0 { + if collection == nil || len(collection.data) == 0 || disabled { return false } diff --git a/protip/protip_test.go b/protip/protip_test.go index 61ba6c05..0fbd3aab 100644 --- a/protip/protip_test.go +++ b/protip/protip_test.go @@ -42,6 +42,14 @@ func (s *TipSuite) TestAdd(c *C) { c.Assert(collection.data, HasLen, 0) tip.Message = "Test message" + + disabled = true + + Add(tip) + c.Assert(collection.data, HasLen, 0) + + disabled = false + Add(tip) c.Assert(collection.data, HasLen, 1) c.Assert(collection.data[0].Weight, Equals, 0.5)