From c5fc9874b1d226017664e6757c4f41fce358a2f9 Mon Sep 17 00:00:00 2001
From: JFronny <33260128+JFronny@users.noreply.github.com>
Date: Fri, 12 Jun 2020 15:12:13 +0200
Subject: [PATCH] More null proofing
---
Commandline/Commandline.csproj | 1 +
Commandline/TUI/DiffDraw.cs | 14 +++++++-------
Commandline/TUI/Pixel.cs | 2 ++
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Commandline/Commandline.csproj b/Commandline/Commandline.csproj
index 1186f20..49e237f 100644
--- a/Commandline/Commandline.csproj
+++ b/Commandline/Commandline.csproj
@@ -19,6 +19,7 @@
1.0.0.0
0.0
1.1.$(VersionSuffix)
+ enable
diff --git a/Commandline/TUI/DiffDraw.cs b/Commandline/TUI/DiffDraw.cs
index a37e21a..6c925d4 100644
--- a/Commandline/TUI/DiffDraw.cs
+++ b/Commandline/TUI/DiffDraw.cs
@@ -30,8 +30,8 @@ namespace CC_Functions.Commandline.TUI
{
Console.CursorTop = 0;
Console.CursorLeft = 0;
- ConsoleColor fcol = Console.ForegroundColor;
- ConsoleColor bcol = Console.BackgroundColor;
+ ConsoleColor fCol = Console.ForegroundColor;
+ ConsoleColor bCol = Console.BackgroundColor;
int width = Width;
int height = Height;
for (int y = 0; y < height; y++)
@@ -53,8 +53,8 @@ namespace CC_Functions.Commandline.TUI
Console.WriteLine();
Console.CursorLeft = 0;
}
- Console.ForegroundColor = fcol;
- Console.BackgroundColor = bcol;
+ Console.ForegroundColor = fCol;
+ Console.BackgroundColor = bCol;
_last = Screen;
}
@@ -75,8 +75,8 @@ namespace CC_Functions.Commandline.TUI
{
for (int x = 0; x < width; x++)
{
- Pixel tmp1 = Screen[y, x];
- if (color)
+ Pixel? tmp1 = Screen[y, x];
+ if (tmp1 != null && color)
{
if (Console.ForegroundColor != tmp1.ForeColor)
Console.ForegroundColor = tmp1.ForeColor;
@@ -84,7 +84,7 @@ namespace CC_Functions.Commandline.TUI
Console.BackgroundColor = tmp1.BackColor;
}
Console.CursorLeft = x;
- Console.Write(tmp1);
+ Console.Write(tmp1 ?? Pixel.Empty);
}
Console.WriteLine();
Console.CursorLeft = 0;
diff --git a/Commandline/TUI/Pixel.cs b/Commandline/TUI/Pixel.cs
index b065cff..7bd29d8 100644
--- a/Commandline/TUI/Pixel.cs
+++ b/Commandline/TUI/Pixel.cs
@@ -8,6 +8,8 @@ namespace CC_Functions.Commandline.TUI
///
public class Pixel
{
+ public static readonly Pixel Empty = new Pixel();
+
///
/// This pixels background color
///