CTree 1.1.1

dotnet add package CTree --version 1.1.1
                    
NuGet\Install-Package CTree -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CTree" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CTree" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="CTree" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CTree --version 1.1.1
                    
#r "nuget: CTree, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CTree@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CTree&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=CTree&version=1.1.1
                    
Install as a Cake Tool

0. <a href="#_0" id="li_0">다운로드</a>

1. <a href="#_1" id="li_1">시작 배경</a>

2. <a href="#_2" id="li_2">개발 환경</a>

3. <a href="#_3" id="li_3">사용 방법</a>

  1. <a href="#_3_1" id="li_3_1">기본 예제</a>
  2. <a href="#_3_2" id="li_3_2">Folding 예제</a>
  3. <a href="#_3_3" id="li_3_3">Dummy 예제</a>
  4. <a href="#_3_4" id="li_3_4">색상 변경 예제</a>
  5. <a href="#_3_5" id="li_3_5">브릿지 길이 조절</a>
  6. <a href="#_3_6" id="li_3_6">트리 패딩</a>

<br> <br> <br> <br>

0. 다운로드 <a href="#_0" id="_0"></a>

nuget에서 CTree 검색 후 다운로드하면 됨.

alternate text is missing from this package README image

<br> <br> <br>

1. 시작 배경 <a href="#_1" id="_1"></a>

Tcp 홀펀칭 구현을 하면서 콘솙창에 트리 구조의 메뉴를 출력하다가
몇년전에 cmd에서 tree 명령을 치던 기억이 떠올라서 만들게 되었다.

<br> <br> <br>

2. 개발 환경 <a href="#_2" id="_2"></a>

비주얼스튜디오 2022 .Net 6.0
바로 실행해보고 싶으면 비주얼 스튜디오로 CTree.sln을 연 후
CTreeTest 프로젝트를 선택해서 F5를 눌러서 실행하면 됨.

CTree: 콘솔에서 트리형식의 출력을 지원해주는 라이브러리  
CTreeTest: CTree 라이브러리 테스트용 콘솔 프로젝트

<br> <br> <br>

3. 사용 방법<a href="#_3" id="_3"></a>

<br>

1. <b>[기본 예제]</b><a href="#_3_1" id="_3_1"></a>

ConsoleTree root = new ConsoleTree("루트");

ConsoleTreeItem child1 = new("자식-1");
ConsoleTreeItem child2 = new("자식-2");

{
   ConsoleTreeItem child21 = new("자식-2-1");
   ConsoleTreeItem child22 = new("자식-2-2");

   {
      ConsoleTreeItem child221 = new("자식-2-2-1");
      ConsoleTreeItem child222 = new("자식-2-2-2");
      child22.Add(child221, child222);
   }
   ConsoleTreeItem child23 = new("자식-2-3");
   child2.Add(child21, child22, child23);
}

ConsoleTreeItem child3 = new("자식-3");
ConsoleTreeItem child4 = new("자식-4");
root.Add(child1, child2, child3, child4);
root.Print();


/* 동일한 출력 빌더 버전
var root = new ConsoleTree("루트");
root.Add("자식-1")
    .AddReturnChild("자식-2")
        .Add("자식-2-1")
        .AddReturnChild("자식-2-2")
            .Add("자식-2-2-1")
            .AddReturnParent("자식-2-2-2")
        .AddReturnParent("자식-2-3")
    .Add("자식-3")
    .Add("자식-4");
root.Print();
*/

<br>

alternate text is missing from this package README image

<br> <br>

2. <b>[Folding 예제]</b><a href="#_3_2" id="_3_2"></a>

Fold 옵션을 주게되면 하위 자식들이 출력되지 않는다. 아래 예시를 보면 자식-2-2에 Fold 옵션을 주게되면 2-2-1 ~ 2-2-3의 자식들이 출력이 안되는 것을 확인할 수 있다.

ConsoleTree root = new ConsoleTree("루트");

ConsoleTreeItem child1 = new("자식-1");
ConsoleTreeItem child2 = new("자식-2");

{
   ConsoleTreeItem child21 = new("자식-2-1");
   ConsoleTreeItem child22 = new("자식-2-2") { Fold = true };

   {
      ConsoleTreeItem child221 = new("자식-2-2-1");
      ConsoleTreeItem child222 = new("자식-2-2-2");
      child22.Add(child221, child222);
   }
   ConsoleTreeItem child23 = new("자식-2-3");
   child2.Add(child21, child22, child23);
}

ConsoleTreeItem child3 = new("자식-3");
ConsoleTreeItem child4 = new("자식-4");
root.Add(child1, child2, child3, child4);
root.Print();


/* 동일한 출력 빌더 버전
var root = new ConsoleTree("루트");
root.Add("자식-1")
    .AddReturnChild("자식-2")
        .Add("자식-2-1")
        .AddReturnChild(new ConsoleTreeItem("자식-2-2") { Fold = true })
            .Add("자식-2-2-1")
            .AddReturnParent("자식-2-2-2")
        .AddReturnParent("자식-2-3")
    .Add("자식-3")
    .Add("자식-4");
root.Print();
*/


