Skip to content

Commit

Permalink
Merge pull request #374 from mum4k/release-0-20-0
Browse files Browse the repository at this point in the history
Releasing Termdash v0.20.0.
  • Loading branch information
mum4k authored Mar 10, 2024
2 parents bc63a16 + db8e463 commit 102df20
Show file tree
Hide file tree
Showing 8 changed files with 674 additions and 45 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.20.0] - 10-Mar-2024

### Added

- Support for an alternative way of splitting containers where the size or
percentage is specified for the right (or bottom) container and the left (or
top) is calculated.

### Changed

- Bump github.com/gdamore/tcell/v2 from 2.7.0 to 2.7.4.

## [0.19.0] - 29-Jan-2024

### Added
Expand Down Expand Up @@ -531,7 +543,8 @@ identifiers shouldn't be used externally.
- The Gauge widget.
- The Text widget.

[unreleased]: https://github.com/mum4k/termdash/compare/v0.19.0...devel
[unreleased]: https://github.com/mum4k/termdash/compare/v0.20.0...devel
[0.20.0]: https://github.com/mum4k/termdash/compare/v0.19.0...v0.20.0
[0.19.0]: https://github.com/mum4k/termdash/compare/v0.18.0...v0.19.0
[0.18.0]: https://github.com/mum4k/termdash/compare/v0.17.0...v0.18.0
[0.17.0]: https://github.com/mum4k/termdash/compare/v0.16.1...v0.17.0
Expand Down
12 changes: 12 additions & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,26 @@ func (c *Container) split() (image.Rectangle, image.Rectangle, error) {
}
if c.opts.splitFixed > DefaultSplitFixed {
if c.opts.split == splitTypeVertical {
if c.opts.splitReversed {
return area.VSplitCellsReversed(ar, c.opts.splitFixed)
}
return area.VSplitCells(ar, c.opts.splitFixed)
}
if c.opts.splitReversed {
return area.HSplitCellsReversed(ar, c.opts.splitFixed)
}
return area.HSplitCells(ar, c.opts.splitFixed)
}

if c.opts.split == splitTypeVertical {
if c.opts.splitReversed {
return area.VSplitReversed(ar, c.opts.splitPercent)
}
return area.VSplit(ar, c.opts.splitPercent)
}
if c.opts.splitReversed {
return area.HSplitReversed(ar, c.opts.splitPercent)
}
return area.HSplit(ar, c.opts.splitPercent)
}

