Skip to content

Commit

Permalink
Merge pull request #397 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.83.1
  • Loading branch information
andyone authored Oct 23, 2023
2 parents 1f81cfa + 3b0c81a commit 4e892dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 12.83.1

* `[protip]` Disabling tips using environment variable (`PROTIP=0`)

### 12.83.0

* `[protip]` Added new package for showing usage tips
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.83.0"
const VERSION = "12.83.1"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
10 changes: 9 additions & 1 deletion protip/protip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package protip

import (
"math/rand"
"os"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil/panel"
Expand Down Expand Up @@ -40,6 +41,8 @@ var Options = panel.Options{panel.TOP_LINE, panel.BOTTOM_LINE}

// ////////////////////////////////////////////////////////////////////////////////// //

var disabled = os.Getenv("PROTIP") == "0"

var collection *Tips

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -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) {
Expand All @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions protip/protip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion usage/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *UsageSuite) TestUsage(c *C) {
c.Assert(info.GetOption("u:unknown").String(), Equals, "")
}

func (s *UsageSuite) TestDeattachedPrint(c *C) {
func (s *UsageSuite) TestDetachedPrint(c *C) {
cmd := &Command{Name: "test", Desc: "Test command", ColorTag: "{#99}"}
opt := &Option{Long: "test", Short: "T", Desc: "Test option", ColorTag: "{#99}"}

Expand Down

0 comments on commit 4e892dd

Please sign in to comment.