Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed write() method which threw exceptions while using Alternative format #67

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ConsoleTables/ConsoleTable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static ConsoleTable FromDictionary(Dictionary<string, Dictionary<string,
var table = new ConsoleTable();

var columNames = values.SelectMany(x => x.Value.Keys).Distinct().ToList();
columNames.Insert(0,"");
columNames.Insert(0, "");
table.AddColumn(columNames);
foreach (var row in values)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ public string ToStringAlternative()
var results = Rows.Select((row, i) => string.Format(Formats[i + 1].TrimStart(), row)).ToList();

// create the divider
var divider = Regex.Replace(columnHeaders, @"[^|]", "-");
var divider = Regex.Replace(columnHeaders, "[^| ]", "-");
var dividerPlus = divider.Replace("|", "+");

builder.AppendLine(dividerPlus);
Expand All @@ -251,6 +251,7 @@ public string ToStringAlternative()
return builder.ToString();
}


private string Format(List<int> columnLengths, char delimiter = '|')
{
// set right alignment if is a number
Expand Down Expand Up @@ -289,6 +290,8 @@ private List<int> ColumnLengths()

public void Write(Format format = ConsoleTables.Format.Default)
{
SetFormats(ColumnLengths(), Enumerable.Range(0, Columns.Count).Select(GetNumberAlignment).ToList());

switch (format)
{
case ConsoleTables.Format.Default:
Expand Down