-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maxlines option on views #30
Comments
I agree that using reflect this much would be unwise, I am not really sure how to go about this after checking the linked issue and PR, linking @jesseduffield @skanehira @mjarkk for feedback |
Agree! |
This would be really useful, for now it's unusable for logging purpose, especially when application is supposed to run for a longer time. Simplified example: type logBuffer struct {
buffer [][]byte
size, position int
}
func newLogBuffer(size int) logBuffer {
return logBuffer{
buffer: make([][]byte, size),
size: size,
position: 0,
}
}
func (b *logBuffer) WriteMessage(message []byte) {
b.buffer[b.position] = message
if b.position+1 == b.size {
b.position = 0
} else {
b.position++
}
}
func (b *logBuffer) ReadLastMessages(n int) [][]byte {
if n > b.size {
n = b.size
}
var data = make([][]byte, 0)
for i := n; i > 0; i-- {
data = append(data, b.buffer[((b.position-i)%b.size+b.size)%b.size])
}
return data
} Note: it requires additional communication when new messages are available in the buffer and filling up all unused horizontal space of view when writing to view to prevent displaying not overwritten cells. _, y := view.Size()
for _, msg := range buf.ReadLastMessages(y) {
view.Write(msg)
view.Write([]byte{'\n'})
} However, my solution is relatively more inefficient on CPU than internal view buffer as whole data needs to be processed and converted into I wonder how much work it would take to implement something like this for internal buffer. |
This is an old issue which I guess got forgotten, so I just want to clarify what is requested. We would want something like However, what should happen when lines would be added to the beginning or middle and the amount would cause them to be removed because of hitting |
Describe the feature you'd like
The ability to clear out the internal buffers either up to the point that the data is being displayed again, or to some arbitrary point provided in the constructor.
There was an issue for something like this on the original repo: jroimartin#103 and an associated PR: jroimartin#104
Describe alternatives you've considered
Ive tried doing this myself with
Clear()
and anFprintf
:But
Clear()
seems far to slow to make this work seamlessly. Not to mention that this requires significant extra processing and memory usage to convert the lines out of their internal representation and back.Reflection magic:
I dont think I really need to point out the issues with this approach. It does work, but reflection to this degree is in general a dangerous idea, and is brittle at best.
Additional context
The use case here is a long running TUI that is constantly written to, for me specifically that is for my game management IRC bot's TUI. As that has near constant writes from game server logs.
The text was updated successfully, but these errors were encountered: