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

[memory] shorten cells too wide to fit in prompt #2287

Closed
wants to merge 2 commits into from

Conversation

midichef
Copy link
Contributor

@midichef midichef commented Feb 2, 2024

If I press Alt+m (memo-cells) on a cell that has contents too wide to fit on the screen, the command fails due to an exception:

File "memo-cell", line 1, in <module>
'VisiData: a curses interface for exploring and arranging tabular data'
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/_input.py", line 543, in input
ret = vd.editText(y, promptlen, w=w,
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/_input.py", line 358, in editText
v = vd.editline(vd.activeSheet._scr, y, x, w, display=display, **kwargs)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/_input.py", line 285, in editline
prew = clipdraw(scr, y, x, dispval[:dispi], attr, w, clear=clear, literal=True)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/cliptext.py", line 211, in clipdraw
return clipdraw_chunks(scr, y, x, chunks, attr, w=w, clear=clear, **kwargs)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/cliptext.py", line 234, in clipdraw_chunks
scr.addstr(y, x, disp_column_fill*actualw, cattr.attr)  # clear whole area before displaying
_curses.error: addwstr() returned ERR

This PR shortens the cell contents, so the prompt will fit on screen and prevent this error.

In the worst case, when the default column width is about as wide as the screen, then the right side of the memo-cells prompt will be overwritten by rightStatus(). The prompt won't be very readable. But the user can widen their terminal to make the prompt readable, and continue the memo action from there.

In this PR, I used a default max width of options.default_width. We could instead use cursorCol.width. That would match the prompt's quoted cell width to the width in the sheet. The advantage there is if the cell is truncated with '…', it's truncated the same in both places, so the cell's last few characters match in both places. The drawback is that the column may be one the user made very wide, which would make the prompt unreadable from being overwritten by the right status bar.

What makes more sense?

visidata/memory.py Outdated Show resolved Hide resolved
@saulpw
Copy link
Owner

saulpw commented Feb 2, 2024

Does inputMultiple effectively workaround this problem?

@midichef midichef marked this pull request as ready for review February 26, 2024 10:55
saulpw added a commit that referenced this pull request May 16, 2024
@saulpw
Copy link
Owner

saulpw commented May 16, 2024

Thanks for your efforts on this, @midichef! I pushed a separate commit with you as the co-author, that doesn't introduce more parameters to inputMultiple, but still should fix the issue. (We use the typed value from the sheet, and not the returned input value, so we don't need to make it read-only).

@saulpw saulpw closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants