term: split cursor blink state into two

There are two different escape sequences that can be used to set the
cursor blink state: ‘CSI ? 12 h/l’ and ‘CSI Ps SP q’.

Up until now, they both modified the same internal state in foot. This
meant you could enable a blinking cursor with e.g. ‘CSI ? 12 h’ and
then disable it with ‘CSI 2 SP q’.

Since the ‘CSI ? 12’ escapes are used in the civis/cnorm/cvvis
terminfo entries, applications often ended up disabling the blink
state on exit (typically be emitting ‘cnorm’), requiring users to
manually re-enable blinking.

By splitting the internal state into two separate states, we can
improve the situation.

The cursor will blink if at least one of the two have been enabled.

The setting in foot.ini sets the default state of the ‘CSI Ps SP q’
escape.

This means if the user has enabled blinking in the configuration, the
cursor will blink regardless of civis/cnorm/cvvis. Which probably is
what the user wants.

If the user has NOT enabled blinking, civis/cnorm/cvvis act as
intended: cvvis blink, civis and cnorm do not.

If an application overrides the cursor blink/style with ‘CSI Ps SP q’,
that will override the user’s setting in foot.ini. But most likely
that too is intended (for example, the user may have configured the
application to use a different cursor style). And, a well written
application will emit the ‘Se’ terminfo sequence on exit, which in
foot is defined to ‘CSI SP q’, which will reset both the style and
blink state to the user configured style/state.

Closes #218
This commit is contained in:
Daniel Eklöf 2020-11-26 18:09:32 +01:00
parent 360cc8e6de
commit cb2f496269
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 15 additions and 38 deletions

View file

@ -338,11 +338,11 @@ struct terminal {
enum cursor_style cursor_style;
struct {
bool active;
enum { CURSOR_BLINK_ON, CURSOR_BLINK_OFF } state;
bool decset; /* Blink enabled via '\E[?12h' */
bool deccsusr; /* Blink enabled via '\E[X q' */
int fd;
enum { CURSOR_BLINK_ON, CURSOR_BLINK_OFF } state;
} cursor_blink;
bool default_cursor_blink;
struct {
uint32_t text;
uint32_t cursor;
@ -538,9 +538,7 @@ void term_cursor_left(struct terminal *term, int count);
void term_cursor_right(struct terminal *term, int count);
void term_cursor_up(struct terminal *term, int count);
void term_cursor_down(struct terminal *term, int count);
void term_cursor_blink_enable(struct terminal *term);
void term_cursor_blink_disable(struct terminal *term);
void term_cursor_blink_restart(struct terminal *term);
void term_cursor_blink_update(struct terminal *term);
void term_print(struct terminal *term, wchar_t wc, int width);