Skip to content

Commit

Permalink
added ChangeBubbleColor method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kura-lab committed Oct 14, 2019
1 parent e06d15d commit b5a83ea
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,20 @@ func main() {
}
}
```

# Settings

```
numbers := 220
// set numbers of a column
bw := NewBubbleWrap(numbers).SetColumn(60)
// change bubble's shapes
bw := NewBubbleWrap(numbers).ChangeBubbleShape("o", "x")
// change bubble's colors
before := color.New(color.FgCyan)
after := color.New(color.FgRed)
bw := NewBubbleWrap(numbers).ChangeBubbleColor(before, after)
```
34 changes: 26 additions & 8 deletions bw.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import (
"fmt"
"math"
"strconv"

"github.com/fatih/color"
)

type BubbleWrap struct {
Numbers int
Column int
Bubbles []bool
before string
after string
Numbers int
Column int
Bubbles []bool
before string
after string
beforeColor color.Color
afterColor color.Color
}

func NewBubbleWrap(numbers int) *BubbleWrap {
Expand Down Expand Up @@ -44,6 +48,12 @@ func (bw *BubbleWrap) ChangeBubbleShape(before string, after string) *BubbleWrap
return bw
}

func (bw *BubbleWrap) ChangeBubbleColor(before *color.Color, after *color.Color) *BubbleWrap {
bw.beforeColor = *before
bw.afterColor = *after
return bw
}

func (bw *BubbleWrap) Pop(i int) {
bw.Bubbles[i] = true
}
Expand All @@ -53,10 +63,18 @@ func (bw *BubbleWrap) Display() {
var c, comp int
for _, v := range bw.Bubbles {
if v {
fmt.Printf("%v", bw.before)
if &bw.beforeColor != nil {
bw.beforeColor.Printf("%v", bw.before)
} else {
fmt.Printf("%v", bw.before)
}
comp++
} else {
fmt.Printf("%v", bw.after)
if &bw.afterColor != nil {
bw.afterColor.Printf("%v", bw.after)
} else {
fmt.Printf("%v", bw.after)
}
}

c++
Expand Down Expand Up @@ -113,5 +131,5 @@ func (bw *BubbleWrap) printCopyRight() {
}

func (bw *BubbleWrap) version() string {
return "1.0.4"
return "1.0.5"
}
17 changes: 17 additions & 0 deletions bw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"math/rand"
"testing"
"time"

"github.com/fatih/color"
)

func TestDemo(t *testing.T) {
Expand Down Expand Up @@ -55,3 +57,18 @@ func TestChangeBubbleShape(t *testing.T) {
bw.Redisplay()
}
}

func TestChangeBubbleColor(t *testing.T) {
numbers := 220

before := color.New(color.FgCyan)
after := color.New(color.FgRed)
bw := NewBubbleWrap(numbers).ChangeBubbleColor(before, after)
bw.Display()

for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
}
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module github.com/kura-lab/bw

go 1.12

require (
github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

0 comments on commit b5a83ea

Please sign in to comment.