From 4a31d90070e16d9e1def147cad33ae901f8cac72 Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Mon, 1 Jun 2015 21:53:57 -0700 Subject: [PATCH] Fill background for borderless one-line paragraph Previously when we had a Par with Width > len(Text) and custom BgColor on the underlying Block, it would skip the first row. This means that it's impossible to have a colored line wider than text width. Block should offset indexes by 1 only if border is present. --- block.go | 8 ++++++-- p_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 p_test.go diff --git a/block.go b/block.go index 9531365..b66e859 100644 --- a/block.go +++ b/block.go @@ -92,8 +92,12 @@ func (d *Block) Buffer() []Point { for i := 0; i < d.innerWidth; i++ { for j := 0; j < d.innerHeight; j++ { p := Point{} - p.X = d.X + 1 + i - p.Y = d.Y + 1 + j + p.X = d.X + i + p.Y = d.Y + j + if d.HasBorder { + p.X++ + p.Y++ + } p.Ch = ' ' p.Bg = d.BgColor ps = append(ps, p) diff --git a/p_test.go b/p_test.go new file mode 100644 index 0000000..a7a9bb1 --- /dev/null +++ b/p_test.go @@ -0,0 +1,20 @@ +package termui + +import "testing" + +func TestPar_NoBorderBackground(t *testing.T) { + par := NewPar("a") + par.HasBorder = false + par.BgColor = ColorBlue + par.TextBgColor = ColorBlue + par.Width = 2 + par.Height = 2 + + pts := par.Buffer() + for _, p := range pts { + t.Log(p) + if p.Bg != par.BgColor { + t.Errorf("expected color to be %v but got %v", par.BgColor, p.Bg) + } + } +}