Skip to content

Commit

Permalink
Release v0.15.0. (#298)
Browse files Browse the repository at this point in the history
### Changed

- Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.2.0.
- Bump github.com/mattn/go-runewidth from 0.0.9 to 0.0.10.
- Allowing CI to modify go.mod and go.sum when necessary.
- Executed `go mod tidy`.

### Added

- TitleColor and TitleFocusedColor options for border title which enables the 
  setting of separate colors for border and title on a container.
  • Loading branch information
mum4k committed Mar 6, 2021
1 parent 74d9de2 commit 8a5b62c
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 29 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ before_install:
script:
- go get -t ./...
- go get -u golang.org/x/lint/golint
- go test ./...
- CGO_ENABLED=1 go test -race ./...
# Temporarily set -mod=mod to allow modification of go.mod and go.sum.
# This seems to be caused by a sum missing in the tcell dependency and
# should be removed when no longer needed.
- go test -mod=mod ./...
- CGO_ENABLED=1 go test -mod=mod -race ./...
- go vet ./...
- diff -u <(echo -n) <(gofmt -d -s .)
- diff -u <(echo -n) <(./internal/scripts/autogen_licences.sh .)
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.15.0] - 06-Mar-2021

### Changed

- Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.2.0.
- Bump github.com/mattn/go-runewidth from 0.0.9 to 0.0.10.
- Allowing CI to modify go.mod and go.sum when necessary.
- Executed `go mod tidy`.

### Added

- TitleColor and TitleFocusedColor options for border title which enables the
setting of separate colors for border and title on a container.

## [0.14.0] - 30-Dec-2020

### Breaking API changes
Expand Down Expand Up @@ -439,7 +453,8 @@ identifiers shouldn't be used externally.
- The Gauge widget.
- The Text widget.

