Skip to content

New truth table generation & styles #2

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

Merged
merged 8 commits into from
Dec 6, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add true/false colour command line args
  • Loading branch information
Tom committed Dec 6, 2022
commit 735675b92febae028d19c27f2a11b29a248f03fd
14 changes: 10 additions & 4 deletions BooleanExpressionParser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ private static void Main(string[] args)

var trueOption = new Option<string>(new[] { "--true", "-t" }, () => "1", description: "Character to use for true values in the truth table.");
var falseOption = new Option<string>(new[] { "--false", "-f" }, () => "0", description: "Character to use for false values in the truth table.");
var colourModeOption = new Option<ColourMode>(new[] { "--colour-mode", "-c" }, () => ColourMode.Foreground, description: "Whether to colour the truth table with foreground or background colours (or no colours).");
var colourModeOption = new Option<ColourMode>(new[] { "--colour-mode", "--color-mode", "-c" }, () => ColourMode.Foreground, description: "Whether to colour the truth table with foreground or background colours (or no colours).");
var trueColourOption = new Option<string>(new[] { "--true-colour", "--true-color" }, () => "green", description: "The colour to use for true values in the truth table.");
var falseColourOption = new Option<string>(new[] { "--false-colour", "--false-color" }, () => "red", description: "The colour to use for false values in the truth table.");
var expressionsArgument = new Argument<string[]>("expression(s)", description: "The boolean expression(s) to evaluate.");

var tableCommand = new Command("table", description: "Prints the truth table of a boolean expression(s). If none are provided, the user will be prompted to enter them.")
{
trueOption,
falseOption,
colourModeOption,
trueColourOption,
falseColourOption,
expressionsArgument
};

tableCommand.SetHandler(Run, trueOption, falseOption, colourModeOption, expressionsArgument);
tableCommand.SetHandler(Run, trueOption, falseOption, colourModeOption, trueColourOption, falseColourOption, expressionsArgument);

rootCommand.AddCommand(tableCommand);

rootCommand.Invoke(args);
}


private static void Run(string @true, string @false, ColourMode colourMode, string[] args)
private static void Run(string @true, string @false, ColourMode colourMode, string trueColour, string falseColour, string[] args)
{
Console.OutputEncoding = Encoding.UTF8;

Expand All @@ -56,7 +60,9 @@ private static void Run(string @true, string @false, ColourMode colourMode, stri
{
True = @true,
False = @false,
ColourMode = colourMode
ColourMode = colourMode,
TrueColour = trueColour,
FalseColour = falseColour
};

foreach (var expression in expressions)
Expand Down