Giter VIP home page Giter VIP logo

Comments (6)

dsouzae avatar dsouzae commented on May 23, 2024

I implemented something similar but left the original Update function alone (for backwards compatibility), and created an "Update2" function of that does the same code.

Below is code I have to trim the maximum lines in the buffer, with some other bug fixes. I should make a PR for this.

diff --git a/view.go b/view.go
index 42082f8..0b81d66 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 {
@@ -215,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
                        }
 
@@ -227,6 +230,12 @@ func (v *View) Write(p []byte) (n int, err error) {
                        }
                }
        }
+
+       if v.MaxLines > 0 && len(v.lines) > v.MaxLines {
+               cut := len(v.lines) - v.MaxLines
+               v.lines = v.lines[cut:]
+       }
+
        return len(p), nil
 }
 
@@ -322,7 +331,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 {

from gocui.

glvr182 avatar glvr182 commented on May 23, 2024

I would be able to add a function called UpdateAsync(), this way we wouldn't change any existing code and still have the wanted functionalities.

What are your thoughts

from gocui.

ripienaar avatar ripienaar commented on May 23, 2024

Ideally to avoid a unbounded growth it would be nice if there was a maxlines setting as suggested.

But yes, the UpdateAsync() would be great. If you agree with that I can send a PR

from gocui.

glvr182 avatar glvr182 commented on May 23, 2024

Yea totally! Go for it!

from gocui.

glvr182 avatar glvr182 commented on May 23, 2024

Can you open it on @awesome-gocui we run a fork of this project theere since the original ownwer hasnt responded to anything in a while

from gocui.

ripienaar avatar ripienaar commented on May 23, 2024

OK, I opened awesome-gocui#67

from gocui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.