[unreleased]: https://github.com/mum4k/termdash/compare/v0.14.0...devel
[unreleased]: https://github.com/mum4k/termdash/compare/v0.15.0...devel
[0.15.0]: https://github.com/mum4k/termdash/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/mum4k/termdash/compare/v0.13.0...v0.14.0
[0.13.0]: https://github.com/mum4k/termdash/compare/v0.12.2...v0.13.0
[0.12.2]: https://github.com/mum4k/termdash/compare/v0.12.1...v0.12.2
Expand Down
148 changes: 148 additions & 0 deletions container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,154 @@ func TestNew(t *testing.T) {
return ft
},
},
{
desc: "sets border title on root container of different color",
termSize: image.Point{10, 10},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
Border(linestyle.Light),
BorderTitle("Ab"),
BorderColor(cell.ColorRed),
FocusedColor(cell.ColorBlue),
TitleColor(cell.ColorMagenta),
TitleFocusedColor(cell.ColorCyan),
SplitVertical(
Left(
Border(linestyle.Light),
),
Right(
Border(linestyle.Light),
),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(
cvs,
image.Rect(0, 0, 10, 10),
draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
)
testdraw.MustBorder(
cvs,
image.Rect(1, 1, 5, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustBorder(
cvs,
image.Rect(5, 1, 9, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustText(
cvs,
"Ab",
image.Point{1, 0},
draw.TextCellOpts(cell.FgColor(cell.ColorCyan)),
)
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "sets different color title on left child container",
termSize: image.Point{10, 10},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
Border(linestyle.Light),
BorderColor(cell.ColorRed),
FocusedColor(cell.ColorBlue),
SplitVertical(
Left(
Border(linestyle.Light),
BorderTitle("Ab"),
TitleColor(cell.ColorMagenta),
TitleFocusedColor(cell.ColorCyan),
),
Right(
Border(linestyle.Light),
),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(
cvs,
image.Rect(0, 0, 10, 10),
draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
)
testdraw.MustBorder(
cvs,
image.Rect(1, 1, 5, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustBorder(
cvs,
image.Rect(5, 1, 9, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustText(
cvs,
"Ab",
image.Point{2, 1},
draw.TextCellOpts(cell.FgColor(cell.ColorMagenta)),
)
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "inherits the border color for the title on left child container when TitleColor is not set",
termSize: image.Point{10, 10},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
Border(linestyle.Light),
BorderColor(cell.ColorRed),
FocusedColor(cell.ColorBlue),
SplitVertical(
Left(
Border(linestyle.Light),
BorderTitle("Ab"),
),
Right(
Border(linestyle.Light),
),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(
cvs,
image.Rect(0, 0, 10, 10),
draw.BorderCellOpts(cell.FgColor(cell.ColorBlue)),
)
testdraw.MustBorder(
cvs,
image.Rect(1, 1, 5, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustBorder(
cvs,
image.Rect(5, 1, 9, 9),
draw.BorderCellOpts(cell.FgColor(cell.ColorRed)),
)
testdraw.MustText(
cvs,
"Ab",
image.Point{2, 1},
draw.TextCellOpts(cell.FgColor(cell.ColorRed)),
)
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "splitting a container removes the widget",
termSize: image.Point{10, 10},
Expand Down
14 changes: 12 additions & 2 deletions container/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,26 @@ func drawBorder(c *Container) error {
return err
}

var cOpts []cell.Option
var cOpts, titleCOpts []cell.Option
if c.focusTracker.isActive(c) {
cOpts = append(cOpts, cell.FgColor(c.opts.inherited.focusedColor))
if c.opts.inherited.titleFocusedColor != nil {
titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleFocusedColor))
} else {
titleCOpts = cOpts
}
} else {
cOpts = append(cOpts, cell.FgColor(c.opts.inherited.borderColor))
if c.opts.inherited.titleColor != nil {
titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleColor))
} else {
titleCOpts = cOpts
}
}

if err := draw.Border(cvs, ar,
draw.BorderLineStyle(c.opts.border),
draw.BorderTitle(c.opts.borderTitle, draw.OverrunModeThreeDot, cOpts...),
draw.BorderTitle(c.opts.borderTitle, draw.OverrunModeThreeDot, titleCOpts...),
draw.BorderTitleAlign(c.opts.borderTitleHAlign),
draw.BorderCellOpts(cOpts...),
); err != nil {
Expand Down
38 changes: 38 additions & 0 deletions container/draw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,44 @@ func TestDrawWidget(t *testing.T) {
return ft
},
},
{
desc: "draws widget with container border and title with different color and focus color",
termSize: image.Point{9, 5},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
Border(linestyle.Light),
BorderTitle("ab"),
TitleColor(cell.ColorBlue),
// The created container is in focus so we must set the focus color
// in order to see the difference.
TitleFocusedColor(cell.ColorBlue),
BorderTitleAlignLeft(),
PlaceWidget(fakewidget.New(widgetapi.Options{})),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
// Container border.
testdraw.MustBorder(
cvs,
cvs.Area(),
draw.BorderCellOpts(cell.FgColor(cell.ColorYellow)),
draw.BorderTitle(
"ab",
draw.OverrunModeThreeDot,
cell.FgColor(cell.ColorBlue),
),
)

// Fake widget border.
testdraw.MustBorder(cvs, image.Rect(1, 1, 8, 4))
testdraw.MustText(cvs, "(7,3)", image.Point{2, 2})
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "draws widget without container border",
termSize: image.Point{9, 5},
Expand Down
23 changes: 23 additions & 0 deletions container/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ type inherited struct {
borderColor cell.Color
// focusedColor is the color used for the border when focused.
focusedColor cell.Color
// titleColor is the color used for the title.
titleColor *cell.Color
// titleFocusedColor is the color used for the title when focused.
titleFocusedColor *cell.Color
}

// focusGroups maps focus group numbers that have the same key assigned.
Expand Down Expand Up @@ -749,6 +753,25 @@ func FocusedColor(color cell.Color) Option {
})
}

// TitleColor sets the color of the title around the container.
// This option is inherited to sub containers created by container splits.
func TitleColor(color cell.Color) Option {
return option(func(c *Container) error {
c.opts.inherited.titleColor = &color
return nil
})
}

// TitleFocusedColor sets the color of the container title when it has
// keyboard focus.
// This option is inherited to sub containers created by container splits.
func TitleFocusedColor(color cell.Color) Option {
return option(func(c *Container) error {
c.opts.inherited.titleFocusedColor = &color
return nil
})
}

// splitType identifies how a container is split.
type splitType int

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module github.com/mum4k/termdash
go 1.14

require (
github.com/gdamore/tcell/v2 v2.0.0
github.com/gdamore/tcell/v2 v2.2.0
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-runewidth v0.0.9
github.com/mattn/go-runewidth v0.0.10
github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e
golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba // indirect
golang.org/x/text v0.3.4 // indirect
)
31 changes: 10 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/gdamore/tcell/v2 v2.2.0 h1:vSyEgKwraXPSOkvCk7IwOSyX+Pv3V2cV9CikJMXg4U4=
github.com/gdamore/tcell/v2 v2.2.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be h1:yzmWtPyxEUIKdZg4RcPq64MfS8NA6A5fNOJgYhpR9EQ=
github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e h1:T8/SzSWIDoWV9trslLNfUdJ5yHrIXXuODEy5M0vou4U=
github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba h1:xmhUJGQGbxlod18iJGqVEp9cHIPLl7QiX2aA3to708s=
golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down

0 comments on commit 8a5b62c

Please sign in to comment.