Skip to content
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

cursor remains enabled in WSL2 direct mode #2129

Closed
dankamongmen opened this issue Aug 30, 2021 · 15 comments · Fixed by #2139
Closed

cursor remains enabled in WSL2 direct mode #2129

dankamongmen opened this issue Aug 30, 2021 · 15 comments · Fixed by #2139
Assignees
Labels
bug Something isn't working mswindows microsoft windows
Milestone

Comments

@dankamongmen
Copy link
Owner

See #2031 for complete background, but @FrankRuben reports that upon entering a Notcurses program in WSL2, the cursor remains visible.

the cursor is still on while the program runs (and also still on once the program ends).
So disabling the cursor does still not seem not work, even if I add an explicit call to notcurses_cursor_disable. When adding notcurses_cursor_disable and setting loglevel = NCLOGLEVEL_DEBUG, I'm getting:
notcurses_cursor_disable:1658:Cursor is not enabled

@dankamongmen dankamongmen added bug Something isn't working mswindows microsoft windows labels Aug 30, 2021
@dankamongmen dankamongmen added this to the 3.0.0 milestone Aug 30, 2021
@dankamongmen dankamongmen self-assigned this Aug 30, 2021
@dankamongmen
Copy link
Owner Author

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

ESC [ ? 25 h DECTCEM Text Cursor Enable Mode Show Show the cursor
ESC [ ? 25 l DECTCEM Text Cursor Enable Mode Hide Hide the cursor

interestingly, this is different from what we see in terminfo for xterm/kitty:

	cnorm=\E[?12h\E[?25h
	cvvis=\E[?12;25h

you have those extra 12;s in there. soooooo....if @FrankRuben was using Windows Terminal, but had an xterm or somesuch TERM....actually, even the ms-terminal terminfo entry has it:

[schwarzgerat](0) $ infocmp ms-terminal | egrep cvv\|cnorm
	clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
	cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
[schwarzgerat](0) $ 

@FrankRuben originally reports:

$ ./notcurses-demo
+q544eGi=1,a=q;notcurses 2.3.13 on xterm-256color
30 rows 120 cols (56.25KiB) 48B crend 256 colors
gcc-9.3.0, 16B LE cells
terminfo from ncurses 6.2.20200212 zlib 1.2.11
built without multimedia support

but this is definitely not XTerm, or else we'd see on XTerm [version]. there was no XTVERSION reply, suggesting to me that this is indeed windows terminal (mintty responds with many data; windows terminal very little).

so i'm wondering if

  • you might not want to be using TERM=ms-terminal, and
  • the ms-terminal terminfo database is wrong on these two

@dankamongmen
Copy link
Owner Author

but even if that's the case, we're supplying the correct (documented, anyway) sequence in windows.c, no?

@dankamongmen
Copy link
Owner Author

oh it appears he was using direct mode

#include <unistd.h>
#include <notcurses/direct.h>

struct nc_state {
  struct ncdirect *nc;
  int termy, termx;
  uint64_t channels;
};

static inline void nc_direct_yx(struct nc_state *nc_state, int y, int x, const char* utf8) {
  ncdirect_cursor_move_yx(nc_state->nc, y, x);
  ncdirect_putstr(nc_state->nc, nc_state->channels, utf8);
}

int main(void) {
  const uint64_t nc_flags = 0u;
  FILE *fp = stdout;
  struct nc_state nc_state = (struct nc_state) {
    .nc = ncdirect_core_init(NULL, fp, nc_flags),
    .channels = 0,
  };
  nc_state.termy = ncdirect_dim_y(nc_state.nc);
  nc_state.termx = ncdirect_dim_x(nc_state.nc);
  ncchannels_set_fg_rgb(&nc_state.channels, 0xffffff);
  ncchannels_set_bg_rgb(&nc_state.channels, 0x0);

  ncdirect_cursor_disable(nc_state.nc);
  ncdirect_clear(nc_state.nc);

  nc_direct_yx(&nc_state, 10, 10, "1"); fflush(fp);

  nc_direct_yx(&nc_state, 10, 10, "2"); fflush(fp);
  sleep(2);

  nc_direct_yx(&nc_state, 10, 10, "3"); fflush(fp);
  sleep(2);

  nc_direct_yx(&nc_state, -1, -1, "4"); fflush(fp);
  sleep(2);

  ncdirect_stop(nc_state.nc);
  fputs("\n\n", fp);
}

@dankamongmen dankamongmen changed the title cursor remains enabled in WSL2 rendered mode cursor remains enabled in WSL2 direct mode Aug 31, 2021
@dankamongmen
Copy link
Owner Author

hmmm. it's working in all my experiments thus far. i'll try again.

@dankamongmen dankamongmen modified the milestones: 3.0.0, 2.4.0 Aug 31, 2021
@WSLUser
Copy link

WSLUser commented Sep 2, 2021

I would completely ignore the ms-terminal terminfo entry until the WT devs update it. Sounds like they'll finally do something about allowing terminfo on Windows but they'll first need to implement infocmp or some equivalent for Windows and it will need to be configured to go to env var. I'm guessing when they do implement it, they'll have a default of xterm-256color set and users will be able to change it from there. COLORTERM will also be allowed, which would definitely affect what this library does. Not sure how it handles COLORTERM for users.

@j4james
Copy link

j4james commented Sep 4, 2021

I actually fixed this cursor issue last month. As far I can remember, the problem was that you hide the cursor before changing to the alt buffer, and switching to the alt buffer caused the Windows console to reset the cursor state (making it visible again).

It should now be working correctly in the latest Windows Terminal preview, but it'll take a while before the fix is available in the conhost console. If you want to try and work around the bug, you may be able to fix it by only setting the cursor state after you've switched to the alt buffer.

Sounds like they'll finally do something about allowing terminfo on Windows

@WSLUser I wasn't aware of this. Was it mentioned in one of the WT issues?

@dankamongmen
Copy link
Owner Author

I actually fixed this cursor issue last month. As far I can remember, the problem was that you hide the cursor before changing to the alt buffer, and switching to the alt buffer caused the Windows console to reset the cursor state (making it visible again).

if this is the case, it may well be fixed in the past few days due to work on #2131 (where i needed to switch into the Kitty keyboard mode only after switching to the alternate screen). i'll test today.

@j4james
Copy link

j4james commented Sep 4, 2021

I just tried with commit e1a1ac3 and it's still doesn't seem to be working on the old Windows console. Looking at the code for notcurses_core_init, it seems that the cursor is made invisible here:

if(cinvis && term_emit(cinvis, ret->ttyfp, false)){

And it only switches to the alt screen several lines later:
if(enter_alternate_screen(ret->ttyfp, &ret->tcache, false)){

@dankamongmen
Copy link
Owner Author

I just tried with commit e1a1ac3 and it's still doesn't seem to be working on the old Windows console. Looking at the code for notcurses_core_init, it seems that the cursor is made invisible here:

if(cinvis && term_emit(cinvis, ret->ttyfp, false)){

And it only switches to the alt screen several lines later:

if(enter_alternate_screen(ret->ttyfp, &ret->tcache, false)){

yep, the fix is on the dankamongmen/kitty-keyboard branch, sorry about that =[

@dankamongmen
Copy link
Owner Author

let me see what of that branch i can merge up right now

@j4james
Copy link

j4james commented Sep 4, 2021

No problem. I just thought I'd check when I pulled the latest code. And didn't realise you were still on a branch.

@dankamongmen
Copy link
Owner Author

No problem. I just thought I'd check when I pulled the latest code. And didn't realise you were still on a branch.

yep, much appreciated and sorry for wasting your time -- i forgot that that change had been made to deal with the kitty keyboard protocol. anyway, i'm just about ready to merge that branch (see #2139).

@dankamongmen
Copy link
Owner Author

Didn't mean to close this, but merged the branch, gotta test!

@j4james
Copy link

j4james commented Sep 4, 2021

I can confirm that this now works for me on the old Windows console.

Edit: By "this", I mean the cursor is no longer visible in notcurses-demo.

@dankamongmen
Copy link
Owner Author

w00t! thanks! @FrankRuben, you ought be good to go =] thanks for the big assist, @j4james!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mswindows microsoft windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants