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

Custom line/row separator #9

Open
sibiarunachalam opened this issue Aug 15, 2022 · 5 comments
Open

Custom line/row separator #9

sibiarunachalam opened this issue Aug 15, 2022 · 5 comments

Comments

@sibiarunachalam
Copy link

This is my table format

id   column1        column2                    column3          
---- --------------- ------------------------------ ------------------ 
 1   data11       data12                           data13
 2   data21       data22                           data23
 3   data31       data32                           data33
 4   data41       data42                           data43

I need to have empty line between each record to view the data clearly.

@freva
Copy link
Owner

freva commented Aug 15, 2022

So what you want is

id   column1        column2                    column3          
---- --------------- ------------------------------ ------------------ 
 1   data11       data12                           data13

 2   data21       data22                           data23

 3   data31       data32                           data33

 4   data41       data42                           data43

?

@sibiarunachalam
Copy link
Author

Yes @freva

@sibiarunachalam
Copy link
Author

It would be even helpful if that is configurable so that line separator can be anything. It would also help to format the span rows.

@freva
Copy link
Owner

freva commented Aug 16, 2022

@sibiarunachalam there are a few ways to achieve this. You can convert the table to rows and then programatically insert empty lines wherever you need them. Another option is to think of the of the empty rows as a row border made out of spaces, e.g.:

String[] headers = {"id", "column1", "column2", "column3"};
String[][] data = {{"1", "data11", "data12", "data13"},
        {"2", "data21", "data22", "data23"},
        {"3", "data31", "data32", "data33"},
        {"4", "data41", "data42", "data43"}};
Character[] style = {null, null, null, null, null, ' ', null, null, '-',
        ' ', null, null, ' ', null, null, ' ', ' ', null, null, null, null, null, null, null, null, null, null, null, null};
System.out.println(AsciiTable.getTable(style, headers, null, data));

Produces

 id   column1   column2   column3 
---- --------- --------- ---------
  1    data11    data12    data13 
                                  
  2    data21    data22    data23 
                                  
  3    data31    data32    data33 
                                  
  4    data41    data42    data43 

@sibiarunachalam
Copy link
Author

sibiarunachalam commented Aug 17, 2022

Thanks @freva for your valuable feedback. Second option will solve the problem in this scenario.
Earlier I tried same approach, but it doesn't work in Windows environment whereas it worked in Linux environment. I think I didn't configure the border style properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants