From d9c362ee9f54aa40a2b82de3c995ff8ccdebe70d Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 14 Jun 2019 21:27:09 -0700 Subject: [PATCH] Make the line wrap settings for the Textfile module configurable via the 'wrapText' setting --- go.sum | 2 ++ modules/textfile/settings.go | 4 ++++ modules/textfile/widget.go | 4 ++-- wtf/text_widget.go | 1 - 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/go.sum b/go.sum index 2f7befe2..35f0a27a 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,7 @@ github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBo github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU= github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY= github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= +github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 h1:GDQdwm/gAcJcLAKQQZGOJ4knlw+7rfEQQcmwTbt4p5E= github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -146,6 +147,7 @@ github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcncea github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= diff --git a/modules/textfile/settings.go b/modules/textfile/settings.go index 4e3e4290..b55d8032 100644 --- a/modules/textfile/settings.go +++ b/modules/textfile/settings.go @@ -7,14 +7,17 @@ import ( const defaultTitle = "Textfile" +// Settings defines the configuration properties for this module type Settings struct { common *cfg.Common filePaths []interface{} format bool formatStyle string + wrapText bool } +// NewSettingsFromYAML creates a new settings instance from a YAML config block func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { settings := Settings{ @@ -23,6 +26,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co filePaths: ymlConfig.UList("filePaths"), format: ymlConfig.UBool("format", false), formatStyle: ymlConfig.UString("formatStyle", "vim"), + wrapText: ymlConfig.UBool("wrapText", true), } return &settings diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index bdf60cfe..604c2ff2 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -44,7 +44,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * widget.SetDisplayFunction(widget.display) widget.View.SetWordWrap(true) - widget.View.SetWrap(true) + widget.View.SetWrap(settings.wrapText) widget.KeyboardWidget.SetView(widget.View) @@ -79,7 +79,7 @@ func (widget *Widget) display() { text += widget.plainText() } - widget.Redraw(title, text, true) + widget.Redraw(title, text, widget.settings.wrapText) } func (widget *Widget) fileName() string { diff --git a/wtf/text_widget.go b/wtf/text_widget.go index 70d96e9a..54488955 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -111,7 +111,6 @@ func (widget *TextWidget) TextView() *tview.TextView { } func (widget *TextWidget) Redraw(title, text string, wrap bool) { - widget.app.QueueUpdateDraw(func() { widget.View.Clear() widget.View.SetWrap(wrap)