Changed table formatting to typically exclude hidden keys
Fixed issue with string centering (Closes #4)
This commit is contained in:
parent
ff4eaa0997
commit
10bd29c296
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Assignment_1
|
||||
{
|
||||
@ -216,26 +218,39 @@ namespace Assignment_1
|
||||
/// <summary>
|
||||
/// Creates and prints a list of all defined variables
|
||||
/// </summary>
|
||||
void List()
|
||||
void List(bool printUnprint = false)
|
||||
{
|
||||
Console.WriteLine("┌" + new string('─', 15) + "┬" + new string('─', 25) + "┬" + new string('─', 9) + "┐");
|
||||
Console.WriteLine("│{0}│{1}│{2}│", CenterString("Symbol",15), CenterString("Value",25), CenterString("Flags",9));
|
||||
Console.WriteLine("├" + new string('─', 15) + "┼" + new string('─', 25) + "┼" + new string('─', 9) + "┤");
|
||||
int keyPos = 0;
|
||||
foreach (var item in Symbols)
|
||||
int keyWidth = 10;
|
||||
int valueWidth = 50;
|
||||
int flagWidth = 9;
|
||||
Console.WriteLine("┌" + new string('─', keyWidth) + "┬" + new string('─', valueWidth) + "┬" + new string('─', flagWidth) + "┐");
|
||||
Console.WriteLine("│{0}│{1}│{2}│", CenterString("Symbol", keyWidth), CenterString("Value", valueWidth), CenterString("Flags", flagWidth));
|
||||
// Figure out how many symbols are eligible for printing
|
||||
List<string> eligibleKeys = new List<string>(Symbols.Count);
|
||||
foreach (var item in Symbols.Keys)
|
||||
{
|
||||
Console.WriteLine("│{0,-15}│{1,-25}│{2,9}│", item.Key, item.Value.Item1.Replace("\r","\\r").Replace("\n","\\n").Replace("\t", "\\t"), Convert.ToString((byte)item.Value.Item2,2).PadLeft(8,'0'));
|
||||
if (keyPos == Symbols.Count-1)
|
||||
if (!Symbols[item].Item2.HasFlag(VariableFlags.NoPrint) || (Symbols[item].Item2.HasFlag(VariableFlags.NoPrint) && printUnprint))
|
||||
{
|
||||
Console.WriteLine("└" + new string('─', 15) + "┴" + new string('─', 25) + "┴" + new string('─', 9) + "┘");
|
||||
eligibleKeys.Add(item);
|
||||
}
|
||||
else
|
||||
}
|
||||
// Control printing based on how many keys are available
|
||||
if (eligibleKeys.Count > 0)
|
||||
{
|
||||
Console.WriteLine("├" + new string('─', 15) + "┼" + new string('─', 25) + "┼" + new string('─', 9) + "┤");
|
||||
Console.WriteLine("├" + new string('─', keyWidth) + "┼" + new string('─', valueWidth) + "┼" + new string('─', flagWidth) + "┤");
|
||||
for (int i = 0; i < eligibleKeys.Count; i++)
|
||||
{
|
||||
string entryFormat = "│{0," + -1*keyWidth + "}│{1," + -1*valueWidth + "}│{2," + -1*flagWidth + "}│";
|
||||
|
||||
Console.WriteLine(entryFormat, eligibleKeys[i], Symbols[eligibleKeys[i]].Item1.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"), Convert.ToString((byte)Symbols[eligibleKeys[i]].Item2, 2).PadLeft(8, '0'));
|
||||
if (i + 1 < eligibleKeys.Count)
|
||||
{
|
||||
Console.WriteLine("├" + new string('─', keyWidth) + "┼" + new string('─', valueWidth) + "┼" + new string('─', flagWidth) + "┤");
|
||||
}
|
||||
keyPos++;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("└" + new string('─', keyWidth) + "┴" + new string('─', valueWidth) + "┴" + new string('─', flagWidth) + "┘");
|
||||
}
|
||||
void Exit()
|
||||
{
|
||||
Environment.Exit(0);
|
||||
@ -720,7 +735,7 @@ namespace Assignment_1
|
||||
int leftHalfPad = (int)Math.Floor(totalPadding / 2.0);
|
||||
int rightHalfPad = (int)Math.Ceiling(totalPadding / 2.0);
|
||||
string t = "{0," + leftHalfPad + "}{1," + -1 * rightHalfPad + "}";
|
||||
string result = string.Format(t, source.Substring(0,leftHalf+1), source.Substring(rightHalf,source.Length-rightHalf));
|
||||
string result = string.Format(t, source[..rightHalf], source[rightHalf..]);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user