Skip to content

Commit

Permalink
Merge 8414868 into a9515f2
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Apr 29, 2019
2 parents a9515f2 + 8414868 commit 45e3d01
Show file tree
Hide file tree
Showing 63 changed files with 6,692 additions and 579 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,8 +1,8 @@
language: go
go:
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- stable
script:
- go get -t ./...
Expand Down
41 changes: 35 additions & 6 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.0] - 28-Apr-2019

### Added

- The `TextInput` widget, an input field allowing interactive text input.
- The `Donut` widget can now display an optional text label under the donut.

### Changed

- Widgets now get information whether their container is focused when Draw is
executed.
- The SegmentDisplay widget now has a method that returns the observed character
capacity the last time Draw was called.
- The grid.Builder API now allows users to specify options for intermediate
containers, i.e. containers that don't have widgets, but represent rows and
columns.
- Line chart widget now allows `math.NaN` values to represent "no value" (values
that will not be rendered) in the values slice.

#### Breaking API changes

- The widgetapi.Widget.Draw method now accepts a second argument which provides
widgets with additional metadata. This affects all implemented widgets.
- Termdash now requires at least Go version 1.10, which allows us to utilize
`math.Round` instead of our own implementation and `strings.Builder` instead
of `bytes.Buffer`.
- Terminal shortcuts like `Ctrl-A` no longer come as two separate events,
Termdash now mirrors termbox-go and sends these as one event.

## [0.8.0] - 30-Mar-2019

### Added
Expand Down Expand Up @@ -70,10 +99,10 @@ identifiers shouldn't be used externally.
- The draw.LineStyle enum was refactored into its own package
linestyle.LineStyle. Users will have to replace:

- draw.LineStyleNone -> linestyle.None
- draw.LineStyleLight -> linestyle.Light
- draw.LineStyleDouble -> linestyle.Double
- draw.LineStyleRound -> linestyle.Round
- draw.LineStyleNone -> linestyle.None
- draw.LineStyleLight -> linestyle.Light
- draw.LineStyleDouble -> linestyle.Double
- draw.LineStyleRound -> linestyle.Round

## [0.7.0] - 24-Feb-2019

Expand Down Expand Up @@ -107,7 +136,6 @@ identifiers shouldn't be used externally.
- The Text widget now has a Write option that atomically replaces the entire
text content.


#### Improvements to the infrastructure

- A function that draws text vertically.
Expand Down Expand Up @@ -236,7 +264,8 @@ identifiers shouldn't be used externally.
- The Gauge widget.
- The Text widget.

[Unreleased]: https://github.com/mum4k/termdash/compare/v0.8.0...devel
[unreleased]: https://github.com/mum4k/termdash/compare/v0.9.0...devel
[0.9.0]: https://github.com/mum4k/termdash/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/mum4k/termdash/compare/v0.7.2...v0.8.0
[0.7.2]: https://github.com/mum4k/termdash/compare/v0.7.1...v0.7.2
[0.7.1]: https://github.com/mum4k/termdash/compare/v0.7.0...v0.7.1
Expand Down
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@

Termdash is a cross-platform customizable terminal based dashboard.

[<img src="./doc/images/termdashdemo_0_8_0.gif" alt="termdashdemo" type="image/gif">](termdashdemo/termdashdemo.go)
[<img src="./doc/images/termdashdemo_0_9_0.gif" alt="termdashdemo" type="image/gif">](termdashdemo/termdashdemo.go)

The feature set is inspired by the
[gizak/termui](http://github.com/gizak/termui) project, which in turn was
Expand Down Expand Up @@ -86,6 +86,18 @@ go run github.com/mum4k/termdash/widgets/button/buttondemo/buttondemo.go

[<img src="./doc/images/buttondemo.gif" alt="buttondemo" type="image/gif" width="50%">](widgets/button/buttondemo/buttondemo.go)

## The TextInput

Allows users to interact with the application by entering, editing and
submitting text data. Run the
[textinputdemo](widgets/textinput/textinputdemo/textinputdemo.go).

```go
go run github.com/mum4k/termdash/widgets/textinput/textinputdemo/textinputdemo.go
```

[<img src="./doc/images/textinputdemo.gif" alt="textinputdemo" type="image/gif" width="80%">](widgets/textinput/textinputdemo/textinputdemo.go)

## The Gauge

Displays the progress of an operation. Run the
Expand Down
43 changes: 38 additions & 5 deletions container/container_test.go
Expand Up @@ -907,9 +907,12 @@ func TestNew(t *testing.T) {
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))
testdraw.MustText(cvs, "(10,10)", image.Point{1, 1})
testcanvas.MustApply(cvs, ft)
fakewidget.MustDraw(
ft,
cvs,
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
},
},
Expand Down Expand Up @@ -1033,18 +1036,21 @@ func TestKeyboard(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 0, 20, 20)),
&widgetapi.Meta{},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
)
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(20, 0, 40, 10)),
&widgetapi.Meta{},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
)

