C
C#15mo ago
Underscore

❔ How does CsConsoleFormat work?

CsConsoleFormat and ConsoleTable are two different libraries to output C# objects into a formatted table in the terminal. CsConsoleFormat is more complex than consoletable. As a beginner to the language I'm kind of confused by the README on the CsConsoleFormat. https://github.com/Athari/CsConsoleFormat/blob/master/ReadMe.md
using static System.ConsoleColor;

var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

var doc = new Document(
new Span("Order #") { Color = Yellow }, Order.Id, "\n",
new Span("Customer: ") { Color = Yellow }, Order.Customer.Name,
new Grid {
Color = Gray,
Columns = { GridLength.Auto, GridLength.Star(1), GridLength.Auto },
Children = {
new Cell("Id") { Stroke = headerThickness },
new Cell("Name") { Stroke = headerThickness },
new Cell("Count") { Stroke = headerThickness },
Order.OrderItems.Select(item => new[] {
new Cell(item.Id),
new Cell(item.Name),
new Cell(item.Count) { Align = Align.Right },
})
}
}
);

ConsoleRenderer.RenderDocument(doc);
using static System.ConsoleColor;

var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

var doc = new Document(
new Span("Order #") { Color = Yellow }, Order.Id, "\n",
new Span("Customer: ") { Color = Yellow }, Order.Customer.Name,
new Grid {
Color = Gray,
Columns = { GridLength.Auto, GridLength.Star(1), GridLength.Auto },
Children = {
new Cell("Id") { Stroke = headerThickness },
new Cell("Name") { Stroke = headerThickness },
new Cell("Count") { Stroke = headerThickness },
Order.OrderItems.Select(item => new[] {
new Cell(item.Id),
new Cell(item.Name),
new Cell(item.Count) { Align = Align.Right },
})
}
}
);

ConsoleRenderer.RenderDocument(doc);
Unlike the README for ConsoleTables https://github.com/khalidabuhakmeh/ConsoleTables
// using ConsoleTables;
static void Main(String[] args)
{
var table = new ConsoleTable("one", "two", "three");
table.AddRow(1, 2, 3)
.AddRow("this line should be longer", "yes it is", "oh");

table.Write();
Console.WriteLine();

var rows = Enumerable.Repeat(new Something(), 10);

ConsoleTable
.From<Something>(rows)
.Configure(o => o.NumberAlignment = Alignment.Right)
.Write(Format.Alternative);

Console.ReadKey();
}
// using ConsoleTables;
static void Main(String[] args)
{
var table = new ConsoleTable("one", "two", "three");
table.AddRow(1, 2, 3)
.AddRow("this line should be longer", "yes it is", "oh");

table.Write();
Console.WriteLine();

var rows = Enumerable.Repeat(new Something(), 10);

ConsoleTable
.From<Something>(rows)
.Configure(o => o.NumberAlignment = Alignment.Right)
.Write(Format.Alternative);

Console.ReadKey();
}
I don't really see where CsConsoleFormat takes in data and when it is printed. I also can't find any more documentation on this library. How would I uses CsConsoleFormat to print a list of class instances and some of their attributes?
GitHub
CsConsoleFormat/ReadMe.md at master · Athari/CsConsoleFormat
.NET C# library for advanced formatting of console output [Apache] - Athari/CsConsoleFormat
GitHub
GitHub - khalidabuhakmeh/ConsoleTables: Print out a nicely formatte...
Print out a nicely formatted table in a console application C# - GitHub - khalidabuhakmeh/ConsoleTables: Print out a nicely formatted table in a console application C#
13 Replies
Angius
Angius15mo ago
It seems the data is inside of Order Whatever and wherever that might be
Underscore
UnderscoreOP15mo ago
hmm and I'm not sure what Order could be either do iterables in C# have a Select method? what does that do? is it like a specialized for each?
Angius
Angius15mo ago
It's LINQ, which is a collection of extension methods on IEnumerable<T> .Select() is more like .map() in JS
MODiX
MODiX15mo ago
Angius
REPL Result: Success
new[]{1, 2, 3, 4}.Select(x => x * 2)
new[]{1, 2, 3, 4}.Select(x => x * 2)
Result: List<int>
[
2,
4,
6,
8
]
[
2,
4,
6,
8
]
Compile: 531.837ms | Execution: 80.671ms | React with ❌ to remove this embed.
Angius
Angius15mo ago
Applies some given method to each element
Underscore
UnderscoreOP15mo ago
alright that kind of helped thanks I'm gonna go reread some more docs
ero
ero15mo ago
maybe check out $spectre instead for something like this
MODiX
MODiX15mo ago
Spectre.Console is a .NET library that allows for easy creation of console UIs, text formatting in the console, and command-line argument parsing. https://spectreconsole.net/
Spectre.Console - Welcome!
Spectre.Console is a .NET library that makes it easier to create beautiful console applications.
Underscore
UnderscoreOP15mo ago
is this better if I just want to print some c# objects?
ero
ero15mo ago
i'd say
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server