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

Minimal format but with spaces between the columns #34

Open
dmoonfire opened this issue Sep 12, 2021 · 3 comments
Open

Minimal format but with spaces between the columns #34

dmoonfire opened this issue Sep 12, 2021 · 3 comments

Comments

@dmoonfire
Copy link

I like the minimal format, except I find the solid bar for the headers to be difficult to parse the columns.

DefaultString DefaultInt32 HiddenString 
----------------------------------------
Row 1                    1 Hidden 1     
Row 2                   10 Hidden 2     
Row 3                  100 Hidden 3     

So, I thought I would try to make a version that had spaces in it:

.WithHeaderCharMapDefinition(
    new Dictionary<HeaderCharMapPositions, char>
    {
        { HeaderCharMapPositions.BottomCenter, ' ' },
        { HeaderCharMapPositions.Divider, ' ' },
        { HeaderCharMapPositions.BorderBottom, '-' },
    })

But what I found was if both BottomCenter and Divider are spaces (' '), then the space is collapsed between the two of them which squishes the columns together. I ended up needing to put something between the two to make it work:

.WithCharMapDefinition(
    new Dictionary<CharMapPositions, char>
    {
        { CharMapPositions.DividerY, ' ' },
    })
.WithHeaderCharMapDefinition(
    new Dictionary<HeaderCharMapPositions, char>
    {
        { HeaderCharMapPositions.BottomCenter, '+' },
        { HeaderCharMapPositions.Divider, ' ' },
        { HeaderCharMapPositions.BorderBottom, '-' },
    });

This produces a table like this:

 DefaultString   DefaultInt32   HiddenString 
---------------+--------------+--------------
 Row 1                      1   Hidden 1     
 Row 2                     10   Hidden 2     
 Row 3                    100   Hidden 3     

Adding that adds extra columns to the right and left of the headers, which isn't ideal but workable. But, being able to have spaces between the columns would be greatly appreciated. Is there a way of doing that?

@minhhungit
Copy link
Owner

Not sure I understand your question, are you asking about 2 bellow char
image

you can set column padding (space left and right of column) using WithPaddingLeft and WithPaddingRight
another option I think you can config Header Char Map for TopLeft, ``BorderLeft, BottomLeft and `TopRight`, `BorderRight`, and `BottomRight` to empty string using `.WithHeaderCharMapDefinition`

image

@dmoonfire
Copy link
Author

Thank you, that covers one of the two questions. The other is the space divider between columns without having padding. In a unit test, this is what I expected would work but didn't.

        [Test]
        public void DefaultFormatWithDataTable()
        {
            var strBuilder =
                ConsoleTableBuilder
                .From(SampleData.SampleTableData)
                .WithPaddingLeft(string.Empty)
                .WithPaddingRight(string.Empty)
                .WithCharMapDefinition(
                    new Dictionary<CharMapPositions, char>
                    {
                        { CharMapPositions.DividerY, ' ' },
                    })
                .WithHeaderCharMapDefinition(
                    new Dictionary<HeaderCharMapPositions, char>
                    {
                        { HeaderCharMapPositions.BottomCenter, ' ' },
                        { HeaderCharMapPositions.Divider, ' ' },
                        { HeaderCharMapPositions.BorderBottom, '-' },
                    });
                .Export();

            Assert.IsTrue(strBuilder.ToString() == @"Name           Position                      Office        Age Start Date
-------------- ----------------------------- ------------- --- ---------------------
Airi Satou     Accountant                    Tokyo         33  5/9/2017 12:00:00 AM   
Angelica Ramos Chief Executive Officer (CEO) New York      47  1/12/2017 12:00:00 AM  
Ashton Cox     Junior Technical Author       London        46  4/2/2017 12:00:00 AM   
Bradley Greer  Software Engineer             San Francisco 28  11/15/2017 12:00:00 AM 
");
            var lines = strBuilder.ToString().Split('\n');
            Assert.IsTrue(lines.Length == 7);
        }

It appears that when I have this:

                        { HeaderCharMapPositions.BottomCenter, ' ' },
                        { HeaderCharMapPositions.Divider, ' ' },

It collapses the divider space entirely instead of giving me a blank line. So I get this divider:

--------------------------------------------------------------------------------

If I change the above BottomCenter to '+', I still get the divider space:

--------------+-----------------------------+-------------+---+---------------------

I would like to know how I could get that unit test output (I might be off on the dashes though on the header).

@minhhungit
Copy link
Owner

It's because it has fallback from CharMapDefinition, but char on CharMapDefinition is empty

I will try to open a toggle to block the fallback

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