diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs
index 24a5df7..1155ad7 100644
--- a/Assignment 1/Program.cs
+++ b/Assignment 1/Program.cs
@@ -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,25 +218,38 @@ namespace Assignment_1
///
/// Creates and prints a list of all defined variables
///
- 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 eligibleKeys = new List(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
- {
- Console.WriteLine("├" + new string('─', 15) + "┼" + new string('─', 25) + "┼" + new string('─', 9) + "┤");
- }
- keyPos++;
}
+ // Control printing based on how many keys are available
+ if (eligibleKeys.Count > 0)
+ {
+ 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) + "┤");
+ }
+ }
+ }
+ Console.WriteLine("└" + new string('─', keyWidth) + "┴" + new string('─', valueWidth) + "┴" + new string('─', flagWidth) + "┘");
}
void Exit()
{
@@ -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