// The focused widget receives the key.
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(20, 10, 40, 20)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
&terminalapi.Keyboard{Key: keyboard.KeyEnter},
)
Expand Down Expand Up @@ -1089,6 +1095,7 @@ func TestKeyboard(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 0, 20, 20)),
&widgetapi.Meta{},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeGlobal},
&terminalapi.Keyboard{Key: keyboard.KeyEnter},
)
Expand All @@ -1097,13 +1104,15 @@ func TestKeyboard(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(20, 0, 40, 10)),
&widgetapi.Meta{},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
)

// The focused widget receives the key.
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(20, 10, 40, 20)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
&terminalapi.Keyboard{Key: keyboard.KeyEnter},
)
Expand All @@ -1128,6 +1137,7 @@ func TestKeyboard(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(ft.Area()),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand All @@ -1152,6 +1162,7 @@ func TestKeyboard(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(ft.Area()),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1249,6 +1260,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(ft.Area()),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1301,11 +1313,13 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 0, 25, 20)),
&widgetapi.Meta{},
widgetapi.Options{},
)
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(25, 10, 50, 20)),
&widgetapi.Meta{},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Keyboard{},
)
Expand All @@ -1314,6 +1328,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(25, 0, 50, 10)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{24, 9}, Button: mouse.ButtonLeft},
&terminalapi.Mouse{Position: image.Point{24, 9}, Button: mouse.ButtonRelease},
Expand Down Expand Up @@ -1381,11 +1396,13 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 0, 25, 20)),
&widgetapi.Meta{},
widgetapi.Options{},
)
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(25, 10, 50, 20)),
&widgetapi.Meta{},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Keyboard{},
)
Expand All @@ -1394,6 +1411,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(26, 1, 49, 9)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{22, 7}, Button: mouse.ButtonLeft},
&terminalapi.Mouse{Position: image.Point{22, 7}, Button: mouse.ButtonRelease},
Expand All @@ -1419,6 +1437,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(ft.Area()),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1453,6 +1472,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(1, 1, 19, 19)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1487,6 +1507,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(1, 1, 20, 19)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1522,6 +1543,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(1, 1, 20, 19)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1553,6 +1575,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 5, 20, 15)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1583,6 +1606,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 5, 20, 15)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1614,6 +1638,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 5, 20, 15)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1650,6 +1675,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 10, 20, 20)),
&widgetapi.Meta{},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1685,6 +1711,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 10, 20, 20)),
&widgetapi.Meta{},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -1720,6 +1747,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 10, 20, 20)),
&widgetapi.Meta{},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1751,6 +1779,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(0, 5, 20, 15)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{0, 0}, Button: mouse.ButtonLeft},
)
Expand Down Expand Up @@ -1782,6 +1811,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(image.Rect(6, 0, 24, 20)),
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{0, 0}, Button: mouse.ButtonLeft},
)
Expand All @@ -1807,6 +1837,7 @@ func TestMouse(t *testing.T) {
fakewidget.MustDraw(
ft,
testcanvas.MustNew(ft.Area()),
&widgetapi.Meta{Focused: true},
widgetapi.Options{},
)
return ft
Expand Down Expand Up @@ -2009,7 +2040,7 @@ func TestUpdate(t *testing.T) {
cvs := testcanvas.MustNew(ft.Area())
wAr := image.Rect(10, 0, 20, 10)
wCvs := testcanvas.MustNew(wAr)
fakewidget.MustDraw(ft, wCvs, widgetapi.Options{})
fakewidget.MustDraw(ft, wCvs, &widgetapi.Meta{}, widgetapi.Options{})
testcanvas.MustCopyTo(wCvs, cvs)
testcanvas.MustApply(cvs, ft)
return ft
Expand Down Expand Up @@ -2041,7 +2072,7 @@ func TestUpdate(t *testing.T) {
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
cvs := testcanvas.MustNew(ft.Area())
fakewidget.MustDraw(ft, cvs, widgetapi.Options{})
fakewidget.MustDraw(ft, cvs, &widgetapi.Meta{Focused: true}, widgetapi.Options{})
testcanvas.MustApply(cvs, ft)
return ft
},
Expand Down Expand Up @@ -2212,6 +2243,7 @@ func TestUpdate(t *testing.T) {
fakewidget.MustDraw(
ft,
cvs,
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
&terminalapi.Keyboard{Key: keyboard.KeyEnter},
)
Expand Down Expand Up @@ -2243,6 +2275,7 @@ func TestUpdate(t *testing.T) {
fakewidget.MustDraw(
ft,
cvs,
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget},
&terminalapi.Mouse{Position: image.Point{0, 0}, Button: mouse.ButtonRelease},
)
Expand Down
7 changes: 6 additions & 1 deletion container/draw.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mum4k/termdash/internal/area"
"github.com/mum4k/termdash/internal/canvas"
"github.com/mum4k/termdash/internal/draw"
"github.com/mum4k/termdash/widgetapi"
)

// drawTree draws this container and all of its sub containers.
Expand Down Expand Up @@ -130,7 +131,11 @@ func drawWidget(c *Container) error {
return err
}

if err := c.opts.widget.Draw(cvs); err != nil {
meta := &widgetapi.Meta{
Focused: c.focusTracker.isActive(c),
}

if err := c.opts.widget.Draw(cvs, meta); err != nil {
return err
}
return cvs.Apply(c.term)
Expand Down

0 comments on commit 45e3d01

Please sign in to comment.