From d8a476ec57b23be95a1c4aa6f3f248f46083855f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Dec 2020 07:55:34 +0000 Subject: [PATCH 01/21] Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0 Bumps [github.com/gdamore/tcell/v2](https://github.com/gdamore/tcell) from 2.0.0 to 2.1.0. - [Release notes](https://github.com/gdamore/tcell/releases) - [Changelog](https://github.com/gdamore/tcell/blob/master/CHANGESv2.adoc) - [Commits](https://github.com/gdamore/tcell/compare/v2.0.0...v2.1.0) Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 7d8ce5f0..d387d99c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mum4k/termdash go 1.14 require ( - github.com/gdamore/tcell/v2 v2.0.0 + github.com/gdamore/tcell/v2 v2.1.0 github.com/kylelemons/godebug v1.1.0 github.com/mattn/go-runewidth v0.0.9 github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e diff --git a/go.sum b/go.sum index b9b635e0..d39aed70 100644 --- a/go.sum +++ b/go.sum @@ -1,25 +1,14 @@ -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.1.0 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro= +github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= 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/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= From f4b0d03624e4b590a6bfe22b60b3600c3e0dc2f3 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Wed, 30 Dec 2020 23:40:17 -0500 Subject: [PATCH 02/21] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 790c1faa..33ece876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0. + ## [0.14.0] - 30-Dec-2020 ### Breaking API changes From 22ae449020bddd164e15d0669b2356249f894cfa Mon Sep 17 00:00:00 2001 From: Andreea Sobon Date: Mon, 4 Jan 2021 12:20:40 -0500 Subject: [PATCH 03/21] Support setting of different colors for container's border and title. --- container/container_test.go | 149 ++++++++++++++++++++++++++++++++++++ container/draw.go | 18 ++++- container/draw_test.go | 38 +++++++++ container/options.go | 23 ++++++ 4 files changed, 224 insertions(+), 4 deletions(-) diff --git a/container/container_test.go b/container/container_test.go index d4d4704a..26a19176 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -1003,6 +1003,155 @@ 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 title color 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"), + ), + 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}, diff --git a/container/draw.go b/container/draw.go index d186b127..83524b34 100644 --- a/container/draw.go +++ b/container/draw.go @@ -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)) - } else { + 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 { diff --git a/container/draw_test.go b/container/draw_test.go index 9789772a..76c14d7b 100644 --- a/container/draw_test.go +++ b/container/draw_test.go @@ -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}, diff --git a/container/options.go b/container/options.go index 795e61c5..1fa718a8 100644 --- a/container/options.go +++ b/container/options.go @@ -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. @@ -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 From f8470e7dfee48adf541ee68ee1f44979c0010c31 Mon Sep 17 00:00:00 2001 From: Andreea Sobon Date: Mon, 4 Jan 2021 12:34:23 -0500 Subject: [PATCH 04/21] Fix formatting issues. --- container/container_test.go | 11 +++++------ container/draw.go | 12 ++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/container/container_test.go b/container/container_test.go index 26a19176..1fcb2a93 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -1003,7 +1003,7 @@ 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) { @@ -1065,9 +1065,9 @@ func TestNew(t *testing.T) { SplitVertical( Left( Border(linestyle.Light), - BorderTitle("Ab"), - TitleColor(cell.ColorMagenta), - TitleFocusedColor(cell.ColorCyan), + BorderTitle("Ab"), + TitleColor(cell.ColorMagenta), + TitleFocusedColor(cell.ColorCyan), ), Right( Border(linestyle.Light), @@ -1103,7 +1103,6 @@ func TestNew(t *testing.T) { return ft }, }, - { desc: "inherits title color on left child container", termSize: image.Point{10, 10}, @@ -1116,7 +1115,7 @@ func TestNew(t *testing.T) { SplitVertical( Left( Border(linestyle.Light), - BorderTitle("Ab"), + BorderTitle("Ab"), ), Right( Border(linestyle.Light), diff --git a/container/draw.go b/container/draw.go index 83524b34..9368f2de 100644 --- a/container/draw.go +++ b/container/draw.go @@ -87,19 +87,19 @@ func drawBorder(c *Container) error { 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 { + if c.opts.inherited.titleFocusedColor != nil { titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleFocusedColor)) - } else { + } else { titleCOpts = cOpts } - } else { + } else { cOpts = append(cOpts, cell.FgColor(c.opts.inherited.borderColor)) - if c.opts.inherited.titleColor != nil { + if c.opts.inherited.titleColor != nil { titleCOpts = append(titleCOpts, cell.FgColor(*c.opts.inherited.titleColor)) - } else { + } else { titleCOpts = cOpts } - } + } if err := draw.Border(cvs, ar, draw.BorderLineStyle(c.opts.border), From a645df600ac35ce2e30e08140de8ed8f562deac4 Mon Sep 17 00:00:00 2001 From: Andreea Sobon Date: Tue, 5 Jan 2021 09:52:19 -0500 Subject: [PATCH 05/21] Update CHANGELOG.md and rephrease test description. --- CHANGELOG.md | 6 ++++++ container/container_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ece876..7914479b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0. +### 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 diff --git a/container/container_test.go b/container/container_test.go index 1fcb2a93..2d1d76e7 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -1104,7 +1104,7 @@ func TestNew(t *testing.T) { }, }, { - desc: "inherits title color on left child container", + 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( From ab06c916979453966e104719668b166caa6d05f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Jan 2021 07:10:35 +0000 Subject: [PATCH 06/21] Bump github.com/mattn/go-runewidth from 0.0.9 to 0.0.10 Bumps [github.com/mattn/go-runewidth](https://github.com/mattn/go-runewidth) from 0.0.9 to 0.0.10. - [Release notes](https://github.com/mattn/go-runewidth/releases) - [Commits](https://github.com/mattn/go-runewidth/compare/v0.0.9...v0.0.10) Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d387d99c..d9024254 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/gdamore/tcell/v2 v2.1.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 diff --git a/go.sum b/go.sum index d39aed70..edb9193e 100644 --- a/go.sum +++ b/go.sum @@ -7,10 +7,12 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+ 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.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/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= +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-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= From 5b49d8958a08d6f4cd8fc25391765611b1a0f634 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Tue, 12 Jan 2021 22:04:20 -0500 Subject: [PATCH 07/21] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7914479b..bb2b050d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0. +- Bump github.com/mattn/go-runewidth from 0.0.9 to 0.0.10. ### Added From a5995f58b1f682c15a3347bf3192c5f4a5f7ded0 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 6 Mar 2021 02:07:39 -0500 Subject: [PATCH 08/21] Allow CI to modify go.mod and go.sum for missing hashes. (#297) * Allow CI to modify go.mod and go.sum for missing hashes. * Updating CHANGELOG. --- .travis.yml | 7 +++++-- CHANGELOG.md | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2bb2e36..89839162 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 .) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2b050d..d87a6e9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Bump github.com/gdamore/tcell/v2 from 2.0.0 to 2.1.0. +- 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. ### Added From 975e06844545f5635c3612a65e51c9efa7727126 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Mar 2021 02:17:49 -0500 Subject: [PATCH 09/21] Bump github.com/gdamore/tcell/v2 from 2.1.0 to 2.2.0 (#295) * Bump github.com/gdamore/tcell/v2 from 2.1.0 to 2.2.0 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 3 +-- go.sum | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index d9024254..1cd63357 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/mum4k/termdash go 1.14 require ( - github.com/gdamore/tcell/v2 v2.1.0 + github.com/gdamore/tcell/v2 v2.2.0 github.com/kylelemons/godebug v1.1.0 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 ) diff --git a/go.sum b/go.sum index edb9193e..69981ea5 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,21 @@ 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.1.0 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro= -github.com/gdamore/tcell/v2 v2.1.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.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.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 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= 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-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/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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= From f9872ab14991241b7bdc81a72a9affb0b2ca4965 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 6 Mar 2021 02:21:06 -0500 Subject: [PATCH 10/21] Updating CHANGELOG. And running `go mod tidy`. --- CHANGELOG.md | 7 +++++-- go.sum | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d87a6e9c..ccafe990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,18 +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 @@ -451,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 diff --git a/go.sum b/go.sum index 69981ea5..44032fc5 100644 --- a/go.sum +++ b/go.sum @@ -16,7 +16,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuF 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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 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= From 1e6a2e1b529e15db504b8a06187ba76988aab785 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Apr 2021 12:37:45 -0400 Subject: [PATCH 11/21] Bump github.com/mattn/go-runewidth from 0.0.10 to 0.0.12 (#300) Bumps [github.com/mattn/go-runewidth](https://github.com/mattn/go-runewidth) from 0.0.10 to 0.0.12. - [Release notes](https://github.com/mattn/go-runewidth/releases) - [Commits](https://github.com/mattn/go-runewidth/compare/v0.0.10...v0.0.12) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1cd63357..5677ad8c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/gdamore/tcell/v2 v2.2.0 github.com/kylelemons/godebug v1.1.0 - github.com/mattn/go-runewidth v0.0.10 + github.com/mattn/go-runewidth v0.0.12 github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e golang.org/x/text v0.3.4 // indirect ) diff --git a/go.sum b/go.sum index 69981ea5..1c2ddb1d 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,9 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 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.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow= +github.com/mattn/go-runewidth v0.0.12/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= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= @@ -16,7 +17,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuF 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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 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= From 336236233b423c557e0ae51e6f9fbc44de150bf8 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 3 Apr 2021 12:38:29 -0400 Subject: [PATCH 12/21] Updating CHANGELOG on behalf of dependabot. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccafe990..1a70e5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump github.com/mattn/go-runewidth from 0.0.10 to 0.0.12. + ## [0.15.0] - 06-Mar-2021 ### Changed From 4238ac6f76485bfbf321d3919d18534234ad9ec8 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 3 Apr 2021 17:04:53 -0400 Subject: [PATCH 13/21] Implements a buffer limit for the Text widget. (#301) See issue #293 where memory and performance can degrade with a high number of lines written to the Text widget. This is a very simplistic implementation to limit the possible length the text buffer can grow to with the `maxContent` option. Default value of -1 means there's no limit and therefore behaviour should remain standard. It has been working in our test app and allows the use of the Text widget to monitor logs (ie tail) and therefore doesn't bloat over time, but happy to adjust as required. --- CHANGELOG.md | 5 + private/runewidth/runewidth.go | 50 +++++- private/runewidth/runewidth_test.go | 25 ++- widgets/text/options.go | 25 +++ widgets/text/text.go | 49 +++++- widgets/text/text_test.go | 249 ++++++++++++++++++++++++++++ 6 files changed, 396 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a70e5c9..816f6573 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] +### Added + +- The `Text` widget has a new option `MaxTextCells` which can be used to limit + the maximum number of cells the widget keeps in memory. + ### Changed - Bump github.com/mattn/go-runewidth from 0.0.10 to 0.0.12. diff --git a/private/runewidth/runewidth.go b/private/runewidth/runewidth.go index 4f2f63a8..731abb6a 100644 --- a/private/runewidth/runewidth.go +++ b/private/runewidth/runewidth.go @@ -18,6 +18,41 @@ package runewidth import runewidth "github.com/mattn/go-runewidth" +// Option is used to provide options. +type Option interface { + // set sets the provided option. + set(*options) +} + +// options stores the provided options. +type options struct { + runeWidths map[rune]int +} + +// newOptions create a new instance of options. +func newOptions() *options { + return &options{ + runeWidths: map[rune]int{}, + } +} + +// option implements Option. +type option func(*options) + +// set implements Option.set. +func (o option) set(opts *options) { + o(opts) +} + +// CountAsWidth overrides the default behavior, counting the specified runes as +// the specified width. Can be provided multiple times to specify an override +// for multiple runes. +func CountAsWidth(r rune, width int) Option { + return option(func(opts *options) { + opts.runeWidths[r] = width + }) +} + // RuneWidth returns the number of cells needed to draw r. // Background in http://www.unicode.org/reports/tr11/. // @@ -29,7 +64,16 @@ import runewidth "github.com/mattn/go-runewidth" // This should be safe, since even in locales where these runes have ambiguous // width, we still place all the character content around them so they should // have be half-width. -func RuneWidth(r rune) int { +func RuneWidth(r rune, opts ...Option) int { + o := newOptions() + for _, opt := range opts { + opt.set(o) + } + + if w, ok := o.runeWidths[r]; ok { + return w + } + if inTable(r, exceptions) { return 1 } @@ -38,10 +82,10 @@ func RuneWidth(r rune) int { // StringWidth is like RuneWidth, but returns the number of cells occupied by // all the runes in the string. -func StringWidth(s string) int { +func StringWidth(s string, opts ...Option) int { var width int for _, r := range []rune(s) { - width += RuneWidth(r) + width += RuneWidth(r, opts...) } return width } diff --git a/private/runewidth/runewidth_test.go b/private/runewidth/runewidth_test.go index 06a342cc..d23a13f4 100644 --- a/private/runewidth/runewidth_test.go +++ b/private/runewidth/runewidth_test.go @@ -24,6 +24,7 @@ func TestRuneWidth(t *testing.T) { tests := []struct { desc string runes []rune + opts []Option eastAsian bool want int }{ @@ -34,9 +35,17 @@ func TestRuneWidth(t *testing.T) { }, { desc: "non-printable characters from mattn/runewidth/runewidth_test", - runes: []rune{'\x00', '\x01', '\u0300', '\u2028', '\u2029'}, + runes: []rune{'\x00', '\x01', '\u0300', '\u2028', '\u2029', '\n'}, want: 0, }, + { + desc: "override rune width with an option", + runes: []rune{'\n'}, + opts: []Option{ + CountAsWidth('\n', 3), + }, + want: 3, + }, { desc: "half-width runes from mattn/runewidth/runewidth_test", runes: []rune{'セ', 'カ', 'イ', '☆'}, @@ -107,7 +116,7 @@ func TestRuneWidth(t *testing.T) { }() for _, r := range tc.runes { - if got := RuneWidth(r); got != tc.want { + if got := RuneWidth(r, tc.opts...); got != tc.want { t.Errorf("RuneWidth(%c, %#x) => %v, want %v", r, r, got, tc.want) } } @@ -119,6 +128,7 @@ func TestStringWidth(t *testing.T) { tests := []struct { desc string str string + opts []Option eastAsian bool want int }{ @@ -127,6 +137,15 @@ func TestStringWidth(t *testing.T) { str: "hello", want: 5, }, + { + desc: "override rune widths with an option", + str: "hello", + opts: []Option{ + CountAsWidth('h', 5), + CountAsWidth('e', 5), + }, + want: 13, + }, { desc: "string from mattn/runewidth/runewidth_test", str: "■㈱の世界①", @@ -158,7 +177,7 @@ func TestStringWidth(t *testing.T) { runewidth.DefaultCondition.EastAsianWidth = false }() - if got := StringWidth(tc.str); got != tc.want { + if got := StringWidth(tc.str, tc.opts...); got != tc.want { t.Errorf("StringWidth(%q) => %v, want %v", tc.str, got, tc.want) } }) diff --git a/widgets/text/options.go b/widgets/text/options.go index 1896d69b..a25aa867 100644 --- a/widgets/text/options.go +++ b/widgets/text/options.go @@ -36,6 +36,7 @@ type options struct { scrollDown rune wrapMode wrap.Mode rollContent bool + maxTextCells int disableScrolling bool mouseUpButton mouse.Button mouseDownButton mouse.Button @@ -56,6 +57,7 @@ func newOptions(opts ...Option) *options { keyDown: DefaultScrollKeyDown, keyPgUp: DefaultScrollKeyPageUp, keyPgDown: DefaultScrollKeyPageDown, + maxTextCells: DefaultMaxTextCells, } for _, o := range opts { o.set(opt) @@ -77,6 +79,9 @@ func (o *options) validate() error { if o.mouseUpButton == o.mouseDownButton { return fmt.Errorf("invalid ScrollMouseButtons(up:%v, down:%v), the buttons must be unique", o.mouseUpButton, o.mouseDownButton) } + if o.maxTextCells < 0 { + return fmt.Errorf("invalid MaxTextCells(%d), must be zero or a positive integer", o.maxTextCells) + } return nil } @@ -174,3 +179,23 @@ func ScrollKeys(up, down, pageUp, pageDown keyboard.Key) Option { opts.keyPgDown = pageDown }) } + +// The default value for the MaxTextCells option. +// Use zero as no limit, for logs you may wish to try 10,000 or higher. +const ( + DefaultMaxTextCells = 0 +) + +// MaxTextCells limits the text content to this number of terminal cells. +// This is useful when sending large amounts of text to the Text widget, e.g. +// when tailing logs as it will limit the memory usage. +// When the newly added content goes over this number of cells, the Text widget +// behaves as a circular buffer and drops earlier content to accommodate the +// new one. +// Note the count is in cells, not runes, some wide runes can take multiple +// terminal cells. +func MaxTextCells(max int) Option { + return option(func(opts *options) { + opts.maxTextCells = max + }) +} diff --git a/widgets/text/text.go b/widgets/text/text.go index 913874b3..0cca1214 100644 --- a/widgets/text/text.go +++ b/widgets/text/text.go @@ -18,10 +18,12 @@ package text import ( "fmt" "image" + "strings" "sync" "github.com/mum4k/termdash/private/canvas" "github.com/mum4k/termdash/private/canvas/buffer" + "github.com/mum4k/termdash/private/runewidth" "github.com/mum4k/termdash/private/wrap" "github.com/mum4k/termdash/terminal/terminalapi" "github.com/mum4k/termdash/widgetapi" @@ -90,6 +92,16 @@ func (t *Text) reset() { t.contentChanged = true } +// contentCells calculates the number of cells the content takes to display on +// terminal. +func (t *Text) contentCells() int { + cells := 0 + for _, c := range t.content { + cells += runewidth.RuneWidth(c.Rune, runewidth.CountAsWidth('\n', 1)) + } + return cells +} + // Write writes text for the widget to display. Multiple calls append // additional text. The text contain cannot control characters // (unicode.IsControl) or space character (unicode.IsSpace) other than: @@ -108,7 +120,17 @@ func (t *Text) Write(text string, wOpts ...WriteOption) error { if opts.replace { t.reset() } - for _, r := range text { + + truncated := truncateToCells(text, t.opts.maxTextCells) + textCells := runewidth.StringWidth(truncated, runewidth.CountAsWidth('\n', 1)) + contentCells := t.contentCells() + // If MaxTextCells has been set, limit the content if needed. + if t.opts.maxTextCells > 0 && contentCells+textCells > t.opts.maxTextCells { + diff := contentCells + textCells - t.opts.maxTextCells + t.content = t.content[diff:] + } + + for _, r := range truncated { t.content = append(t.content, buffer.NewCell(r, opts.cellOpts)) } t.contentChanged = true @@ -284,3 +306,28 @@ func (t *Text) Options() widgetapi.Options { WantKeyboard: ks, } } + +// truncateToCells truncates the beginning of text, so that it can be displayed +// in at most maxCells. Setting maxCells to zero disables truncating. +func truncateToCells(text string, maxCells int) string { + textCells := runewidth.StringWidth(text, runewidth.CountAsWidth('\n', 1)) + if maxCells == 0 || textCells <= maxCells { + return text + } + + haveCells := 0 + textRunes := []rune(text) + i := len(textRunes) - 1 + for ; i >= 0; i-- { + haveCells += runewidth.RuneWidth(textRunes[i], runewidth.CountAsWidth('\n', 1)) + if haveCells > maxCells { + break + } + } + + var b strings.Builder + for j := i + 1; j < len(textRunes); j++ { + b.WriteRune(textRunes[j]) + } + return b.String() +} diff --git a/widgets/text/text_test.go b/widgets/text/text_test.go index 2c96a339..3cee5f92 100644 --- a/widgets/text/text_test.go +++ b/widgets/text/text_test.go @@ -809,6 +809,176 @@ func TestTextDraws(t *testing.T) { return ft }, }, + { + desc: "tests maxTextCells length being applied - multiline", + canvas: image.Rect(0, 0, 10, 3), + opts: []Option{ + MaxTextCells(10), + RollContent(), + }, + writes: func(widget *Text) error { + return widget.Write("line0\nline1\nline2\nline3\nline4") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + // \n still counts as a chacter in the string length + testdraw.MustText(c, "ine3", image.Point{0, 0}) + testdraw.MustText(c, "line4", image.Point{0, 1}) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells - multiple writes - first one fits", + canvas: image.Rect(0, 0, 10, 3), + opts: []Option{ + MaxTextCells(10), + RollContent(), + }, + writes: func(widget *Text) error { + if err := widget.Write("line0\nline"); err != nil { + return err + } + return widget.Write("1\nline2\nline3\nline4") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + // \n still counts as a chacter in the string length + testdraw.MustText(c, "ine3", image.Point{0, 0}) + testdraw.MustText(c, "line4", image.Point{0, 1}) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells - multiple writes - first one does not fit", + canvas: image.Rect(0, 0, 10, 3), + opts: []Option{ + MaxTextCells(10), + RollContent(), + }, + writes: func(widget *Text) error { + if err := widget.Write("line0\nline123"); err != nil { + return err + } + return widget.Write("1\nline2\nline3\nline4") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + testdraw.MustText(c, "ine3", image.Point{0, 0}) + testdraw.MustText(c, "line4", image.Point{0, 1}) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells - accounts for pre-existing full-width runes on the content", + canvas: image.Rect(0, 0, 10, 3), + opts: []Option{ + MaxTextCells(3), + RollContent(), + }, + writes: func(widget *Text) error { + if err := widget.Write("界"); err != nil { + return err + } + return widget.Write("ab") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + testdraw.MustText(c, "ab", image.Point{0, 0}) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells exact length of 5", + canvas: image.Rect(0, 0, 10, 1), + opts: []Option{ + RollContent(), + MaxTextCells(5), + }, + writes: func(widget *Text) error { + return widget.Write("12345") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + // Line return (\n) counts as one character + testdraw.MustText( + c, + "12345", + image.Point{0, 0}, + ) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells partial bufffer replacement", + canvas: image.Rect(0, 0, 10, 1), + opts: []Option{ + RollContent(), + MaxTextCells(10), + }, + writes: func(widget *Text) error { + return widget.Write("hello wor你12345678") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + testdraw.MustText( + c, + "你12345678", + image.Point{0, 0}, + ) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells length not being limited", + canvas: image.Rect(0, 0, 72, 1), + opts: []Option{ + RollContent(), + }, + writes: func(widget *Text) error { + return widget.Write("1234567890abcdefghijklmnopqrstuvwxyz") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + testdraw.MustText( + c, + "1234567890abcdefghijklmnopqrstuvwxyz", + image.Point{0, 0}, + ) + testcanvas.MustApply(c, ft) + return ft + }, + }, + { + desc: "tests maxTextCells length being applied - single line", + canvas: image.Rect(0, 0, 10, 3), + opts: []Option{ + MaxTextCells(5), + RollContent(), + }, + writes: func(widget *Text) error { + return widget.Write("1234567890abcdefghijklmnopqrstuvwxyz") + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + c := testcanvas.MustNew(ft.Area()) + testdraw.MustText(c, "vwxyz", image.Point{0, 0}) + testcanvas.MustApply(c, ft) + return ft + }, + }, } for _, tc := range tests { @@ -901,3 +1071,82 @@ func TestOptions(t *testing.T) { }) } } + +func TestTruncateToCells(t *testing.T) { + tests := []struct { + desc string + text string + maxCells int + want string + }{ + { + desc: "returns empty on empty text", + text: "", + maxCells: 0, + want: "", + }, + { + desc: "no need to truncate, length matches max", + text: "a", + maxCells: 1, + want: "a", + }, + { + desc: "no need to truncate, shorter than max", + text: "a", + maxCells: 2, + want: "a", + }, + { + desc: "no need to truncate, maxCells set to zero", + text: "a", + maxCells: 0, + want: "a", + }, + { + desc: "truncates single rune to enforce max cells", + text: "abc", + maxCells: 2, + want: "bc", + }, + { + desc: "truncates multiple runes to enforce max cells", + text: "abcde", + maxCells: 3, + want: "cde", + }, + { + desc: "accounts for cells taken by newline characters", + text: "a\ncde", + maxCells: 3, + want: "cde", + }, + { + desc: "truncates full-width rune on its edge", + text: "世界", + maxCells: 2, + want: "界", + }, + { + desc: "truncates full-width rune because only half of it fits", + text: "世界", + maxCells: 3, + want: "界", + }, + { + desc: "full-width runes - truncating not needed", + text: "世界", + maxCells: 4, + want: "世界", + }, + } + + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + got := truncateToCells(tc.text, tc.maxCells) + if diff := pretty.Compare(tc.want, got); diff != "" { + t.Errorf("truncateToCells => unexpected diff (-want, +got):\n%s", diff) + } + }) + } +} From fd93d4a1128a35c42cc80f2d7496928fb23e282c Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 3 Apr 2021 17:06:12 -0400 Subject: [PATCH 14/21] Update CHANGELOG for release v0.16.0. --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 816f6573..94045baf 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.16.0] - 03-Apr-2021 + ### Added - The `Text` widget has a new option `MaxTextCells` which can be used to limit @@ -462,7 +464,8 @@ identifiers shouldn't be used externally. - The Gauge widget. - The Text widget. -[unreleased]: https://github.com/mum4k/termdash/compare/v0.15.0...devel +[unreleased]: https://github.com/mum4k/termdash/compare/v0.16.0...devel +[0.16.0]: https://github.com/mum4k/termdash/compare/v0.15.0...v0.16.0 [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 From 09d8a5b0d9f865c05c2846e67da6bf2420f2d1e6 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 3 Apr 2021 17:12:35 -0400 Subject: [PATCH 15/21] Add missing test coverage for negative MaxTextCells. --- widgets/text/text_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/widgets/text/text_test.go b/widgets/text/text_test.go index 3cee5f92..0f953f98 100644 --- a/widgets/text/text_test.go +++ b/widgets/text/text_test.go @@ -54,6 +54,17 @@ func TestTextDraws(t *testing.T) { }, wantErr: true, }, + { + desc: "fails when MaxTextCells is negative", + opts: []Option{ + MaxTextCells(-1), + }, + canvas: image.Rect(0, 0, 1, 1), + want: func(size image.Point) *faketerm.Terminal { + return faketerm.MustNew(size) + }, + wantErr: true, + }, { desc: "fails when scroll mouse buttons aren't unique", opts: []Option{ From 8ad0acff789a4d81bd65cd3e07b2fe1a3786214a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Nov 2021 02:27:09 -0500 Subject: [PATCH 16/21] Bump github.com/mattn/go-runewidth from 0.0.12 to 0.0.13 (#309) Bumps [github.com/mattn/go-runewidth](https://github.com/mattn/go-runewidth) from 0.0.12 to 0.0.13. - [Release notes](https://github.com/mattn/go-runewidth/releases) - [Commits](https://github.com/mattn/go-runewidth/compare/v0.0.12...v0.0.13) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 5677ad8c..dd7cc219 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/gdamore/tcell/v2 v2.2.0 github.com/kylelemons/godebug v1.1.0 - github.com/mattn/go-runewidth v0.0.12 + github.com/mattn/go-runewidth v0.0.13 github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e golang.org/x/text v0.3.4 // indirect ) diff --git a/go.sum b/go.sum index 688839b1..d0d7531a 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,13 @@ github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tW github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow= -github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 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= -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= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.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= From 4297302225107c9082d3d4e6c5d0f61ce85c1cd0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Nov 2021 02:29:39 -0500 Subject: [PATCH 17/21] Bump github.com/gdamore/tcell/v2 from 2.2.0 to 2.4.0 (#315) Bumps [github.com/gdamore/tcell/v2](https://github.com/gdamore/tcell) from 2.2.0 to 2.4.0. - [Release notes](https://github.com/gdamore/tcell/releases) - [Changelog](https://github.com/gdamore/tcell/blob/master/CHANGESv2.md) - [Commits](https://github.com/gdamore/tcell/compare/v2.2.0...v2.4.0) --- updated-dependencies: - dependency-name: github.com/gdamore/tcell/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index dd7cc219..1a6b4673 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mum4k/termdash go 1.14 require ( - github.com/gdamore/tcell/v2 v2.2.0 + github.com/gdamore/tcell/v2 v2.4.0 github.com/kylelemons/godebug v1.1.0 github.com/mattn/go-runewidth v0.0.13 github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e diff --git a/go.sum b/go.sum index d0d7531a..05254dd9 100644 --- a/go.sum +++ b/go.sum @@ -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.2.0 h1:vSyEgKwraXPSOkvCk7IwOSyX+Pv3V2cV9CikJMXg4U4= -github.com/gdamore/tcell/v2 v2.2.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= +github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM= +github.com/gdamore/tcell/v2 v2.4.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.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= From 11e38fd7d4b01dfb4fc23a8c48c4c896a7b62961 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Thu, 13 Jan 2022 23:36:19 -0500 Subject: [PATCH 18/21] Updating CHANGELOG. --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94045baf..68a38165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.16.1] - 13-Jan-2022 + +### Changed + +- Bump github.com/gdamore/tcell from 2.2.0 to 2.4.0. +- Bump github.com/mattn/go-runewidth from 0.0.12 to 0.0.13. + ## [0.16.0] - 03-Apr-2021 ### Added @@ -464,7 +471,8 @@ identifiers shouldn't be used externally. - The Gauge widget. - The Text widget. -[unreleased]: https://github.com/mum4k/termdash/compare/v0.16.0...devel +[unreleased]: https://github.com/mum4k/termdash/compare/v0.16.1...devel +[0.16.1]: https://github.com/mum4k/termdash/compare/v0.16.0...v0.16.1 [0.16.0]: https://github.com/mum4k/termdash/compare/v0.15.0...v0.16.0 [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 From b6a4177439ab8f97af3c7a80d551004c16b82610 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Fri, 14 Jan 2022 00:01:10 -0500 Subject: [PATCH 19/21] Note about Go version change. --- .travis.yml | 4 ++-- CHANGELOG.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89839162..904ee138 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.14.x - - 1.15.x + - 1.16.x + - 1.17.x - stable before_install: - go get github.com/mattn/goveralls diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a38165..9699a581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump github.com/gdamore/tcell from 2.2.0 to 2.4.0. - Bump github.com/mattn/go-runewidth from 0.0.12 to 0.0.13. +- Change the Go versions the CI builds with up to 1.17. ## [0.16.0] - 03-Apr-2021 From 8f493dc3f0da1b7b71e799cf3d603ffa90a9a82b Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Fri, 14 Jan 2022 00:17:30 -0500 Subject: [PATCH 20/21] Bump CI. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9699a581..b068f78a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Change the Go versions the CI builds with up to 1.17. - Bump github.com/gdamore/tcell from 2.2.0 to 2.4.0. - Bump github.com/mattn/go-runewidth from 0.0.12 to 0.0.13. -- Change the Go versions the CI builds with up to 1.17. ## [0.16.0] - 03-Apr-2021 From ab8e6dd194fc9cab82409d38dfc3b9d3e9e8da84 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Fri, 14 Jan 2022 00:29:17 -0500 Subject: [PATCH 21/21] Re-enabling coverage reporting. --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 904ee138..8be8141d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ go: - 1.17.x - stable before_install: + - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls script: - go get -t ./... @@ -11,13 +12,13 @@ script: # 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 ./... + - go test -v -covermode=count -coverprofile=coverage.out -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 .) - diff -u <(echo -n) <(golint ./...) - - $GOPATH/bin/goveralls -service=travis-pro + - $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN env: global: - CGO_ENABLED=0