Skip to content

Commit

Permalink
Make the line wrap settings for the Textfile module configurable via …
Browse files Browse the repository at this point in the history
…the 'wrapText' setting
  • Loading branch information
senorprogrammer committed Jun 15, 2019
1 parent 98f0d5f commit d9c362e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions modules/textfile/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/textfile/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion wtf/text_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d9c362e

Please sign in to comment.