Re: [hackers] [st][PATCH] Restore cursor when exiting alt mode.

From: Stein Gunnar Bakkeby <bakkeby_AT_gmail.com>
Date: Tue, 11 May 2021 15:28:36 +0200

Hi Hijito,

I think it's more likely that I am the one missing something.

I found that I had this in my .vimrc file:

if has("autocmd")
  au VimEnter,InsertLeave * silent execute '!echo -ne "\e[2 q"' | redraw!
  au InsertEnter,InsertChange *
\ if v:insertmode == 'i' |
\ silent execute '!echo -ne "\e[6 q"' | redraw! |
\ elseif v:insertmode == 'r' |
\ silent execute '!echo -ne "\e[4 q"' | redraw! |
\ endif
au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw!
endif

So this changes the cursor based on context.

In practice on the command line you can change the cursor to a bar like this:

$ echo -ne "\e[6 q"

and I guess the expectation is that this sets the cursor what it is by default:

$ echo -ne "\e[ q"

In st the cursor becomes a block.

You can disregard this patch, it doesn't look correct in this context.


Thanks,

-Stein


On Tue, May 11, 2021 at 2:39 PM Hiltjo Posthuma <hiltjo_AT_codemadness.org> wrote:
>
> On Tue, May 11, 2021 at 10:41:29AM +0200, Stein Gunnar Bakkeby wrote:
> > From 7fa0a12281f4b595b75e40e497919076497281e8 Mon Sep 17 00:00:00 2001
> > From: bakkeby <bakkeby_AT_gmail.com>
> > Date: Tue, 11 May 2021 10:20:23 +0200
> > Subject: [PATCH] Restore cursor when exiting alt mode.
> >
> > If the mouse cursor is changed to a bar or an underline then st will use that
> > when the terminal is first opened. When an application that changes the cursor
> > via escape sequences is executed, e.g. vim which uses a block cursor by default,
> > then that cursor will remain after exiting the program.
> >
> > This change sets the cursor back to default when exiting alt mode.
> > ---
> > st.c | 2 ++
> > win.h | 1 +
> > x.c | 6 ++++++
> > 3 files changed, 9 insertions(+)
> >
> > diff --git a/st.c b/st.c
> > index ebdf360..f0db3e0 100644
> > --- a/st.c
> > +++ b/st.c
> > _AT_@ -1057,6 +1057,8 @@ tswapscreen(void)
> > term.line = term.alt;
> > term.alt = tmp;
> > term.mode ^= MODE_ALTSCREEN;
> > + if (!IS_SET(MODE_ALTSCREEN))
> > + xsetdefaultcursor();
> > tfulldirt();
> > }
> >
> > diff --git a/win.h b/win.h
> > index e6e4369..320585f 100644
> > --- a/win.h
> > +++ b/win.h
> > _AT_@ -33,6 +33,7 @@ int xsetcolorname(int, const char *);
> > void xseticontitle(char *);
> > void xsettitle(char *);
> > int xsetcursor(int);
> > +void xsetdefaultcursor(void);
> > void xsetmode(int, unsigned int);
> > void xsetpointermotion(int);
> > void xsetsel(char *);
> > diff --git a/x.c b/x.c
> > index 7186040..eae9f95 100644
> > --- a/x.c
> > +++ b/x.c
> > _AT_@ -1712,6 +1712,12 @@ xsetcursor(int cursor)
> > return 0;
> > }
> >
> > +void
> > +xsetdefaultcursor(void)
> > +{
> > + xsetcursor(cursorshape);
> > +}
> > +
> > void
> > xseturgency(int add)
> > {
> > --
> > 2.31.1
> >
>
> Hi,
>
> Which escape sequence does vim use for setting the altscreen, is it CSI 1047 or
> 1049?
>
> st also has a comment to handle this case:
>
> case 1049: /* swap screen & set/restore cursor as xterm */
>
> To which terminal are you comparing the behaviour?
>
> Can you provide a minimal test-case as a shellscript or a hexdump recording of
> your vim session?
>
> I briefly tested and compared it to xterm but found no difference there using a blinking
> underline cursor: printf '\x1b[5; q'
>
> and altscreen '\x1b[?1047h' or smcup/rmcup '\x1b[?1049h' / '\x1b[?1049l'.
>
> Maybe I'm missing something.
>
> Thanks,
>
> --
> Kind regards,
> Hiltjo
>
Received on Tue May 11 2021 - 15:28:36 CEST

This archive was generated by hypermail 2.3.0 : Wed May 12 2021 - 06:24:36 CEST