-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
show: elide long strings #40724
Labels
display and printing
Aesthetics and correctness of printed representations of objects.
feature
Indicates new feature / enhancement requests
strings
"Strings!"
Comments
This is neat - didn't know I needed it but now I know I do. Nice! |
StefanKarpinski
added a commit
that referenced
this issue
May 6, 2021
StefanKarpinski
added a commit
that referenced
this issue
May 6, 2021
StefanKarpinski
added a commit
that referenced
this issue
May 7, 2021
StefanKarpinski
added a commit
that referenced
this issue
May 7, 2021
StefanKarpinski
added a commit
that referenced
this issue
May 7, 2021
shirodkara
pushed a commit
to shirodkara/julia
that referenced
this issue
Jun 9, 2021
johanmon
pushed a commit
to johanmon/julia
that referenced
this issue
Jul 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
display and printing
Aesthetics and correctness of printed representations of objects.
feature
Indicates new feature / enhancement requests
strings
"Strings!"
We helpfully avoid dumping huge arrays into your REPL output if you look at them, eliding the middle and showing just the corners. If someone has a gargantuan string, however, we just dump the whole thing in the REPL. Perhaps we should elide long strings as well? Inspiration: https://stackoverflow.com/questions/67400862/what-is-the-option-in-julia-repl-that-allows-only-a-limited-output. I'm not keen on just putting
...
in the middle of the string data like that, but perhaps we could show the quoted head and tail of the string separated by⋯
if the string would be more than, say, five lines:Example usages:
I have inserted line breaks where my terminal wraps the screen so that you can see how this would look in a terminal (GitHub's code display doesn't wrap lines). The last example shows that even for a very long string we only show five lines with the ellipsis in the middle. The middle two examples with string lengths of 423 and 424 show that I've got the cutoff logic for when to do the elision correct: 423 fits exactly in five lines whereas 424 wouldn't, so it gets elided.
Note that care needs to be taken with the implementation to avoid doing
O(ncodeunits(str))
work, which is easy to accidentally do, e.g. by checking iflength(str)
is larger than some minimum. This implementation avoids that by advancing characters from the beginning and ends of the string and then checking to see if those indices overlap. We never figure out exactly how many characters the string is, but we know it's enough characters that we need to wrap it, and we know how much of the head and tail to print. The middle of a long string is never examined at all.Another consideration is character width: this code assumes that all characters have a column width of one. Of course, some characters are two columns, others are zero, and sometimes sequences of characters combine into a single output glyph. Some characters will also be quoted in a string instead of printed. Since we can't know the correct printed width of any string when in a given terminal and font, using the approximation of counting each character as a single column seems fine. Worst case, instead of printing exactly
lines
lines of text, we'll print a little more or a little less. NBD.The text was updated successfully, but these errors were encountered: