Skip to content

Commit

Permalink
[protip] Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 20, 2023
1 parent f055815 commit 583b4c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions protip/protip.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var Probability = 0.25
// ColorTag is default panel color tag
var ColorTag = "{#75}"

// Options contains default panel options
var Options = panel.Options{panel.TOP_LINE, panel.BOTTOM_LINE}

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

var collection *Tips
Expand Down Expand Up @@ -88,17 +91,14 @@ func Show(force bool) bool {
color := strutil.Q(tip.ColorTag, ColorTag)
color = strutil.B(fmtc.IsTag(color), color, "{#75}")

panel.Panel(
"❏ PROTIP", color, tip.Title, tip.Message,
panel.BOTTOM_LINE, panel.TOP_LINE, panel.INDENT_OUTER,
)
panel.Panel("❏ PROTIP", color, tip.Title, tip.Message, Options...)

return true
}

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

// searchInts improved searchInts version
// searchInts improved sort.SearchInts version
//
// Original: https://github.com/mroth/weightedrand
func searchInts(a []int, x int) int {
Expand Down
8 changes: 8 additions & 0 deletions protip/protip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ func (s *TipSuite) TestShow(c *C) {

c.Assert(Show(true), Equals, true)
}

func (s *TipSuite) TestIntSearch(c *C) {
k := []int{1, 3, 5}

c.Assert(searchInts(k, 1), Equals, 0)
c.Assert(searchInts(k, 3), Equals, 1)
c.Assert(searchInts(k, 5), Equals, 2)
}

0 comments on commit 583b4c6

Please sign in to comment.