I'm Douglas, a Fullstack developer in Oregon, US.
I enjoy writing utilities & tools, and gamedev in my spare time!
Faster, colorable, more configurable, and more robust console colors & tables for C# console applications
License: GNU Lesser General Public License v3.0
Hi,
if you create a table without rows the ToString() method returns errors.
var table = new Table(..);
....
table.AddRows(rows); // rows count = 0
var ret = table.ToString();
System.IndexOutOfRangeException
Index was outside the bounds of the array.
at BetterConsoleTables.Table.ToString(Int32[] columnLengths)
at BetterConsoleTables.Table.ToString()
I've already created a performance friendly text-wrapping method, but the current table generation logic doesn't enable cells to be dynamically sized vertically.
Given a IList data set added to a Table using the From method is written to the console
When the result is piped to a file (e.g. dotnet run > test.txt
)
Then an unhandled exception is raised, namely:
Unhandled exception. System.ArgumentOutOfRangeException: Positive number required. (Parameter 'width')
Actual value was -1.
at System.ConsolePal.SetWindowSize(Int32 width, Int32 height)
at System.Console.set_WindowWidth(Int32 value)
at BetterConsoleTables.Table.PadRow(String row)
at BetterConsoleTables.Table.FormatHeader(Int32[] columnLengths, IList`1 values, Char innerDelimiter, Char outerDelimiter)
at BetterConsoleTables.Table.ToString(Int32[] columnLengths)
at BetterConsoleTables.Table.ToString()
Example code:
public void Present<T>(IList<T> index) where T : IModel
{
var table = new Table(TableConfiguration.Markdown());
table.From(index);
Console.WriteLine(table.ToString());
}
Hello. I was trying to run a project using this library in a RaspberryPi 4, and I get this exception:
Unhandled exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Runtime.Intrinsics.X86.Popcnt.PopCount(UInt32 value)
at BetterConsoles.Colors.Extensions.FormatExtensions.BitCount(FontStyleExt styles)
at BetterConsoles.Colors.Extensions.FormatExtensions.GetAnsiCodes(IFormat format, Int32 extraArraySize)
at BetterConsoles.Colors.Extensions.StringExtensions.SetStyle(String value, IFormat format)
at BetterConsoles.Tables.Table.FormatRow(IList`1 values, IList`1 formats, Int32[] columnLengths, Char& innerDelimiter, Char& outerDelimiter)
at BetterConsoles.Tables.Table.ToString(Int32[] columnLengths)
at BetterConsoles.Tables.Table.ToString()
at Media.Storage.Console.Commands.HealthCommand.Handle(IConsole console, IHost host, String[] labels, ErrorHandler errorHandler, OutputFormat outputFormat, String output, String colSep, String rowSep, Boolean exact) in C:\Users\PedroSilva\source\repos\Media\Media.Storage.Console\Commands\HealthCommand.cs:line 143
It works fine when running on a Windows 10 x64 machine. I think the issue is with this PopCount call here, which I assume is just a performance optimization for platforms that support it. Would it be possible to exclude based on the processor (ARM vs x86) instead of just the framework version?
In the meantime, since I assume this conditional block can just be removed without any functionality being lost, I will just git clone the project and make the changes locally on my end, so it's cool for me. Just wanted to put this here in case other people stumble across the same issue as me.
Thanks
Hi there,
I'm trying to use this library in LINQPad to copy/paste a table for some readme docs; but soon as I try to call .ToString
on the table, I get an IO exception.
I'm guessing because the library is running in an execution context without the console subsystem, but it would be nice if it ran in a situation like this without a console.
Here's the query I tried to run in LINQPad:
Bogus.dll
https://github.com/bchavez/BogusBetterConsoleTables
.void Main()
{
Randomizer.Seed = new Random(1337);
var orderIds = 0;
var testOrders = new Faker<Order>()
.RuleFor(o => o.OrderId, f => orderIds++)
.RuleFor(o => o.Item, f => f.Commerce.Product() )
.RuleFor(o => o.Quantity, f => f.Random.Number(1, 5));
var orders = testOrders.Generate(5).ToArray();
orders.Dump();
var table = new Table("OrderId", "Item", "Quantity");
foreach( var o in orders){
table.AddRow(o.OrderId, o.Item, o.Quantity);
}
table.ToString().Dump();
}
// Define other methods and classes here
public class Order{
public int OrderId{get;set;}
public string Item{get;set;}
public int Quantity{get;set;}
}
And here's the exception stack I'm getting:
Feel free to close the issue if you don't think this is an appropriate execution environment.
Also, I could send a pull request to fix the issue if you think it is appropriate to accept one.
Let me know.
Thanks!
Brian
Chinese is not supported
Does this library support formatting cells with multiple lines?
I tried embedding System.Environment.NewLine but that corrupted the table format
Hi,
Is possible create output html?
Best regards
I wonder if there's a way to print two tables side by side rather than one after the other. Maybe via some string manipulation? I would love to hear from you.
.Config = Config.UnicodeAlt(); Not working
I needed to delete that line and add:
table.Config = TableConfiguration.UnicodeAlt();
Should be changed in documentation
thank you
var table = new Table("Họ tên", "Tuổi", "Giới tính", "Chi phí đồng phục");
foreach (Student student in students)
{
double uniformCost = student.CalculateUniformCost();
string gender = (student is Female_Student) ? "Nữ" : "Nam";
table.AddRow(student.name, student.age, gender, uniformCost);
}
table.Config = TableConfiguration.Unicode();
Console.WriteLine(table.ToString());
IDK if this is bug of old windows console or your libary have issue with Unicode intergration
Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
23:43:06.176 at System.ConsolePal.set_WindowWidth(Int32 value)
23:43:06.176 at BetterConsoleTables.Table.PadRow(String row)
23:43:06.176 at BetterConsoleTables.Table.ToString(Int32[] columnLengths)
Hi.
I'm currently using version 2.0.3-rc1 of the library and am getting a weird column width issue
The code that generates this is
var decodingtable = new BetterConsoles.Tables.Table(decodingHeaders.ToArray());
decodingtable.Config = new BetterConsoles.Tables.Configuration.TableConfig(BetterConsoles.Tables.Style.Unicode);
foreach (var file in decodingValues.Keys)
{
var indexMin = decodingValues[file].IndexOf(decodingValues[file].Min());
var benchmarkValues = decodingValues[file].ConvertAll(v => v.ToString(@"ss\.ffffff"));
benchmarkValues[indexMin] = benchmarkValues[indexMin].ForegroundColor(System.Drawing.Color.DarkGreen);
decodingtable.AddRow(
Array.Empty<string>()
.Append(file)
.Concat(benchmarkValues).ToArray());
}
Console.Write(decodingtable.ToString());
I am setting the foreground color as DarkGreen
for the cell that contains the minimum value in a list/row.
Any ideas as to why this is happening?
Thanks.
If I am building a table from a collection of objects, and any of the property values are null, a NullReferenceException is thrown. I should get (null)
or something similar in the output.
Can we have an option where we can render the entire table into an image like PNG ?
table.ToImage(ImageFormat.Png)
Hi @douglasg14b
I found somethig weird in my testing
I compare table printout to expected string in my integration test.
When i run test from Visual Studio all is fine.
When i run test in dotnet test cli command it sqrews up printout.
Speciffically it adds whitespaces and test failes
┌──────┬───────────┐
│ �[38;2;250;250;210m Id �[0m │ �[38;2;0;128;0m Name �[0m │
├──────┼───────────┤
│ �[38;2;250;250;210m1291�[0m │ �[38;2;0;128;0mChristine�[0m │
└──────┴───────────┘
Look at the space after ┌──────┬───────────┐
There id plenty of whitespaces there.
They show up only when test is run thrue dotnet test
Can you comment that ?
This issue highlighted that this path may be awkward: #28
var table = new Table(TableConfig.Unicode());
table.From(statistics.ToArray());
// Enable inner formatting for all columns.
foreach (var header in table.Headers)
header.RowsFormat.InnerFormatting = true;
Console.Write(table.ToString());
Perhaps the From()
method could accept some parameters that apply to all columns?
Goals/Scope:
Table
classoutputWidth
argumentOut of Scope:
This will mostly require a rewrite of much of the Table's working so I can bake in interoperability and compatibility while minimizing code reuse.
Misc Thoughts:
Extracting table through reflection:
Table.From<TModel>(TModel tableModel)
.From<>
returns a config builder for the type.AddColumn(TModel x => x.MyProp, ...config ... )
.AddColumn(TModel x => x.MyProp).SetColor(...).AlignContent(...).AddColumn(...) ...
Bugs
This is the stack trace:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at BetterConsoleTables.Table.ToString(Int32[] columnLengths)
at BetterConsoleTables.Table.ToString()
Something I really want to add in are table colors.
This will mean redesigning the table generation logic and configuration from scratch. I'm thinking of leaving the current non-colored table, and having a seperate class for colored tables. This ensures backwards compatibility (if anyone actually uses this library...), and keep the performance benefits of the current implementation.
I'll want to extract common items for the table and config into an interface, to make compatibility a bit simpler.
Hi,
what does this mean?
The new console window size would force the console buffer size to be too large.
Parameter name: width
Actual value was 186
Best regards
I added nuget and try to use Column type
Cant find ns
Shame, i wanted to use this lib
BetterConsoles.Tables.TableBase.PadRowInConsole can generate an ArgumentOutOfRangeException when outputting to a file using: >> file.txt. This happens when the table is too large horizontally to fit within the console window.
System.ArgumentOutOfRangeException: Positive number required.
Parameter name: width
Actual value was -1.
at System.Console.SetWindowSize(Int32 width, Int32 height)
at BetterConsoles.Tables.TableBase`3.PadRowInConsole(String renderedRow)
at BetterConsoles.Tables.TableBase`3.GenerateDivider(Int32[] columnLengths, Char innerDelimiter, Char divider, Char left, Char right)
at BetterConsoles.Tables.Table.ToString(Int32[] columnLengths)
at BetterConsoles.Tables.Table.ToString()
Tested on .NET Framework 4.8 and BetterConsoleTables 2.0.4-rc1
Right now if you try and bold or dim an RGB colored piece of text, nothing happens.
This is because RGB already sets the intensity and the majority or terminals will not try and change that with the bold sequence.
I could detect that we are using RGB & bold/dim at the same time, and then manually adjust the intensity of the provided RGB.
If a cell say, starts with a pre-formatted string and that cell has formatting. The cells formatting will be inserted before that custom formatting (At the beginning of the cells string), and if that custom formatting terminates with an ANSI reset, then that cells formatting will be terminated at that reset point.
Example:
�[38;2;220;220;220m�[38;2;204;83;78mSolo�[0m: A Star Wars Story
I frequently find myself needing to display real time tables in console apps. Is it possible to update the table in a loop and write row by row instead of building the entire table and printing it all at once?
Is there a way to change the default text color in version 2? After transitioning from v1 to v2, all table text was colored gray. I know that you can change it by using ColumnBuilder but it seems overly verbose to have to change it for each and every column for both the column header and rows. # #
Hi,
wonderful job. Is it possible to specify in ToString if the column is aligned to the right?
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.