ascii-table icon indicating copy to clipboard operation
ascii-table copied to clipboard

Custom line/row separator

Open sibiarunachalam opened this issue 2 years ago • 5 comments

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.

sibiarunachalam avatar Aug 15 '22 05:08 sibiarunachalam

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

?

freva avatar Aug 15 '22 06:08 freva

Yes @freva

sibiarunachalam avatar Aug 15 '22 06:08 sibiarunachalam

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.

sibiarunachalam avatar Aug 15 '22 06:08 sibiarunachalam

@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 

freva avatar Aug 16 '22 17:08 freva

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.

sibiarunachalam avatar Aug 17 '22 08:08 sibiarunachalam