SharpTables
1.0.0
汎用性とカスタマイズ可能なコンソールテーブルフォーマッタ。テーブルを生成するためにジェネレーターが使用している文字をカスタマイズする機能を備えたコンソールに書き込む準備ができたテーブルを生成します。
サンプルプログラムについては、例を参照してください。すべての機能が含まれているわけではないことに留意してください。
using SharpTables ;
Formatting f = Formatting . Minimalist ;
object [ , ] dataset = new object [ , ]
{
{ "Name" , "Age" , "City" } ,
{ "John Doe" , 42 , "New York" } ,
{ "Jane Doe" , 36 , "Chicago" } ,
{ "Joe Bloggs" , 25 , "Los Angeles" } ,
{ "Jenny Smith" , 28 , "Miami" }
} ;
Table table = Table . FromDataSet ( dataset ) // Also supports IEnumerable<IEnumerable<T>>
. AddRow ( new Row ( "Jimmy Jones" , null , "Las Vegas" ) ) // Supports nullables and manually adding rows
. UseNullOrEmptyReplacement ( "N/A" )
. UsePreset ( cell => cell . Color = cell . IsNumeric ? ConsoleColor . Yellow : ConsoleColor . White ) ;
table . Print ( ) ;
/*
Name Age City
────────────────────────────────────────────
John Doe 42 New York
Jane Doe 36 Chicago
Joe Bloggs 25 Los Angeles
Jenny Smith 28 Miami
Jimmy Jones N/A Las Vegas
*/Formattingクラスには既にいくつかのプリセットがあります。また、 recordタイプであるためwith使用して使用することも、独自のインスタンスを作成することもできます。デフォルトでは、 new Formatting()を使用すると、 Formatting.Defaultが使用されます
// Using the power of records!
Formatting format = Formatting . ASCII with
{
DividerColor = ConsoleColor . DarkGray ,
BottomLeftDivider = '@' ,
BottomRightDivider = '@' ,
TopLeftDivider = '@' ,
TopRightDivider = '@' ,
MiddleDivider = '%' ,
Header = Formatting . ASCII . Header with { Separated = true , }
} ;
/*
+----------------+--------+----------------+
|Name |Age |City |
+----------------+--------+----------------+
@----------------+--------+----------------@
|John Doe |42 |New York |
+----------------%--------%----------------+
|Jane Doe |36 |Chicago |
+----------------%--------%----------------+
|Joe Bloggs |25 |Los Angeles |
+----------------%--------%----------------+
|Jenny Smith |28 |Miami |
+----------------%--------%----------------+
|Jimmy Jones |N/A |Las Vegas |
@----------------+--------+----------------@
*/また、セル固有のフォーマットを使用することもできます。これは、テーブル内のセルがどのように見えるかを変更するために使用できます。
List < Foo > foos = new List < Foo >
{
new Foo { A = 1 , B = "Hello" , C = true } ,
new Foo { A = 2 , B = "World" , C = false } ,
new Foo { A = 3 , B = "Something" , C = true } ,
} ;
// 'c' represents any cell in the table
table . UsePreset ( c =>
{
if ( bool . TryParse ( c . Text , out bool b ) )
{
c . Text = b ? "V" : "X" ;
c . Alignment = Alignment . Center ;
c . Color = b ? ConsoleColor . Green : ConsoleColor . Red ;
}
if ( int . TryParse ( c . Text , out int i ) )
{
c . Color = ConsoleColor . Yellow ;
c . Padding = 0 ;
c . Alignment = Alignment . Right ;
}
} ) ;
/*
The result is colored on console.
╔═══════════╦══════════════╦════╗
║ Is Active ║ Name ║ ID ║
╠═══════════╬══════════════╬════╣
│ V │Hello │ 1│
├───────────┼──────────────┼────┤
│ X │World │ 2│
├───────────┼──────────────┼────┤
│ V │Something │ 3│
└───────────┴──────────────┴────┘
*/ バグを見つけたり、質問をしたり、独自の追加を実装したり、他の方法で貢献したりしたい場合は、Pullリクエストを自由に開いてください!
このプロジェクトは、MITライセンスの下でライセンスされています