icecream
icecream copied to clipboard
Improve output for strings
Issue
Characters inside strings can modify their output by default. This leads to lost or misleading information when debugging.
Proposed Solution
Make IceCream output strings in a way that preserves all information by default. That means:
- Showing control characters and invisibles explicitly instead of letting them affect terminal layout.
- Deciding carefully whether newlines should render literally or as escaped symbols.
Examples
- Control characters alter the output instead of being visible. For instance, \b (backspace) removes characters ā abc\bX prints as abX (information lost).
- Invisible Unicode characters disappear silently. For instance, Zero-width space (\u200B), left/right marks (\u200E, \u200F) are not shown ā the user cannot tell they exist.
- Newlines are always shown as multi-line blocks. Iām not confident this should be the default behavior.
- Whitespace is ambiguous. For instance, tabs (\t) are expanded into spaces, making them indistinguishable.
- Long strings flood the output. Very long lines are printed in full without truncation or summary.
- Bytes / bytearray with control characters. For instance, bytes with \n or \x00 are printed raw, producing real line breaks or invisible content.
Open Questions
- Should escaped/visible mode be the default behavior?
- Should there be an option to output strings in a more readable form than one huge single line?
- Do we want to summarize long strings (length, line count, preview) instead of printing the full content by default?