Closed dankox closed 3 years ago
@mjarkk Again with another problem with SetCursor
:) I wrote down how I think it could work. I didn't start to write down the fix, because I wanted to confirm if you are ok with this way, or if you have better suggestion.
This problem is most apparent with mouse control, but I could imagine other application using gocui
to hit similar problem too.
pinging @mjarkk
Sorry for the late reply last few week have been busy.
Anyway i should definitely fix that panic that's never good.
About the logic behind SetCursor i'm not sure if we should do that i see the issue of applications that have to change now because of this change but i don't think that are manny.
Besides in all GUI libraries the cursor position is based on the buffer so why not do that here? I cannot think personally of any possibilities where a TUI library's cursor handling is an exception to the rule?
I see... in that case I will leave it to you. I can't really think of any other problem than the mouse problem. But mouse is in gocui control, so it shouldn't be a problem to fix it.
Describe the bug
SetCursor()
function working on top of the view buffer lines can cause panics when mouse control is turned on.To Reproduce Steps to reproduce the behavior:
go run _examples/mouse.go
Expected behavior It shouldn't panic.
Additional context
SetCursor
function was used before from outside "world" point of view with just knowledge of theView
dimension. This is easy to deal with as all terminals/consoles have specific dimension,Views
are setup according to it, and application can points to it.If it's used with the knowledge of the view buffer content, programs need to be updated to consider it and not point to the position which would be outside of this buffer. Even in
gocui
mouse position is used relative to the terminal window andView
and registering the location without any knowledge of the buffer content.Proposed solution could be, that there will be another two functions
SetCursorInBuffer
,CursorInBuffer
, which would act as the currentSetCursor
andCursor
and the original functions would be enhanced to translate the position from buffer position to "real" position on the screen.This way
SetCursor
would use originalView
dimension to check for invalid point and the new functions could be used inedit.go
to work with the buffer as it is right now.