Skip to content

Commit

Permalink
Merge pull request #67 from gsmander/main
Browse files Browse the repository at this point in the history
Fixed write() method which threw exceptions while using Alternative format
  • Loading branch information
khalidabuhakmeh authored Oct 27, 2023
2 parents 2f75536 + abe793c commit c93523a
Showing 1 changed file with 6 additions and 3 deletions.
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.Data;
using System.IO;
Expand Down Expand Up @@ -73,7 +73,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 @@ -257,7 +257,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 @@ -273,6 +273,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 @@ -311,6 +312,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

0 comments on commit c93523a

Please sign in to comment.