vscode integrate terminal Color issues with C#

I am trying to set background color of the console with Console.BackgroundColor property.
ColoredItem<Sword> blueSword = new ColoredItem<Sword>(new Sword(), ConsoleColor.Blue);
ColoredItem<Bow> redBow = new ColoredItem<Bow>(new Bow(), ConsoleColor.Red);
ColoredItem<Axe> yellowAxe = new ColoredItem<Axe>(new Axe(), ConsoleColor.Green);

blueSword.Display();
redBow.Display();
yellowAxe.Display();

Console.ReadLine();

public class ColoredItem<T>
{
private T item;
private ConsoleColor color;

public ColoredItem(T item, ConsoleColor color)
{
this.item = item;
this.color = color;
}

public void Display()
{
ConsoleColor prevBGColor = Console.BackgroundColor;
Console.BackgroundColor = color;
Console.WriteLine(item);
Console.BackgroundColor = prevBGColor;
}
}
public class Sword { }
public class Bow { }
public class Axe { }
ColoredItem<Sword> blueSword = new ColoredItem<Sword>(new Sword(), ConsoleColor.Blue);
ColoredItem<Bow> redBow = new ColoredItem<Bow>(new Bow(), ConsoleColor.Red);
ColoredItem<Axe> yellowAxe = new ColoredItem<Axe>(new Axe(), ConsoleColor.Green);

blueSword.Display();
redBow.Display();
yellowAxe.Display();

Console.ReadLine();

public class ColoredItem<T>
{
private T item;
private ConsoleColor color;

public ColoredItem(T item, ConsoleColor color)
{
this.item = item;
this.color = color;
}

public void Display()
{
ConsoleColor prevBGColor = Console.BackgroundColor;
Console.BackgroundColor = color;
Console.WriteLine(item);
Console.BackgroundColor = prevBGColor;
}
}
public class Sword { }
public class Bow { }
public class Axe { }
for some reason in vscode integrated terminal I get wrong colors but when running it via dedicated powershell or cmd terminal I don't. I searched around but I could only find a 7 year old issue that was marked resolved
No description
No description
2 Replies
Ganesh
GaneshOP14h ago
Oh it seems that vs code theme affects the colors for terminal. I need to look into this
Ganesh
GaneshOP14h ago
Terminal Appearance
Visual Studio Code's integrated terminal allows customizing its appearance in various ways.

Did you find this page helpful?