Skip to content

Commit

Permalink
Improve visuals of string view
Browse files Browse the repository at this point in the history
  • Loading branch information
jkendall327 committed Jul 28, 2024
1 parent be88d17 commit 6301c78
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions DependencyInjection.Visualization/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ public string GenerateTreeView(IEnumerable<ServiceNode> nodes, bool onlyUserCode

var sb = new StringBuilder();

var grouped = nodes
var groupedNodes = nodes
.GroupBy(n => n.Descriptor.ServiceType.Namespace)
.OrderBy(g => g.Key);

foreach (var group in grouped)
foreach (var group in groupedNodes)
{
sb.AppendLine($"Namespace: {group.Key}");
sb.AppendLine(new('-', 50));
sb.AppendLine(new string('─', 50));

foreach (var node in group)
{
AppendNodeAndDependencies(sb, node, 0);
AppendNodeAndDependencies(sb, node, "", true);
}

sb.AppendLine();
Expand All @@ -34,15 +34,15 @@ public string GenerateTreeView(IEnumerable<ServiceNode> nodes, bool onlyUserCode
return sb.ToString();
}

private void AppendNodeAndDependencies(StringBuilder sb, ServiceNode node, int depth)
private void AppendNodeAndDependencies(StringBuilder sb, ServiceNode node, string prefix, bool isLast)
{
var description = GetServiceDescription(node.Descriptor);

sb.AppendLine($"{new string(' ', depth * 2)}{description}");

foreach (var child in node.Dependencies)
sb.AppendLine($"{prefix}{(isLast ? "└── " : "├── ")}{GetServiceDescription(node.Descriptor)}");

for (int i = 0; i < node.Dependencies.Count; i++)
{
AppendNodeAndDependencies(sb, child, depth + 1);
var child = node.Dependencies[i];
var childPrefix = prefix + (isLast ? " " : "│ ");
AppendNodeAndDependencies(sb, child, childPrefix, i == node.Dependencies.Count - 1);
}
}

Expand Down

0 comments on commit 6301c78

Please sign in to comment.