|
8 | 8 | using System.IO; |
9 | 9 | using System.Linq; |
10 | 10 | using System.Reflection; |
11 | | -using CommandLine.Colors; |
| 11 | +using CommandLine.ColorScheme; |
12 | 12 |
|
13 | 13 | namespace CommandLine |
14 | 14 | { |
15 | 15 | public static partial class Parser |
16 | 16 | { |
17 | | - public static class Configuration |
| 17 | + public static class ColorScheme |
18 | 18 | { |
19 | | - public static bool DisplayErrorMessageOnError { get; set; } = true; |
| 19 | + private static IColors s_helpColors; |
| 20 | + private static object s_lockObj = new object(); |
20 | 21 |
|
21 | | - public static string EnvironmentVariablePrefix { get; set; } = "Commandline_"; |
22 | | - |
23 | | - public static bool UseEnvironmentVariables { get; set; } = true; |
24 | | - |
25 | | - public static class DisplayColors |
| 22 | + public static IColors Get(ConsoleColor backgroundColor = (ConsoleColor)(-1)) |
26 | 23 | { |
27 | | - private static IColors s_helpColors; |
28 | | - private static object s_lockObj = new object(); |
29 | | - |
30 | | - public static IColors Get(ConsoleColor backgroundColor = (ConsoleColor)(-1)) |
| 24 | + if (s_helpColors != null) |
31 | 25 | { |
32 | | - if (s_helpColors != null) |
33 | | - { |
34 | | - return s_helpColors; |
35 | | - } |
| 26 | + return s_helpColors; |
| 27 | + } |
36 | 28 |
|
37 | | - // if the color is not specified, default to the current console's background color. |
38 | | - if (backgroundColor == (ConsoleColor)(-1)) |
39 | | - { |
40 | | - backgroundColor = Console.BackgroundColor; |
41 | | - } |
| 29 | + // if the color is not specified, default to the current console's background color. |
| 30 | + if (backgroundColor == (ConsoleColor)(-1)) |
| 31 | + { |
| 32 | + backgroundColor = Console.BackgroundColor; |
| 33 | + } |
42 | 34 |
|
43 | | - // Get the color scheme. |
44 | | - lock (s_lockObj) |
| 35 | + // Get the color scheme. |
| 36 | + lock (s_lockObj) |
| 37 | + { |
| 38 | + if (s_helpColors == null) |
45 | 39 | { |
46 | | - if (s_helpColors == null) |
47 | | - { |
48 | | - s_helpColors = GetDefault(backgroundColor); |
49 | | - } |
| 40 | + s_helpColors = GetDefault(backgroundColor); |
50 | 41 | } |
51 | | - |
52 | | - return s_helpColors; |
53 | 42 | } |
54 | 43 |
|
55 | | - private static IColors GetDefault(ConsoleColor backgroundColor) |
| 44 | + return s_helpColors; |
| 45 | + } |
| 46 | + |
| 47 | + private static IColors GetDefault(ConsoleColor backgroundColor) |
| 48 | + { |
| 49 | + switch (backgroundColor) |
56 | 50 | { |
57 | | - switch (backgroundColor) |
58 | | - { |
59 | | - case ConsoleColor.Black: |
60 | | - case ConsoleColor.Blue: |
61 | | - case ConsoleColor.DarkBlue: |
62 | | - case ConsoleColor.DarkCyan: |
63 | | - case ConsoleColor.DarkGray: |
64 | | - case ConsoleColor.DarkGreen: |
65 | | - case ConsoleColor.DarkMagenta: |
66 | | - case ConsoleColor.DarkRed: |
67 | | - case ConsoleColor.Magenta: |
68 | | - return new DarkBackgroundColors(); |
69 | | - case ConsoleColor.DarkYellow: |
70 | | - return new DarkYellowBackgroundColors(); |
71 | | - case ConsoleColor.Gray: |
72 | | - return new GrayBackgroundColors(); |
73 | | - case ConsoleColor.Green: |
74 | | - return new GreenBackgroundColors(); |
75 | | - case ConsoleColor.Red: |
76 | | - return new RedBackgroundColors(); |
77 | | - case ConsoleColor.Cyan: |
78 | | - return new CyanBackgroundColors(); |
79 | | - case ConsoleColor.White: |
80 | | - case ConsoleColor.Yellow: |
81 | | - return new LightBackgroundColors(); |
82 | | - default: |
83 | | - return new DarkBackgroundColors(); |
84 | | - } |
| 51 | + case ConsoleColor.Black: |
| 52 | + case ConsoleColor.Blue: |
| 53 | + case ConsoleColor.DarkBlue: |
| 54 | + case ConsoleColor.DarkCyan: |
| 55 | + case ConsoleColor.DarkGray: |
| 56 | + case ConsoleColor.DarkGreen: |
| 57 | + case ConsoleColor.DarkMagenta: |
| 58 | + case ConsoleColor.DarkRed: |
| 59 | + case ConsoleColor.Magenta: |
| 60 | + return new DarkBackground(); |
| 61 | + case ConsoleColor.DarkYellow: |
| 62 | + return new DarkYellowBackground(); |
| 63 | + case ConsoleColor.Gray: |
| 64 | + return new GrayBackground(); |
| 65 | + case ConsoleColor.Green: |
| 66 | + return new GreenBackground(); |
| 67 | + case ConsoleColor.Red: |
| 68 | + return new RedBackground(); |
| 69 | + case ConsoleColor.Cyan: |
| 70 | + return new CyanBackground(); |
| 71 | + case ConsoleColor.White: |
| 72 | + case ConsoleColor.Yellow: |
| 73 | + return new LightBackground(); |
| 74 | + default: |
| 75 | + return new DarkBackground(); |
85 | 76 | } |
| 77 | + } |
86 | 78 |
|
87 | | - public static void Set(IColors colors) |
| 79 | + public static void Set(IColors colors) |
| 80 | + { |
| 81 | + lock (s_lockObj) |
88 | 82 | { |
89 | | - lock (s_lockObj) |
90 | | - { |
91 | | - s_helpColors = colors; |
92 | | - } |
| 83 | + s_helpColors = colors; |
93 | 84 | } |
94 | 85 | } |
95 | 86 | } |
|
0 commit comments