I needed to change the API because I wanted to support Crayons.jl. Now, every single styling is handle by Crayons.jl. The downside is that this is breaking (sorryβ¦). The good side is that we have now many options to customize our tables, like changing the background to highlight rows and columns:
I have updated the package (master) to support multiple lines in the cells. Hence, we can now have something like:
julia> data = Any[1.0 "Flag 1, Flag 2, Flag 3\nFlag 4, Flag 5, Flag 6, Flag 7";
2.0 "Flag 2, Flag 3, Flag 8\nFlag 10";
3.0 "Flag 4, Flag 6"];
julia> pretty_table(data, ["t" "Active flags"]; linebreaks=true, alignment=:l, hlines = [1,2,3])
βββββββ¬βββββββββββββββββββββββββββββββββ
β t β Active flags β
βββββββΌβββββββββββββββββββββββββββββββββ€
β 1.0 β Flag 1, Flag 2, Flag 3 β
β β Flag 4, Flag 5, Flag 6, Flag 7 β
βββββββΌβββββββββββββββββββββββββββββββββ€
β 2.0 β Flag 2, Flag 3, Flag 8 β
β β Flag 10 β
βββββββΌβββββββββββββββββββββββββββββββββ€
β 3.0 β Flag 4, Flag 6 β
βββββββ΄βββββββββββββββββββββββββββββββββ
I would appreciate if someone can test before I tag the new version
I just noticed this package β it might be just what I was looking for. I looked in the documentation and didnβt see this there, but is it possible to print a custom row name rather than a row number?
Edit: I suppose it could be treated as just another column in this formulation.
So I think Iβve found a possibly legitimate reason to want row labels β the row labels might be a different type than the array. And the array might be sparse, and there are currently some problems in Base with some operations on SparseArrays of type Any, which is what youβd get if the row labels were concatenated to the matrix. Thereβs also the performance impact of constructing the row-concatenated array purely for display purposes.
I also noticed that larger tables donβt get visually abbreviated, which may be a feature or a curse, depending on circumstance.
My use case is for implementing the printing of a custom array type, which may get very large, so Iβd need to edit down the printed array in some fashion.
Yeah, I havenβt though yet what to do if the table is bigger than the display. When I have to print really long tables, I print to files and open in an editor without line wrapping.
I have to escape the string to avoid formatting problems. The Julia function escape_string automatically escape " by default. I have not idea how to easily fix that without introducing many other problems. For example, if I do not escape the string, a header with β1234\tβ will break the format of the table.
Escaping usually depends on what youβre trying to accomplish β is the goal here to know how many on-screen characters each string takes up so that you can compute the layout parameters?
Then you might be able to get away with simply stripping out characters of variable width (eg. strip(s, ['\t']). In ASCII I donβt know of any other than tab off the top of my head, so that might be a good start.
Escaping is also used e.g. in HTML to prevent accidental injection of content as code, but thatβs a different use. In case thatβs also useful for PrettyTables HTML display you can see how I implemented it in my Hyperscript package here and here.
The problem of selecting which characters to escape with string is that I may miss many more, like, for example, \e etc. Thatβs why escaping the entire string (like the display function of DataFrames do) seems more appropriate.