radian icon indicating copy to clipboard operation
radian copied to clipboard

Line wrap not working in Windows Terminal

Open toscm opened this issue 4 years ago • 7 comments
trafficstars

Hi, it seems that line wrap is not working when using Windows Terminal (wt) instead of the default terminal emulator used by pwsh.exe/cmd.exe.

wt_radian_bug

I also did a quick check of running radian within wt inside WSL2-Ubuntu-bash instead of pwsh and suprisingly there it worked:

image

So my feeling is, that is has to do with some environment variables that need to be set or some special workarounds that radian does when running on windows, which aren't required for wt. (I tested all options that can be set through .radian_profile, e.g. radian.auto_width without success).

Used versions checks on windows:

  • Windows Terminal Preview Version: 1.9.1523.0
  • Radian: 0.5.11
  • Python: 3.8.8
  • R: 4.0.5

Used versions for check on WSL2:

  • Radian: 0.5.11
  • Python: 3.8.5
  • R: 3.6.3

Any advice on how to fix/debug this issue would be greatly appreciated.

toscm avatar Jun 15 '21 12:06 toscm

I guess it may be due to the fact that we are still using prompt toolkit 2.0. We might want to eventually stop supporting python 2 and upgrade prompt toolkit to 3.0.

randy3k avatar Jun 18 '21 07:06 randy3k

Thanks for the hint. I checked which version of prompt toolkit I have installed and it's actually 3.0.18, but I think you're right anyways.

I tried to step through the code to find out where the line gets cut off and it seems to happen in line 171-172 of console.py (in the output.write_raw(buf); output.flush() part.

radian_ipdb

As a workaround I replaced the output.write_raw(buf); output.flush() with sys.stdout.write(buf); sys.stdout.flush() and it seems to work for now 🥳

radian_workaround radian_fixed

toscm avatar Jun 19 '21 13:06 toscm

Actually we ship with our own vendored version of prompt-toolkit https://github.com/randy3k/lineedit/tree/master/lineedit/deps

randy3k avatar Jun 19 '21 14:06 randy3k

I think it should work. The reason to use output from prompt-toolkit instead of stdout is that stdout of cmd.exe does not support all vt100 sequences and promot-toolkit does some magics on it. IINM, the new Windows terminal is fully vt100 compatible.

randy3k avatar Jun 19 '21 14:06 randy3k

Ah, I did not notice that you were using you're own prompt-toolkit version. Thanks for the explanation. In this case I can see that updating prompt-toolkit has a good chance to solve the problem.

So from my side it would be ok to close the issue now, unless you want to leave it open for other Windows Terminal users who might run into the same problem?

toscm avatar Jun 19 '21 16:06 toscm

I'm having the same issue... I'm on the latest version of lineedit (0.1.6). For me it's both powershell and cmd.exe where radian (but not Rterm) does not wrap toscm's cat(paste(rep("-", 200), collapse = "-")) - although note I actually only care about interacting with radian via VS code.

Any other suggestions @randy3k, given that you suggest not using stdout?

radian 0.6.4 VS Code 1.76.0 Powershell 5.1.22621.963

Thanks

EDIT: in the meantime I've used @toscm's fix, which is working without any issues thank you toscm.

jayhaast avatar Mar 04 '23 06:03 jayhaast