From de34629ad811a7dc183e01111a606af5aed4700e Mon Sep 17 00:00:00 2001 From: Ellery D'Souza Date: Fri, 3 Jul 2020 14:30:23 -0400 Subject: [PATCH 1/3] Support maximum lines in a view --- view.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/view.go b/view.go index 42082f8c..c069cc92 100644 --- a/view.go +++ b/view.go @@ -71,6 +71,9 @@ type View struct { // If Mask is true, the View will display the mask instead of the real // content Mask rune + + // Set the maximum number of lines to store + MaxLines int } type viewLine struct { @@ -227,6 +230,13 @@ func (v *View) Write(p []byte) (n int, err error) { } } } + + // Cap the maximum number of lines in the view + if v.MaxLines > 0 && len(v.lines) > v.MaxLines { + cut := len(v.lines) - v.MaxLines + v.lines = v.lines[cut:] + } + return len(p), nil } From 30fff87cf77357dfa37bbdeda7984f91499a6d61 Mon Sep 17 00:00:00 2001 From: Ellery D'Souza Date: Fri, 3 Jul 2020 14:36:27 -0400 Subject: [PATCH 2/3] Check if ParseInput returns an empty array --- view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view.go b/view.go index c069cc92..d72462dd 100644 --- a/view.go +++ b/view.go @@ -218,7 +218,7 @@ func (v *View) Write(p []byte) (n int, err error) { } default: cells := v.parseInput(ch) - if cells == nil { + if cells == nil || len(cells) <= 0 { continue } From 1cecd8e5b10bee309875bc16b33df03b239d4ef5 Mon Sep 17 00:00:00 2001 From: Ellery D'Souza Date: Fri, 3 Jul 2020 14:37:40 -0400 Subject: [PATCH 3/3] If view lines are larger than window, make sure that the last line is shown in window --- view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view.go b/view.go index d72462dd..ff505930 100644 --- a/view.go +++ b/view.go @@ -332,7 +332,7 @@ func (v *View) draw() error { } if v.Autoscroll && len(v.viewLines) > maxY { - v.oy = len(v.viewLines) - maxY + v.oy = len(v.viewLines) - maxY - 1 } y := 0 for i, vline := range v.viewLines {