From 62c9e3892ac043a8be14afff5600bfd62ff1f0bd Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 23 Apr 2018 09:35:23 -0700 Subject: [PATCH] Generic PadRow function added --- todo/display.go | 18 ++++-------------- wtf/utils.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/todo/display.go b/todo/display.go index 421a58ea..31146f2f 100644 --- a/todo/display.go +++ b/todo/display.go @@ -2,8 +2,10 @@ package todo import ( "fmt" - "strings" + //"strings" //"github.com/gdamore/tcell" + + "github.com/senorprogrammer/wtf/wtf" ) const checkWidth = 4 @@ -32,20 +34,8 @@ func (widget *Widget) display() { item.Text, ) - str = widget.padLine(str, item) + "\n" + str = str + wtf.PadRow((4+len(item.Text)), widget.View) + "\n" } fmt.Fprintf(widget.View, "%s", str) } - -// Pad with spaces to get full-line highlighting -func (widget *Widget) padLine(str string, item *Item) string { - _, _, w, _ := widget.View.GetInnerRect() - - padSize := w - checkWidth - len(item.Text) - if padSize < 0 { - padSize = 0 - } - - return str + strings.Repeat(" ", padSize) -} diff --git a/wtf/utils.go b/wtf/utils.go index 9508eb6a..663fe5af 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -61,6 +61,20 @@ func NamesFromEmails(emails []string) []string { return names } +// PadRow returns a padding for a row to make it the full width of the containing widget. +// Useful for ensurig row highlighting spans the full width (I suspect tcell has a better +// way to do this, but I haven't yet found it) +func PadRow(offset int, view *tview.TextView) string { + _, _, w, _ := view.GetInnerRect() + + padSize := w - offset + if padSize < 0 { + padSize = 0 + } + + return strings.Repeat(" ", padSize) +} + func ReadFileBytes(filePath string) ([]byte, error) { fileData, err := ioutil.ReadFile(filePath) if err != nil {