Comments (6)
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.
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.
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.
Yea totally! Go for it!
from gocui.
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.
OK, I opened awesome-gocui#67
from gocui.
Related Issues (20)
- Wrong layout when Title uses a different encoding HOT 1
- True color support ? HOT 2
- Keybindings not working on FreeBSD HOT 3
- Examples does not support east asian windows? HOT 1
- Can you support run jar packet? HOT 1
- Add a project that using gocui HOT 1
- Update Screenshot Example HOT 1
- Start printing at cursor position
- Add lazygit to the list of projects HOT 1
- Better tags support HOT 2
- how to read input
- Support ANSI code for hyperlinks
- Add Omnivore to projects list.
- Lazydocker is not listed HOT 2
- Extended ANSI color codes are not supported
- Is the library still actively maintained?
- Chinese Support HOT 2
- KeyBinding For Mouse(Any of them) dosn't trigger HOT 2
- git-bug relies on gocui
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gocui.