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

Compact printing of Array{Char}s? #19845

Closed
andreasnoack opened this issue Jan 3, 2017 · 6 comments
Closed

Compact printing of Array{Char}s? #19845

andreasnoack opened this issue Jan 3, 2017 · 6 comments
Labels
display and printing Aesthetics and correctness of printed representations of objects.

Comments

@andreasnoack
Copy link
Member

@alanedelman brought up that Array{Char}s can be useful for summarizing numerical arrays but that it would be better if the printing of Array{Char} was more compact. I.e. instead of

julia> A = randn(10,10);

julia> ['+', '-'][(A .> 0) + 1]
10×10 Array{Char,2}:
 '+'  '-'  '-'  '-'  '-'  '-'  '-'  '+'  '+'  '-'
 '-'  '-'  '-'  '-'  '-'  '+'  '-'  '+'  '+'  '+'
 '-'  '+'  '+'  '+'  '+'  '+'  '-'  '-'  '-'  '+'
 '-'  '+'  '-'  '+'  '-'  '+'  '-'  '+'  '+'  '-'
 '-'  '-'  '+'  '+'  '-'  '-'  '-'  '-'  '+'  '-'
 '-'  '-'  '+'  '+'  '-'  '+'  '+'  '-'  '-'  '-'
 '+'  '-'  '+'  '+'  '-'  '+'  '+'  '-'  '+'  '-'
 '-'  '-'  '-'  '+'  '+'  '-'  '+'  '-'  '-'  '-'
 '-'  '-'  '-'  '-'  '+'  '+'  '-'  '-'  '+'  '-'
 '-'  '-'  '+'  '+'  '-'  '+'  '+'  '-'  '+'  '-'

it was proposed that we follow our competitor and print it like

julia> print(join(mapslices(String, ['+', '-'][(A .> 0) + 1], 2), '\n'))
+------++-
-----+-+++
-+++++---+
-+-+-+-++-
--++----+-
--++-++---
+-++-++-+-
---++-+---
----++--+-
--++-++-+-

Thoughts?

@stevengj
Copy link
Member

stevengj commented Jan 3, 2017

That works well if all the chars have charwidth(c) == 1, but it seems problematic in other cases.

Also is a bit problematic if you have a lot of whitespace chars.

@JeffBezanson JeffBezanson added the display and printing Aesthetics and correctness of printed representations of objects. label Jan 3, 2017
@andreasnoack
Copy link
Member Author

Would it make sense to adjust the width of each "cell" to the maximum charwidth of the array? There seems to be something wrong with wide characters in the mac terminals, though, so I don't know if it is yet possible to make special characters look good in the terminal.

screen shot 2017-01-03 at 8 28 00 pm

@stevengj
Copy link
Member

stevengj commented Jan 4, 2017

@andreasnoack, that's #3721. It seems to be really hard to solve unless the whole software stack (terminal on up) agrees on the width of the characters.

@stevengj
Copy link
Member

stevengj commented Jan 4, 2017

Also, charwidth-0 characters (e.g. combining characters) are going to look odd.

@TotalVerb
Copy link
Contributor

@stevengj combining characters already print odd (they combine with the initial single quote), so that will not be a new issue.

@oscardssmith
Copy link
Member

given variable width chars, this is probably a bad idea.

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.
Projects
None yet
Development

No branches or pull requests

5 participants