Giter Club home page Giter Club logo

Comments (3)

douglasg14b avatar douglasg14b commented on May 26, 2024 1

You could also use:

IColumn[] headers = new[]
{
    new Column(""),
    new Column("QoiCi"),
    new ColumnBuilder("QoiCore")
        .RowsFormat()
            .HasInnerFormatting()
        .GetColumn(),
    new Column("QoiFileTypeNet"),
    new Column("QoiNetStandard"),
    new Column("QoiShark"),
};

And continue coloring it as you currently are. I parse out the ANSI codes when this flag is active, but it has a performance cost (small).

from betterconsoletables.

douglasg14b avatar douglasg14b commented on May 26, 2024

This is expected as the color formatting is occurring outside of the table. This adds ANSI codes to the string that the console renders as formatting. This also means that the string essentially contains a bunch of invisible characters. The header will be sized to the expected column width, but the invisible characters are not actually rendered by the console/terminal. Resulting in the effects seen here.

If you wish for a column or a value be formatted you must use the table API for that, which will calculate the correct column widths and apply formatting after.

To apply column formatting you need to configure the columns in your table:

IColumn[] headers = new[]
{
    new Column(""),
    new Column("QoiCi"),
    new ColumnBuilder("QoiCore")
        .RowsFormat()
            .ForegroundColor(System.Drawing.Color.DarkGreen)
        .GetColumn(),
    new Column("QoiFileTypeNet"),
    new Column("QoiNetStandard"),
    new Column("QoiShark"),
};

var decodingtable = new BetterConsoles.Tables.Table(headers);

Unfortunately I cannot run your example as I don't have an example decodingHeaders or decodingValues to use. But the above should do what you are aiming for if my memory serves me right.

That said, you can find full examples of this and similar APIs in the examples project & file here: (Including the tables in the image on the repo's readme)


Admittedly this API isn't as good as it could be, it's high up on my list of things to make better when I have the time to invest in it.

from betterconsoletables.

zmira avatar zmira commented on May 26, 2024

Thanks for the above. Although I had to tweak the code a bit, it now displays correctly.

image

The new code

    var columnsWithMin = new List<int>();
    var decodingTableRows = new List<string[]>();
    foreach (var file in decodingValues.Keys)
    {
        var indexMin = decodingValues[file].IndexOf(decodingValues[file].Min());

        if (!columnsWithMin.Contains(indexMin))
        {
            columnsWithMin.Add(indexMin);
        }

        var benchmarkValues = decodingValues[file]
            .ConvertAll(v => v.ToString(@"ss\.ffffff"));
        benchmarkValues[indexMin] = benchmarkValues[indexMin]
            .ForegroundColor(System.Drawing.Color.DarkGreen);

        decodingTableRows.Add(Array.Empty<string>()
            .Append(file)
            .Concat(benchmarkValues).ToArray());
    }

    var decodingTableHeaders = new List<BetterConsoles.Tables.Models.IColumn>();
    decodingTableHeaders.Add(new BetterConsoles.Tables.Models.Column(string.Empty));

    for (var i = 0; i < decodingHeaders.Count; i++)
    {
        decodingTableHeaders.Add(columnsWithMin.Contains(i)
            ? new BetterConsoles.Tables.Builders.ColumnBuilder(decodingHeaders[i])
                .RowsFormat().HasInnerFormatting().GetColumn()
            : new BetterConsoles.Tables.Models.Column(decodingHeaders[i]));
    }

    var decodingtable = new BetterConsoles.Tables.Table(decodingTableHeaders.ToArray());
    decodingtable.Config = new BetterConsoles.Tables.Configuration.TableConfig(BetterConsoles.Tables.Style.Unicode);
    decodingtable.AddRows(decodingTableRows);

    Console.Write(decodingtable.ToString());

from betterconsoletables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.