Skip to content

IEnumerable<T> 인 리스트를 콘솔창에서 테이블형태로 깔끔하게 그려줍니다.

License

Notifications You must be signed in to change notification settings

Newp/Npgg.ConsoleTable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Npgg.ConsoleTable

https://www.nuget.org/packages/Npgg.ConsoleTable/

특징

  1. Reflection 을 이용하여 자동으로 테이블을 그립니다.
  2. 한글/영문/특수문자에서도 깨지지 않고 똑바로 그립니다.
  3. 패턴매칭이나 대리자를 사용하여 원하는 Row에 원하는 색을 지정할 수 있습니다.

Exmaple

var items = new[]
{
    new Item(){ Name= "Leoric's Crown", Rarity = Rarity.Normal, Slot ="Helm"},
    new Item(){ Name= "Thunderfury", Rarity = Rarity.Unique, Slot ="One Handed Weapon"},
    new Item(){ Name= "할배검 the grandfather", Rarity = Rarity.Legendary, Slot ="Two Handed Weapon"},
    new Item(){ Name= "WINDFORCE", Rarity = Rarity.Magic, Slot ="양손무기"},
};

ConsoleTable.Write(items, item => item.Rarity switch
{
    Rarity.Magic => ConsoleColor.DarkCyan,
    Rarity.Unique => ConsoleColor.DarkMagenta,
    Rarity.Legendary => ConsoleColor.DarkYellow,
    _ => ConsoleColor.White
});

결과

image

다양한 폰트에서도 문제없이 동작

image

간단하게 출력하고 싶다면?

    var items = new[]
    {
        new Item(){ Name= "Leoric's Crown", Rarity = Rarity.Normal, Slot ="Helm"},
        new Item(){ Name= "Thunderfury", Rarity = Rarity.Unique, Slot ="One Handed Weapon"},
        new Item(){ Name= "할배검 the grandfather", Rarity = Rarity.Legendary, Slot ="Two Handed Weapon"},
        new Item(){ Name= "WINDFORCE", Rarity = Rarity.Magic, Slot ="양손무기"},
    };


    ConsoleTable.Write(items);

Column,Row,Table 색상 설정

    ConsoleTable.TableColor = ConsoleColor.Red; //테이블 색깔을 지정합니다.
    ConsoleTable.ColumnColor = ConsoleColor.Cyan; //Column에 들어가는 Text 색상을 지정합니다.
    ConsoleTable.RowColor = ConsoleColor.White; //Row의 색상을 지정합니다. 단, 대리자를 이용한 색상 지정일 경우에는 동작하지 않습니다.

image

anonymous/tuple을 활용하여 원하는 Property/Member만 출력하기

ConsoleTable.Write(items.Select(item => (item.Name, item.Rarity)));
//or
ConsoleTable.Write(items.Select(item => new { item.Name, item.Rarity }));

image

한개의 오브젝트의 Property/Member 정보들을 출력

var obj = new Item() { Name = "Leoric's Crown", Rarity = Rarity.Normal, Slot = "Helm" };
ConsoleTable.WriteSingle(obj);

image

About

IEnumerable<T> 인 리스트를 콘솔창에서 테이블형태로 깔끔하게 그려줍니다.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages