From f5f815b384b5df25fa95c8cd31d1c23f25a8aac6 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Fri, 3 May 2019 20:58:17 +0100 Subject: [PATCH 1/7] @SpellarBot fixed 3 typos for you :) --- doc/hld.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/hld.md b/doc/hld.md index 5e663e0..a38eb8a 100644 --- a/doc/hld.md +++ b/doc/hld.md @@ -5,7 +5,7 @@ Develop infrastructure of dashboard widgets. The widgets should support both input (mouse and keyboard) and output (display of information to the user). -Fulfill the requirements outlined in the main +Fulfil the requirements outlined in the main [README](http://github.com/mum4k/termdash). ## Background @@ -76,11 +76,11 @@ The infrastructure handles terminal setup, input events and manages containers. #### Input events The infrastructure regularly polls events from the terminal layer and feeds -them into the event distribution system (EDS). The EDS fulfills the following +them into the event distribution system (EDS). The EDS fulfils the following functions: - Allow subscribers to specify the type of events they want to receive. -- Distributeis events in a non-blocking manner, i.e. a single slow subscriber +- Distributes events in a non-blocking manner, i.e. a single slow subscriber cannot slow down other subscribers. - Events to each subscriber are throttled, if a subscriber builds a long tail of unprocessed input events, the EDS selectively drops repetitive events From 4fdf11b21c7a816d5332b4c87b9060ba4bd213a3 Mon Sep 17 00:00:00 2001 From: Donald Wilson Date: Sat, 4 May 2019 05:19:14 -0400 Subject: [PATCH 2/7] Update termdashdemo.go --- termdashdemo/termdashdemo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termdashdemo/termdashdemo.go b/termdashdemo/termdashdemo.go index a37dd75..f2b6ab2 100644 --- a/termdashdemo/termdashdemo.go +++ b/termdashdemo/termdashdemo.go @@ -13,7 +13,7 @@ // limitations under the License. // Binary termdashdemo demonstrates the functionality of termdash and its various widgets. -// Exist when 'q' is pressed. +// Exits when 'q' is pressed. package main import ( From 6980f88810aabb80a5247f6fb3d27477ac3bef6b Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Mon, 13 May 2019 22:28:41 -0400 Subject: [PATCH 3/7] Release widget's mutex before activating external callback. Fixes #205. --- widgets/button/button.go | 41 +++++++++++++++++++++++++--------- widgets/textinput/textinput.go | 24 +++++++++++++++----- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/widgets/button/button.go b/widgets/button/button.go index 0a7544e..beaf5ca 100644 --- a/widgets/button/button.go +++ b/widgets/button/button.go @@ -154,11 +154,8 @@ func (b *Button) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error { ) } -// Keyboard processes keyboard events, acts as a button press on the configured -// Key. -// -// Implements widgetapi.Widget.Keyboard. -func (b *Button) Keyboard(k *terminalapi.Keyboard) error { +// activated asserts whether the keyboard event activated the button. +func (b *Button) keyActivated(k *terminalapi.Keyboard) bool { b.mu.Lock() defer b.mu.Unlock() @@ -166,16 +163,27 @@ func (b *Button) Keyboard(k *terminalapi.Keyboard) error { b.state = button.Down now := time.Now().UTC() b.keyTriggerTime = &now + return true + } + return false +} + +// Keyboard processes keyboard events, acts as a button press on the configured +// Key. +// +// Implements widgetapi.Widget.Keyboard. +func (b *Button) Keyboard(k *terminalapi.Keyboard) error { + if b.keyActivated(k) { + // Mutex must be released when calling the callback. + // Users might call container methods from the callback like the + // Container.Update, see #205. return b.callback() } return nil } -// Mouse processes mouse events, acts as a button press if both the press and -// the release happen inside the button. -// -// Implements widgetapi.Widget.Mouse. -func (b *Button) Mouse(m *terminalapi.Mouse) error { +// mouseActivated asserts whether the mouse event activated the button. +func (b *Button) mouseActivated(m *terminalapi.Mouse) bool { b.mu.Lock() defer b.mu.Unlock() @@ -183,7 +191,18 @@ func (b *Button) Mouse(m *terminalapi.Mouse) error { b.state = state b.keyTriggerTime = nil - if clicked { + return clicked +} + +// Mouse processes mouse events, acts as a button press if both the press and +// the release happen inside the button. +// +// Implements widgetapi.Widget.Mouse. +func (b *Button) Mouse(m *terminalapi.Mouse) error { + if b.mouseActivated(m) { + // Mutex must be released when calling the callback. + // Users might call container methods from the callback like the + // Container.Update, see #205. return b.callback() } return nil diff --git a/widgets/textinput/textinput.go b/widgets/textinput/textinput.go index cc2de60..5b0b05c 100644 --- a/widgets/textinput/textinput.go +++ b/widgets/textinput/textinput.go @@ -220,9 +220,11 @@ func (ti *TextInput) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error { return nil } -// Keyboard processes keyboard events. +// keyboard processes keyboard events. +// Returns a bool indicating if the content was submitted and the text in the +// field at submission time. // Implements widgetapi.Widget.Keyboard. -func (ti *TextInput) Keyboard(k *terminalapi.Keyboard) error { +func (ti *TextInput) keyboard(k *terminalapi.Keyboard) (bool, string) { ti.mu.Lock() defer ti.mu.Unlock() @@ -251,21 +253,33 @@ func (ti *TextInput) Keyboard(k *terminalapi.Keyboard) error { ti.editor.reset() } if ti.opts.onSubmit != nil { - return ti.opts.onSubmit(text) + return true, text } default: if err := wrap.ValidText(string(k.Key)); err != nil { // Ignore unsupported runes. - return nil + return false, "" } if ti.opts.filter != nil && !ti.opts.filter(rune(k.Key)) { // Ignore filtered runes. - return nil + return false, "" } ti.editor.insert(rune(k.Key)) } + return false, "" +} + +// Keyboard processes keyboard events. +// Implements widgetapi.Widget.Keyboard. +func (ti *TextInput) Keyboard(k *terminalapi.Keyboard) error { + if submitted, text := ti.keyboard(k); submitted { + // Mutex must be released when calling the callback. + // Users might call container methods from the callback like the + // Container.Update, see #205. + return ti.opts.onSubmit(text) + } return nil } From ce095e1447ef1581ea9988cdb1f5cf32719c879c Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Mon, 13 May 2019 22:42:50 -0400 Subject: [PATCH 4/7] Listing projects in README - listing similar projects. - starting a list of Termdash users. - noting that PRs should be against the devel branch. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 7e61dd7..0ae9ee2 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,20 @@ before contributing. If you're developing a new widget, please see the [widget development](doc/widget_development.md) section. +Termdash uses [this branching model](https://nvie.com/posts/a-successful-git-branching-model/). When you fork the repository, base your changes off the [devel](https://github.com/mum4k/termdash/tree/devel) branch and the pull request should merge it back to the devel branch. Commits to the master branch are limited to releases, major bug fixes and documentation updates. + +# Similar projects in Go + +- [termui](https://github.com/gizak/termui) +- [tview](https://github.com/rivo/tview) +- [gocui](https://github.com/jroimartin/gocui) +- [gowid](https://github.com/gcla/gowid) +- [clui](https://github.com/VladimirMarkelov/clui) +- [tui-go](https://github.com/marcusolsson/tui-go) + +# Projects using Termdash + +- [grafterm](https://github.com/slok/grafterm) # Disclaimer From ead318993bd944dcb1d7e212a6b51c4000912261 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Mon, 13 May 2019 22:44:00 -0400 Subject: [PATCH 5/7] Updating CHANGELOG. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fdfa5d..4f7fd65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Termdash could deadlock when a `Button` or a `TextInput` was configured to + call the `Container.Update` method. + ## [0.9.0] - 28-Apr-2019 ### Added From cc66ef040e622b3775d1ca40dab9f2c67753cb40 Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Tue, 14 May 2019 07:11:52 +0200 Subject: [PATCH 6/7] Add grafterm description on readme Signed-off-by: Xabier Larrakoetxea --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ae9ee2..e34072f 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ go get -u github.com/mum4k/termdash The usage of most of these elements is demonstrated in [termdashdemo.go](termdashdemo/termdashdemo.go). To execute the demo: - ```go go run github.com/mum4k/termdash/termdashdemo/termdashdemo.go ``` @@ -207,7 +206,7 @@ Termdash uses [this branching model](https://nvie.com/posts/a-successful-git-bra # Projects using Termdash -- [grafterm](https://github.com/slok/grafterm) +- [grafterm](https://github.com/slok/grafterm): Metrics dashboards visualization on the terminal. # Disclaimer From 6fe095f49b2376fd173dcf1c23e455814d53aca4 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Wed, 15 May 2019 23:20:51 -0400 Subject: [PATCH 7/7] Updating CHANGELOG for bugfix release v0.9.1. --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7fd65..1dadd76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.9.1] - 15-May-2019 + ### Fixed - Termdash could deadlock when a `Button` or a `TextInput` was configured to @@ -269,7 +271,8 @@ identifiers shouldn't be used externally. - The Gauge widget. - The Text widget. -[unreleased]: https://github.com/mum4k/termdash/compare/v0.9.0...devel +[unreleased]: https://github.com/mum4k/termdash/compare/v0.9.1...devel +[0.9.1]: https://github.com/mum4k/termdash/compare/v0.9.0...v0.9.1 [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