alternate text is missing from this package README image

<br> <br>

3. <b>[Dummy 예제]</b><a href="#_3_3" id="_3_3"></a>

Dummy 옵션을 주게 되면 해당 아이템이 있던 행은 유지한채로 안보이게 만들어줌 물론 하위 자식들도 출력되지 않는다.

기존 아이템을 더미로 만들어 버릴수도 있고 AddDummy(int count)
함수를 사용해서 사이사이 원하는 수만큼 더미를 추가할 수도 있다.

  1. 자식-1이 Dummy 처리되어 출력되지 않고 있다.
  2. 자식 2-1과 자식 2-2사이에 1개의 더미노드가 추가되었다.
  3. 자식 2-2와 자식 2-3사이에 2개의 더미노드가 추가되었다.
ConsoleTree root = new ConsoleTree("루트");

ConsoleTreeItem child1 = new("자식-1") { Dummy = true }; // 더미로 만들어버릴 수 있음
ConsoleTreeItem child2 = new("자식-2");  

{
    ConsoleTreeItem child21 = new("자식-2-1");
    ConsoleTreeItem child22 = new("자식-2-2");

    {
        ConsoleTreeItem child221 = new("자식-2-2-1");
        ConsoleTreeItem child222 = new("자식-2-2-2");
        child22.Add(child221, child222);
    }
    ConsoleTreeItem child23 = new("자식-2-3");
    child2.Add(child21);
    child2.AddDummy();
    child2.Add(child22);
    child2.AddDummy(2);
    child2.Add(child23);
}

ConsoleTreeItem child3 = new("자식-3");
ConsoleTreeItem child4 = new("자식-4");
root.Add(child1, child2, child3, child4);
root.Print();



/* 동일한 출력 빌더 버전
var root = new ConsoleTree("루트");
root.Add(new ConsoleTreeItem("자식-1") { Dummy = true })
    .AddReturnChild("자식-2")
        .Add("자식-2-1")
        .AddDummy()
        .AddReturnChild("자식-2-2")
            .Add("자식-2-2-1")
            .AddReturnParent("자식-2-2-2")
        .AddDummy(2)
        .AddReturnParent("자식-2-3")
    .Add("자식-3")
    .Add("자식-4");
root.Print();
*/

alternate text is missing from this package README image

<br> <br>

4. <b>[색상 변경 예제]</b><a href="#_3_4" id="_3_4"></a>

  1. 트리 전체 브릿지, 아이템 색상 변경 가능
  2. 트리 개별 아이템 색상 변경 가능
ConsoleTree root = new("루트")
{
    ItemForegroundColor = ConsoleColor.Cyan,        // 전체 아이템 색상, 브릿지 색상 변경가능
    BridgeForegroundColor = ConsoleColor.Red
};

ConsoleTreeItem child1 = new("자식-1");
ConsoleTreeItem child2 = new("자식-2");

{
    ConsoleTreeItem child21 = new("자식-2-1");
    ConsoleTreeItem child22 = new("자식-2-2");

    {
        // 개별 아이템 색상 변경도 가능
        ConsoleTreeItem child221 = new("자식-2-2-1") { ForegroundColor = ConsoleColor.DarkYellow };
        ConsoleTreeItem child222 = new("자식-2-2-2") { ForegroundColor = ConsoleColor.DarkYellow };
        child22.Add(child221, child222);
    }
    ConsoleTreeItem child23 = new("자식-2-3");
    child2.Add(child21, child22, child23);
}

ConsoleTreeItem child3 = new("자식-3");
ConsoleTreeItem child4 = new("자식-4");
root.Add(child1, child2, child3, child4);
root.Print();

alternate text is missing from this package README image

<br> <br>

5. <b>[브릿지 길이 조절]</b><a href="#_3_5" id="_3_5"></a>

var root = new ConsoleTree("루트");

for (int i = 0; i < 20; i++)
{
    root.Add(new ConsoleTreeItem($"자식-{i}") { BridgeLength = i });
}

root.Print();

alternate text is missing from this package README image

<br> <br>

6. <b>[트리 패딩]</b><a href="#_3_6" id="_3_6"></a>

var root = new ConsoleTree("루트");
root.ItemLeftPad = 5;

root.AddReturnChild(new ConsoleTreeItem($"자식-1"))
        .Add("자식-1-1")
        .Add("자식-1-2")
        .Add("자식-1-3");
root.Add(new ConsoleTreeItem($"자식-1"));
root.Add(new ConsoleTreeItem($"자식-1"));

root.Print();

alternate text is missing from this package README image

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 547 11/18/2022
1.1.0 461 11/18/2022
1.0.0 596 11/17/2022