Mono C # weird console color

I have this Consoleartistic function,

public static void Ask(string message)
{
    ConsoleColor previousColor = Console.ForegroundColor;
    Console.ForegroundColor = ConsoleColor.White;
    Console.Write (message);
    Console.Write (" : ");
    Console.ForegroundColor = previousColor;
}

This is my Main()

Console.WriteLine("Hello World");
Ask("Roll No");

Two printed colors whitedo not match as shown below

Screenshot

In the debugger, I see that previousColoras well ConsoleColor.White.

+4
source share
1 answer

This is an area that sometimes causes confusion. Call it a limitation rather than a mistake.

There are two important factors:

  • , X, xterm rxvt, 1990- : , ANSI ( ), Linux, , ANSI .

    VTE ( ) , Konsole.

    xterm reverseVideo , ANSI , :

               Other control sequences can alter the foreground and background
               colors which are used:

               o   Programs can also use the ANSI color control  sequences  to
                   set the foreground and background colors.

               o   Extensions  to the ANSI color controls (such as 16-, 88- or
                   256-colors) are treated similarly to the ANSI control.

               o   Using other control sequences (the  "dynamic  colors"  fea-
                   ture),  a  program can change the foreground and background
                   colors.
  1. Console ( , ) ncurses. ncurses Ncurses / , ncurses , — Console .

    ncurses , "", , "" ( ).

+3

Source: https://habr.com/ru/post/1605973/


All Articles