-
Notifications
You must be signed in to change notification settings - Fork 264
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
use terminal cursor #953
base: master
Are you sure you want to change the base?
use terminal cursor #953
Conversation
Awesome! Thank you for this. I change cursor styles like that (on top of your pull request): diff --git a/vis-modes.c b/vis-modes.c
index 2e120aa..8dd2803 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -146,6 +146,7 @@ static void vis_mode_normal_enter(Vis *vis, Mode *old) {
return;
if (old != mode_get(vis, VIS_MODE_INSERT) && old != mode_get(vis, VIS_MODE_REPLACE))
return;
+ printf("\e[2 q\n"); /* block cursor */
if (vis->autoindent && strcmp(vis->key_prev, "<Enter>") == 0) {
Text *txt = win->file->text;
for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) {
@@ -229,6 +230,10 @@ static void vis_mode_visual_leave(Vis *vis, Mode *new) {
static void vis_mode_insert_replace_enter(Vis *vis, Mode *old) {
if (!vis->win || vis->win->parent)
return;
+ if (vis->mode->id == VIS_MODE_REPLACE)
+ printf("\e[4 q\n"); /* underline cursor */
+ else
+ printf("\e[6 q\n"); /* bar cursor */
if (!vis->action.op) {
action_reset(&vis->action_prev);
vis->action_prev.op = &vis_operators[VIS_OP_MODESWITCH]; Not sure if this is the correct way to do it. |
Could this perhaps be made optional via lua config? Either use terminal cursor or configure via style. |
This would be cool!
I think it's not the correct way to do it (just talking about my patch on top of this pull request). I get weird behavior when I enter this after starting vis: |
It seems to be working with this patch: diff --git a/vis-modes.c b/vis-modes.c
index 2e120aa..d414a2b 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -146,6 +146,8 @@ static void vis_mode_normal_enter(Vis *vis, Mode *old) {
return;
if (old != mode_get(vis, VIS_MODE_INSERT) && old != mode_get(vis, VIS_MODE_REPLACE))
return;
+ printf("\e[2 q"); /* block cursor */
+ fflush(stdout);
if (vis->autoindent && strcmp(vis->key_prev, "<Enter>") == 0) {
Text *txt = win->file->text;
for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) {
@@ -229,6 +231,11 @@ static void vis_mode_visual_leave(Vis *vis, Mode *new) {
static void vis_mode_insert_replace_enter(Vis *vis, Mode *old) {
if (!vis->win || vis->win->parent)
return;
+ if (vis->mode->id == VIS_MODE_REPLACE)
+ printf("\e[4 q"); /* underline cursor */
+ else
+ printf("\e[6 q"); /* bar cursor */
+ fflush(stdout);
if (!vis->action.op) {
action_reset(&vis->action_prev);
vis->action_prev.op = &vis_operators[VIS_OP_MODESWITCH]; Sorry for spamming this pull request. But maybe it's better than no answer at all :-) |
Hello. Maybe comments are more related to issue #927 (edit: #781), but it seems worth mentioning I had been using this for a long time (I prefer the block shape nowadays :D):
I guess having an event which is triggered when mode gets changed would be more Notice that it writes the escape sequences to stderr, which seems to be where Cheers. |
Cool! That's good to know. I hope your PR will be accepted someday. |
How do I get access to the 'strf' function? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Petros,
I've tested it with and without curses support enabled and
everything seems fine to me. Personally I see no point in making this
configurable. Also the STYLE_CURSOR_MATCHING
addition is very welcome.
Thanks for the patch! I will merge it soon.
@gotroyb127 |
Sorry for taking so long to reply.
Without With the I don't understand what you mean by drawing Cheers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, so after some more testing I noticed that this seems to break the highlighting of a matching pair when vis is used in a tty. I pushed this branch with the rebased and squashed changes to work off of. I can potentially look into it more if I find some time.
I don't understand what you mean by drawing
|
.
Sorry I said that because of an added comment in the code. The confusion about the cursor was because it wasn't clear if the commit message was referring to the terminal's cursor or vis' cursor. I understand now, thanks.
Also, this doesn’t apply cleanly (or rather not at all) on the current master branch. @gotroyb127 Could we ask for the rebase, please? |
Previously, vis used to hide the terminal's cursor, but now terminal's cursor is positioned to the active cursor's position. The STYLE_CURSOR_MATCHING style is added so that it can be adjusted independently.
I've reimplemented it (with some improvements) based on current master, and overwritten the previous What's different with this new patch is that
Cheers. |
I like this and want to merge it but I think there is a remaining issue. When you do some actions such as |
Hi.
This is, indeed, not the intended behavior, and I am unsure why this happens. In |
Related issues: #927, #462, #952.
With this, the primary cursor is not drawn via styling the cell it is positioned at, but instead it has the terminal draw it. Consequently, the
STYLE_CURSOR_PRIMARY
is removed, as it is now unused. Also, I addedSTYLE_CURSOR_MATCHING
to specify the style for the matching pair of a(){}[]`"'
, which is the same for primary and secondary cursors (it is trivial to change it so that one can specify different style for those).About the implementation:
I have removed all ocurances of
curs_set(.)
andcursor_visible(.)
inui-terminal-{curses,vt100}.c
respectively, which I am unsure if it is the way you would want it.Also, I just renamed
STYLE_CURSOR_PRIMARY
toSTYLE_CURSOR_MATCHING
in all files (lua/themes/*.lua
included) to make clear that it is not used anymore and also to have the new option appear somewhere.Something else to notice is that I tried to prevent drawing of the primary selection when it is only the cell under the cursor so that if one changes the cursor style via terminal-specific escape sequences, such as
\e[6 q
, the underlying cell is not styled specially.I expect your comments so I can adjust this to something that might be worth merging.
Cheers.
Edit: also related: #911.