Use terminal cursor, redux - #1372
Conversation
bb58070 to
34bf741
Compare
|
if you're interested in this feature I have it as a plugin instead of a patch: modecursor.lua by default it doesn't set the shape of the normal mode cursor but you can do it in visrc like this: local cursor = require('modecursor')
cursor.shapes[vis.modes.NORMAL] = 'block'it uses a bit of a hack to hide vis' cursor but it works ok. @tassmjau I don't mean to hijack your pr, this code is obviously a better solution, my hack is just a workaround while this is being worked on. |
|
Thanks @micampe I had a look at your plugin, it looks nice! My main motivation for this patch is getting the cursor position to behave nice when switching between vis and tmux's copy-mode. Ie I want the tmux cursor to start off at the line/column where the cursor is in vis, and not at the bottom where the hidden cursor resides. Maybe the more pragmatic way of achieving that is to sync the position of the "real cursor" (even though it's hidden), so that when switching from the cell-drawn cursor out to tmux's copy-mode it works as I would expect(?). Personally I prefer this, but if such a patch is more likely to get merged it could likely be done. |
|
I am going to run this for a while before I give any review. I just remember I kept running into issues with the original version and I don't want to miss anything that I have forgotten about since then. |
this patch removes |
rnpnr
left a comment
There was a problem hiding this comment.
Having tested this for a while I did not find any issues with the core functionality. However it still has the annoying behaviour of breaking styling when the cursor is on top of a \t character and it makes it difficult to distinguish which parentheses of a pair the cursor is currently on.
Because of the parentheses issue I have been repeatedly making the mistake of inserting text in the wrong location since applying this patch.
The tab issue is quite important even if only for editing vis' source code. Personally the only reason my tabwidth is set to 2 instead of 1 is so that I can see that I inserted a tab and not a space allowing others to view the text with whatever spacing they prefer. With this patch I can't see the highlighting anymore.
I'm pretty sure both of these issues can be fixed with very minor changes to the code but that would need to be done before I would consider merging this.
|
Thanks for trying it out @rnpnr, By breaking the styling when being on a The matching cursor styling has not been an issue for me. Could it be a theme issue? vis_cursor_1.mp4 |
Yes, and I believe it should be fixable by storing the correct style in the extra cells in
Right, I forgot about |
Sorry this may be a little misleading. The selection is styled after |
Make vis use the terminal/tty's real cursor (instead of hiding it and drawing it using cell attributes).
34bf741 to
9efb762
Compare
|
I found where I broke it, and reverted that part: Like you say, filling the tab is a side-effect of It would reduce the cycles spent on drawing the cursor in normal mode, but not changing this behavior in the first place is probably better :) |
|
I was trying this with a "bar" style cursor and that makes it apparent that the "selection" block is always rendered behind the cursor: vis_draw_non_primary_selection.mp4The second approach from my previous message doesn't produce this artifact, since it only renders that block when being on top of a vis_dont_draw_non_primary_selection.mp4I don't have any strong feelings about it since I normally use a block cursor anyway, but thought it was a difference worth mentioning. |
The default way xterm is drawing a cursor is reversing background/foreground into a block. Prior to this, for an un-styled xterm-cursor, the cursor drawing was broken since xterm would draw the UI_STYLE_SELECTION in reverse, instead of the "real" cursor. The solution here is to skip window_draw_selection for the current cursor position.
|
@tassmjau personally I use a bar cursor in insert mode and block otherwise (and I think that's the reasonable option); in normal mode the selection should be visible, like in your first video. |
Make vis use the terminal/tty's cursor instead of hiding it and drawing it using cell attributes.
This PR is based on the idea in #953, since that PR has been inactive for some quite time, and I want this functionality, I opened this one. Credit goes to @gotroyb127 for the original proposal.
Some underlying constructs that patch either relied on or had to work around has changed, which allows this patch to be simpler in some places.
For example: we no longer need to accumulate
dxanddyoffsets across windows to figure out which coordinates are the selected window, since they're now available onvis->win.My initial attempt at a rebase was packed with conflicts to the point where it was simpler to take what was needed line by line and implement the rest.
There were some discussion in #953 about having optional styling for the primary cursor. In this proposal I got rid of
STYLE_CURSOR_PRIMARYall together, since that's how I prefer it. If that's a deal breaker I can dig into it.There were also an outstanding issue about the cursor not working as expected for auto-complete which is addressed here.