visidata icon indicating copy to clipboard operation
visidata copied to clipboard

visidata crashes when Windows Terminal is resized

Open seajhawk opened this issue 1 year ago • 12 comments

Small description if visidata (running via pipx install in Windows Terminal via PowerShell) is open and I enlarge or reduce the window horizontally, it will crash with no error. When I reopen the file, the columns are out of alignment.

Expected result Visidata doesn't crash and shows more or fewer columns based on horizontal enlarge or reduce

Actual result with screenshot If you get an unexpected error, please include the full stack trace that you get with Ctrl-E.

Before horizontal enlarge image

After horizontal enlarge Back at the command prompt with no error shown

Re-open file after horizontal enlarge image

Before horizontal reduce image

Reopen file after horizontal reduce image

Steps to reproduce with sample data and a .vd Please attach the commandlog (saved with Ctrl-D) to show the steps that led to the issue. See here for more details. I have tried multiple files. You should be able to repro with any file.

  1. Open file.
  2. With the mouse, grab the right edge of the window to enlarge or reduce it.

Additional context Please include the version of VisiData. package visidata 2.9.1, installed using Python 3.10.4

Windows 11 Microsoft.WindowsTerminal 1.14.1963.0 PowerShell 7.2.5 (Also repros with Command Prompt, but it opens in Windows Terminal host as well)

seajhawk avatar Aug 04 '22 13:08 seajhawk

Hi @seajhawk, does Ctrl+L fix the display for you after resizing?

saulpw avatar Aug 05 '22 05:08 saulpw

I should have mentioned it, but no, that didn't work. I could see the screen refresh, but the columns didn't change.

seajhawk avatar Aug 05 '22 07:08 seajhawk

I once had an issue related to window resize on Linux. Not sure if this would help: https://github.com/saulpw/visidata/issues/280

frosencrantz avatar Aug 13 '22 17:08 frosencrantz

@seajhawk Can you try @frosencrantz 's solution and see if it fixes your problem?

@VisiData.api
def fix_size(vd):
    (c,r) = os.get_terminal_size()
    curses.resizeterm(r,c)

BaseSheet.addCommand('zZ', 'real-resize', 'fix_size()')

saulpw avatar Aug 16 '22 04:08 saulpw

I'm also running into the same issue as OP. Similar setup (pipx on windows 10 using visidata 2.9.1 and python 3.8.12)

I attempted to add your commands to visidatarc and I still get a crash when resizing the window on windows terminal/command prompt.

georgebreen avatar Aug 22 '22 19:08 georgebreen

Hi @georgebreen, when you say "crash", do you mean that you had to restart your computer? Or the program made a loud crashing noise? Could you still use any commands?

saulpw avatar Aug 22 '22 19:08 saulpw

Hi @saulpw, apologies for not specifying.

I have two scenarios that cause some issues.

To replicate scenario 1:

  1. I open a fresh command prompt as a window
  2. Open visidata via 'visidata'
  3. Maximize the window

At this point I'm kicked back to the terminal without warning.

WindowsTerminal_F4W7tmFzNc

Another scenario which might be interesting:

  1. I open a fresh command prompt and maximize it.
  2. Open visidata via 'visidata'
  3. "un-maximize" the window

At this point, the terminal is still receiving commands, but CTRL+L to refresh does not display anything.

image

However, if I maximize the window once again, and scroll wheel up, it seems to continue working but the UI element that has File Edit View etc is missing on all frames. image

If I try to use the real-refresh command you posted above, I get the following error.


Traceback (most recent call last):
  File "C:\Users\GeorgeB\.local\pipx\venvs\visidata\lib\site-packages\visidata\basesheet.py", line 169, in execCommand
    escaped = super().execCommand2(cmd, vdglobals=vdglobals)
  File "C:\Users\GeorgeB\.local\pipx\venvs\visidata\lib\site-packages\visidata\basesheet.py", line 69, in execCommand2
    exec(code, vdglobals, LazyChainMap(vd, self))
  File "real-resize", line 1, in <module>
    'VisiData: a curses interface for exploring and arranging tabular data'
  File "C:\Users\GeorgeB\.visidatarc", line 4, in fix_size
    curses.resizeterm(r,c)
AttributeError: module 'curses' has no attribute 'resizeterm'

Hopefully this all helps. This is a wonderful tool.

georgebreen avatar Aug 22 '22 19:08 georgebreen

According to the windows-curses package, it's actually resize_term on Windows. Try using curses.resize_term(0,0) instead. Otherwise I'm sorry, I'm out of ideas :/

saulpw avatar Aug 24 '22 04:08 saulpw

Unfortunately that did not fix the issue, but thank you for the suggestion.

I did check the windows application event log and found that it does show curses as the faulting module (curses.cp38-win_amd64.pyd).

It is strange because every other part of the program seems to work just fine, but after researching this issue I've seen that there's appears to be a long history of this bug and the windows builds of curses.

I also confirmed that this behavior happens on the newest stable release of python (3.10.6) on windows 11 with visidata installed NOT using pipx.

I can send you the crash report privately if you believe that will provide some insight.

georgebreen avatar Aug 24 '22 22:08 georgebreen

I don't think it'll mean anything to me, unfortunately. It does sound like it's a problem external to VisiData and shared by other programs, so if you find a workaround, please let us know and we can apply it.

saulpw avatar Aug 25 '22 02:08 saulpw

I had the opportunity to chat with a couple of Python Core Devs and they recommended switching from curses to Rich/Textualize.

I don't know what how much work that entails, or if there are features VisiData needs that they don't support, but that was the advice.

seajhawk avatar Aug 25 '22 17:08 seajhawk

Thanks, @seajhawk. That would be a net negative for VisiData at the moment; as far as I know, Textual doesn't even support the alternate screen yet. But we're discussing possibilities here: https://github.com/saulpw/visidata/discussions/1412#discussioncomment-3453269

saulpw avatar Aug 25 '22 18:08 saulpw

From the looks of this, we are not going to be making further progress on this issue. Please feel free to add any additional bug reports or notes on this error.

Kondo'd.

anjakefala avatar Nov 11 '22 05:11 anjakefala