Skip to content

Conversation

erw7
Copy link
Contributor

@erw7 erw7 commented Jul 21, 2019

Replace cud1 with \x1b[B because \n is CRLF on Windows.

Should we add the following code somewhere to solve this problem fundamentally?

_setmode( _fileno( stdout ), _O_BINARY );

fix #9461

@marvim marvim added the WIP label Jul 21, 2019
@erw7 erw7 changed the title [WIP] Fix text overrides line number on Windows [RFC] Fix text overrides line number on Windows Jul 21, 2019
@marvim marvim added RFC and removed WIP labels Jul 21, 2019

#ifdef WIN32
// Replace cud1 because \n is CRLF on Windows.
unibi_set_str(ut, unibi_cursor_down, "\x1b[B");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in if (xterm) ? Shouldn't it be done always on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cud1 of the non-xterm terminal may not be \x1b[B. I think we have to add cud1 conversion each time we find a terminal that causes a problem.

I think the fundamental solution is to implement a mode that does not convert LF to CRLF in libuv. If we write a patch, it may not be taken upstream, what shuld we do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fundamental solution is to implement a mode that does not convert LF to CRLF in libuv. If we write a patch, it may not be taken upstream, what shuld we do?

If it's a small/low-risk patch, they will probably accept it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erw7 yeah, I think the main issue here is the automatic conversion of LF to CR``LF. "Proper" terminal emulators can deal with both and I know Alacritty supports the "legacy newline mode" too if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that libuvu is not the only one that converts CR to CR+LF. It also seems to occur when uv__vterm_state == UV_SUPPORTED. So it seems to me that ConEmu and VTP are doing the same conversion.

Therefore, in order to solve this problem on Windows, it may be best to ignore the TERM environment variable even if it is set.

@justinmk
Copy link
Member

Should we add the following code somewhere to solve this problem fundamentally?

_setmode( _fileno( stdout ), _O_BINARY );

Sure. But I thought 8072f08 did that already?

@justinmk justinmk added this to the 0.4 milestone Jul 21, 2019
@erw7
Copy link
Contributor Author

erw7 commented Jul 22, 2019

Sure. But I thought 8072f08 did that already?

No, the 8072f08 is a change to the input handle, so the output handle is not affected.

As a result of my research, WriteConsole() does not convert LF to CRLF. libuv is converting from LF to CRLF. Thus, calling _setmode() is not a solution to this problem.

Ref. https://github.com/libuv/libuv/blob/ecff27857dafe3f5d30a6ab8646ea69a93e4940a/src/win/tty.c#L2065-L2069

erw7 added 2 commits July 23, 2019 11:45
Replace cud1 with \x1b[B because \n is CRLF on Windows (due to libuv).

fix #9461
@justinmk justinmk changed the title [RFC] Fix text overrides line number on Windows Windows: Fix text overrides line number Jul 23, 2019
/// Sets an environment variable.
///
/// @warning Existing pointers to the result of os_getenv("foo") are
/// INVALID after os_setenv("foo", …).
int os_setenv(const char *name, const char *value, int overwrite)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future improvement: instead of returning int, we could return a pointer to the new os_getenv() result. So the caller pattern could be like:

term = os_setenv("TERM", term, ...)

However, after inspecting of all existing calls to os_setenv and vim_setenv, it looks like tui.c was the only case where a os_getenv result was passed to os_setenv.

@justinmk justinmk added the tui termcodes, terminfo, termcap label Jul 23, 2019
@justinmk justinmk merged commit 5cccfa7 into neovim:master Jul 23, 2019
justinmk added a commit to justinmk/neovim that referenced this pull request Jul 23, 2019
timeyyy pushed a commit to timeyyy/neovim that referenced this pull request Aug 9, 2019
Replace cud1 with \x1b[B because \n is CRLF on Windows (due to libuv).

fix neovim#9461
timeyyy pushed a commit to timeyyy/neovim that referenced this pull request Aug 9, 2019
@erw7 erw7 deleted the fix-text-overrides-line-number2 branch September 11, 2019 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:windows tui termcodes, terminfo, termcap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows/TUI: Text overrides line numbers
4 participants