Fix advanced inventory manager crash on small terminals #61166
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Bugfixes "Fix advanced inventory manager crash on small terminals"
Purpose of change
The advanced inventory manager crashes when opened with a terminal width of <82. This has been noted several times on Android, but is not Android-exclusive. The crash looks like this (text in Portuguese for a better view of the string trimming problem discussed below):
Before--Improper_trimming_and_crash.mp4
Fixes #59629
Fixes #60047
#59821 has similar symptoms but no crash/debug log, so it might be a duplicate of above
Describe the solution
The crash is due to two separate bugs interacting:
So, to solve this:
Describe alternatives you've considered
Testing
Test cases were added for trim_by_length given width <= 0, confirming that it provides a debugmsg warning.
The AIM was tested at a variety of terminal widths. It did not crash at any size tested, and appeared to trim text correctly. (The page listing on the next line down does not trim correctly, but that's a separate part of the code)
After--Proper_trimming.mp4
Additional context