ronisbr / PrettyTables.jl

Print data in formatted tables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autowrap is not work

NitaKihtan-sHeir opened this issue · comments

I have already parameters in function pretty_table(), but it seems does not work. Please fix this problem hurry. This problem has affected my daily work.
`using PrettyTables
rows = [
Dict(
"Column02" => "2024-03-29 18:09:00",
"Column01" => "This line is long enough to exceed the maximum column width and trigger a line break",
"Column03" => "This line, similarly, is long enough to trigger the automatic line breaking feature of PrettyTables.jl"
)
]

Display the table with options for automatic wrapping and line breaks

pretty_table(rows,
maximum_columns_width=25,
linebreaks=true,
autowrap=true,
alignment=:l)The result show like this:┌─────────────────────┬───────────────────────────┬───────────────────────────┐
│ Column02 │ Column01 │ Column03 │
├─────────────────────┼───────────────────────────┼───────────────────────────┤
│ 2024-03-29 18:09:00 │ This line is long enough… │ This line, similarly, is… │
└─────────────────────┴───────────────────────────┴───────────────────────────┘`

Hi @NitaKihtan-sHeir

autowrap only works when the column width is fixed. maximum_columns_width leads to a variable column width, but with a maximum size. If you want to use autowrap in the current version, you must set columns_width:

julia> pretty_table(rows; columns_width = 25, autowrap = true)
┌───────────────────────────┬───────────────────────────┬───────────────────────────┐
│                  Column02 │                  Column01 │                  Column03 │
├───────────────────────────┼───────────────────────────┼───────────────────────────┤
│       2024-03-29 18:09:00 │  This line is long enough │  This line, similarly, is │
│                           │     to exceed the maximum │    long enough to trigger │
│                           │  column width and trigger │        the automatic line │
│                           │              a line break │       breaking feature of │
│                           │                           │           PrettyTables.jl │
└───────────────────────────┴───────────────────────────┴───────────────────────────┘

Thank you for your reply. I am busy rencently so could not reply your message.

Sorry, but setting columns_width seems far from ideal. I have one column that's just the process ID and the other column is the entire command-line associated with that process. Obviously the command-line column is much larger. Is it not possible to have one column be 20 chars and the other be 100 with autowrap enabled?

@cblackbu yes, just set columns_width to a vector specifying the width of each column:

julia> A = [
       1 "Small column" "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse mattis felis non turpis convallis pellentesque sed et neque. Duis non fringilla mi, vel viverra lorem. Nunc sit amet est nec orci ornare tristique sed eget velit. Nulla rutrum fermentum vehicula. Duis eget justo maximus lectus pharetra congue sit amet ac odio. Vivamus ultrices laoreet pretium. Etiam tristique mauris et felis aliquet hendrerit. Mauris vel lorem ullamcorper justo dapibus fringilla non eu massa. Aliquam molestie diam sapien. Fusce malesuada bibendum dolor vel commodo. Phasellus leo lacus, pharetra id sodales nec, vehicula et magna. Curabitur molestie fermentum cursus. Donec ligula tortor, elementum ac lacus at, congue faucibus urna. Aliquam elementum libero arcu, nec imperdiet sem dictum rutrum. Sed quis hendrerit justo, et consectetur mauris."
       2 "Small column" "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse mattis felis non turpis convallis pellentesque sed et neque. Duis non fringilla mi, vel viverra lorem. Nunc sit amet est nec orci ornare tristique sed eget velit. Nulla rutrum fermentum vehicula. Duis eget justo maximus lectus pharetra congue sit amet ac odio. Vivamus ultrices laoreet pretium. Etiam tristique mauris et felis aliquet hendrerit. Mauris vel lorem ullamcorper justo dapibus fringilla non eu massa. Aliquam molestie diam sapien. Fusce malesuada bibendum dolor vel commodo. Phasellus leo lacus, pharetra id sodales nec, vehicula et magna. Curabitur molestie fermentum cursus. Donec ligula tortor, elementum ac lacus at, congue faucibus urna. Aliquam elementum libero arcu, nec imperdiet sem dictum rutrum. Sed quis hendrerit justo, et consectetur mauris."
       ]

julia> pretty_table(A; columns_width = [-1, 20, 100], autowrap = true)
┌────────┬──────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Col. 1 │               Col. 2 │                                                                                               Col. 3 │
├────────┼──────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────┤
│      1 │         Small column │         Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse mattis felis non turpis │
│        │                      │     convallis pellentesque sed et neque. Duis non fringilla mi, vel viverra lorem. Nunc sit amet est │
│        │                      │   nec orci ornare tristique sed eget velit. Nulla rutrum fermentum vehicula. Duis eget justo maximus │
│        │                      │    lectus pharetra congue sit amet ac odio. Vivamus ultrices laoreet pretium. Etiam tristique mauris │
│        │                      │       et felis aliquet hendrerit. Mauris vel lorem ullamcorper justo dapibus fringilla non eu massa. │
│        │                      │       Aliquam molestie diam sapien. Fusce malesuada bibendum dolor vel commodo. Phasellus leo lacus, │
│        │                      │        pharetra id sodales nec, vehicula et magna. Curabitur molestie fermentum cursus. Donec ligula │
│        │                      │    tortor, elementum ac lacus at, congue faucibus urna. Aliquam elementum libero arcu, nec imperdiet │
│        │                      │                                  sem dictum rutrum. Sed quis hendrerit justo, et consectetur mauris. │
│      2 │         Small column │         Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse mattis felis non turpis │
│        │                      │     convallis pellentesque sed et neque. Duis non fringilla mi, vel viverra lorem. Nunc sit amet est │
│        │                      │   nec orci ornare tristique sed eget velit. Nulla rutrum fermentum vehicula. Duis eget justo maximus │
│        │                      │    lectus pharetra congue sit amet ac odio. Vivamus ultrices laoreet pretium. Etiam tristique mauris │
│        │                      │       et felis aliquet hendrerit. Mauris vel lorem ullamcorper justo dapibus fringilla non eu massa. │
│        │                      │       Aliquam molestie diam sapien. Fusce malesuada bibendum dolor vel commodo. Phasellus leo lacus, │
│        │                      │        pharetra id sodales nec, vehicula et magna. Curabitur molestie fermentum cursus. Donec ligula │
│        │                      │    tortor, elementum ac lacus at, congue faucibus urna. Aliquam elementum libero arcu, nec imperdiet │
│        │                      │                                  sem dictum rutrum. Sed quis hendrerit justo, et consectetur mauris. │
└────────┴──────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────┘

Thanks Ronsibr, I wound up finding another way to do it.

Sets the widths for each column.

tbl_scripts._max_width = {'Command Line' : 107, 'Process ID': 10}