Expand Down
106 changes: 105 additions & 1 deletion container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,33 @@ func TestNew(t *testing.T) {
},
},
{
desc: "horizontal unequal split",
desc: "horizontal, reversed unequal split",
termSize: image.Point{10, 20},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
SplitHorizontal(
Top(
Border(linestyle.Light),
),
Bottom(
Border(linestyle.Light),
),
SplitPercentFromEnd(20),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(cvs, image.Rect(0, 0, 10, 16))
testdraw.MustBorder(cvs, image.Rect(0, 16, 10, 20))
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "horizontal fixed splits",
termSize: image.Point{10, 20},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
Expand All @@ -738,6 +764,32 @@ func TestNew(t *testing.T) {
return ft
},
},
{
desc: "horizontal, reversed fixed splits",
termSize: image.Point{10, 20},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
SplitHorizontal(
Top(
Border(linestyle.Light),
),
Bottom(
Border(linestyle.Light),
),
SplitFixedFromEnd(4),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(cvs, image.Rect(0, 0, 10, 16))
testdraw.MustBorder(cvs, image.Rect(0, 16, 10, 20))
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "horizontal split, parent and children have borders",
termSize: image.Point{10, 10},
Expand Down Expand Up @@ -864,6 +916,32 @@ func TestNew(t *testing.T) {
return ft
},
},
{
desc: "vertical, reversed unequal split",
termSize: image.Point{20, 10},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
SplitVertical(
Left(
Border(linestyle.Light),
),
Right(
Border(linestyle.Light),
),
SplitPercentFromEnd(20),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(cvs, image.Rect(0, 0, 16, 10))
testdraw.MustBorder(cvs, image.Rect(16, 0, 20, 10))
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "vertical fixed splits",
termSize: image.Point{20, 10},
Expand All @@ -890,6 +968,32 @@ func TestNew(t *testing.T) {
return ft
},
},
{
desc: "vertical, reversed fixed splits",
termSize: image.Point{20, 10},
container: func(ft *faketerm.Terminal) (*Container, error) {
return New(
ft,
SplitVertical(
Left(
Border(linestyle.Light),
),
Right(
Border(linestyle.Light),
),
SplitFixedFromEnd(4),
),
)
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
testdraw.MustBorder(cvs, image.Rect(0, 0, 16, 10))
testdraw.MustBorder(cvs, image.Rect(16, 0, 20, 10))
testcanvas.MustApply(cvs, ft)
return ft
},
},
{
desc: "vertical split, parent and children have borders",
termSize: image.Point{10, 10},
Expand Down
67 changes: 57 additions & 10 deletions container/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ type options struct {
inherited inherited

// split identifies how is this container split.
split splitType
splitPercent int
splitFixed int
split splitType
splitReversed bool
splitPercent int
splitFixed int

// widget is the widget in the container.
// A container can have either two sub containers (left and right) or a
Expand Down Expand Up @@ -247,10 +248,11 @@ func newOptions(parent *options) *options {
inherited: inherited{
focusedColor: cell.ColorYellow,
},
hAlign: align.HorizontalCenter,
vAlign: align.VerticalMiddle,
splitPercent: DefaultSplitPercent,
splitFixed: DefaultSplitFixed,
hAlign: align.HorizontalCenter,
vAlign: align.VerticalMiddle,
splitReversed: DefaultSplitReversed,
splitPercent: DefaultSplitPercent,
splitFixed: DefaultSplitFixed,
}
if parent != nil {
opts.global = parent.global
Expand Down Expand Up @@ -281,13 +283,17 @@ func (so splitOption) setSplit(opts *options) error {
return so(opts)
}

// DefaultSplitReversed is the default value for the SplitReversed option.
const DefaultSplitReversed = false

// DefaultSplitPercent is the default value for the SplitPercent option.
const DefaultSplitPercent = 50

// DefaultSplitFixed is the default value for the SplitFixed option.
const DefaultSplitFixed = -1

// SplitPercent sets the relative size of the split as percentage of the available space.
// SplitPercent sets the relative size of the split as percentage of the
// available space.
// When using SplitVertical, the provided size is applied to the new left
// container, the new right container gets the reminder of the size.
// When using SplitHorizontal, the provided size is applied to the new top
Expand All @@ -304,15 +310,35 @@ func SplitPercent(p int) SplitOption {
})
}

// SplitPercentFromEnd sets the relative size of the split as percentage of the
// available space.
// When using SplitVertical, the provided size is applied to the new right
// container, the new left container gets the reminder of the size.
// When using SplitHorizontal, the provided size is applied to the new bottom
// container, the new top container gets the reminder of the size.
// The provided value must be a positive number in the range 0 < p < 100.
// If not provided, defaults to using SplitPercent with DefaultSplitPercent.
func SplitPercentFromEnd(p int) SplitOption {
return splitOption(func(opts *options) error {
if min, max := 0, 100; p <= min || p >= max {
return fmt.Errorf("invalid split percentage %d, must be in range %d < p < %d", p, min, max)
}
opts.splitReversed = true
opts.splitPercent = p
return nil
})
}

// SplitFixed sets the size of the first container to be a fixed value
// and makes the second container take up the remaining space.
// When using SplitVertical, the provided size is applied to the new left
// container, the new right container gets the reminder of the size.
// When using SplitHorizontal, the provided size is applied to the new top
// container, the new bottom container gets the reminder of the size.
// The provided value must be a positive number in the range 0 <= cells.
// If SplitFixed() is not specified, it defaults to SplitPercent() and its given value.
// Only one of SplitFixed() and SplitPercent() can be specified per container.
// If SplitFixed* or SplitPercent* is not specified, it defaults to
// SplitPercent() and its given value.
// Only one SplitFixed* or SplitPercent* may be specified per container.
func SplitFixed(cells int) SplitOption {
return splitOption(func(opts *options) error {
if cells < 0 {
Expand All @@ -323,6 +349,27 @@ func SplitFixed(cells int) SplitOption {
})
}

// SplitFixedFromEnd sets the size of the second container to be a fixed value
// and makes the first container take up the remaining space.
// When using SplitVertical, the provided size is applied to the new right
// container, the new left container gets the reminder of the size.
// When using SplitHorizontal, the provided size is applied to the new bottom
// container, the new top container gets the reminder of the size.
// The provided value must be a positive number in the range 0 <= cells.
// If SplitFixed* or SplitPercent* is not specified, it defaults to
// SplitPercent() and its given value.
// Only one SplitFixed* or SplitPercent* may be specified per container.
func SplitFixedFromEnd(cells int) SplitOption {
return splitOption(func(opts *options) error {
if cells < 0 {
return fmt.Errorf("invalid fixed value %d, must be in range %d <= cells", cells, 0)
}
opts.splitFixed = cells
opts.splitReversed = true
return nil
})
}

// SplitVertical splits the container along the vertical axis into two sub
// containers. The use of this option removes any widget placed at this
// container, containers with sub containers cannot contain widgets.
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mum4k/termdash
go 1.21

require (
github.com/gdamore/tcell/v2 v2.7.0
github.com/gdamore/tcell/v2 v2.7.4
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-runewidth v0.0.15
github.com/nsf/termbox-go v1.1.1
Expand All @@ -13,7 +13,7 @@ require (
github.com/gdamore/encoding v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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/v2 v2.7.0 h1:I5LiGTQuwrysAt1KS9wg1yFfOI3arI3ucFrxtd/xqaA=
github.com/gdamore/tcell/v2 v2.7.0/go.mod h1:hl/KtAANGBecfIPxk+FzKvThTqI84oplgbPEmVX60b8=
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
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.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand Down Expand Up @@ -32,13 +32,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
Loading

0 comments on commit 102df20

Please sign in to comment.