Skip to content

Commit 050bacb

Browse files
committed
Use official syntax highlighting colours
These are specific to .NET, but it looks good universally.
1 parent 3267918 commit 050bacb

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

src/Riverside.JsonBinder.Console/Helpers/SyntaxHighlighter.cs

+48-48
Original file line numberDiff line numberDiff line change
@@ -10,116 +10,116 @@ public static class SyntaxHighlighter
1010
SerializableLanguage.CSharp, new List<SyntaxRule>
1111
{
1212
// Core keywords
13-
new(@"\b(abstract|as|base|break|case|catch|checked|class|const|continue|default|delegate|do|else|enum|event|explicit|extern|finally|fixed|for|foreach|goto|if|implicit|in|interface|internal|is|lock|namespace|new|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|static|switch|this|throw|try|typeof|unchecked|unsafe|using|virtual|volatile|while|get|set)\b", ConsoleColor.Magenta),
13+
new(@"\b(abstract|as|base|break|case|catch|checked|class|const|continue|default|delegate|do|else|enum|event|explicit|extern|finally|fixed|for|foreach|goto|if|implicit|in|interface|internal|is|lock|namespace|new|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|static|switch|this|throw|try|typeof|unchecked|unsafe|using|virtual|volatile|while|get|set)\b", ConsoleColor.Red),
1414

1515
// Types
16-
new(@"\b(bool|byte|char|decimal|double|float|int|long|object|sbyte|short|string|uint|ulong|ushort|void|var)\b", ConsoleColor.DarkCyan),
16+
new(@"\b(bool|byte|char|decimal|double|float|int|long|object|sbyte|short|string|uint|ulong|ushort|void|var)\b", ConsoleColor.White),
1717

1818
// Type definitions (classes, interfaces, etc.)
19-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
19+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
2020

2121
// Properties and methods
22-
new(@"\b[a-z][a-zA-Z0-9_]*(?=\s*[{<])", ConsoleColor.Yellow),
22+
new(@"\b[a-z][a-zA-Z0-9_]*(?=\s*[{<])", ConsoleColor.Magenta),
2323

2424
// Generic type parameters
2525
new(@"<[^>]+>", ConsoleColor.DarkYellow),
2626

2727
// Numbers
28-
new(@"\b\d+\b", ConsoleColor.Green),
28+
new(@"\b\d+\b", ConsoleColor.Blue),
2929

3030
// Strings
31-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.DarkGreen),
31+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.Cyan),
3232
}
3333
},
3434
{
3535
SerializableLanguage.Python, new List<SyntaxRule>
3636
{
3737
// Keywords
38-
new(@"\b(and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b", ConsoleColor.Magenta),
38+
new(@"\b(and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b", ConsoleColor.Red),
3939

4040
// Built-in types and values
41-
new(@"\b(True|False|None|bool|int|float|str|list|dict|set|tuple)\b", ConsoleColor.DarkCyan),
41+
new(@"\b(True|False|None|bool|int|float|str|list|dict|set|tuple)\b", ConsoleColor.White),
4242

4343
// Class names
44-
new(@"(?<=\bclass\s+)\w+", ConsoleColor.Cyan),
44+
new(@"(?<=\bclass\s+)\w+", ConsoleColor.Gray),
4545

4646
// Function definitions
47-
new(@"(?<=\bdef\s+)\w+", ConsoleColor.Yellow),
47+
new(@"(?<=\bdef\s+)\w+", ConsoleColor.Magenta),
4848

4949
// Decorators
5050
new(@"@\w+", ConsoleColor.DarkYellow),
5151

5252
// Numbers
53-
new(@"\b\d+\b", ConsoleColor.Green),
53+
new(@"\b\d+\b", ConsoleColor.Blue),
5454

5555
// Strings
56-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'", ConsoleColor.DarkGreen),
56+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'", ConsoleColor.Cyan),
5757
}
5858
},
5959
{
6060
SerializableLanguage.JavaScript, new List<SyntaxRule>
6161
{
6262
// Keywords
63-
new(@"\b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b", ConsoleColor.Magenta),
63+
new(@"\b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b", ConsoleColor.Red),
6464

6565
// Built-in objects and types
66-
new(@"\b(Array|Boolean|Date|Error|Function|JSON|Math|Number|Object|RegExp|String|Promise|Map|Set|Symbol|BigInt)\b", ConsoleColor.DarkCyan),
66+
new(@"\b(Array|Boolean|Date|Error|Function|JSON|Math|Number|Object|RegExp|String|Promise|Map|Set|Symbol|BigInt)\b", ConsoleColor.White),
6767

6868
// Class names and custom types
69-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
69+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
7070

7171
// Function declarations
72-
new(@"(?<=\bfunction\s+)\w+", ConsoleColor.Yellow),
72+
new(@"(?<=\bfunction\s+)\w+", ConsoleColor.Magenta),
7373

7474
// Arrow functions
7575
new(@"=>\s*{", ConsoleColor.DarkYellow),
7676

7777
// Numbers
78-
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Green),
78+
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Blue),
7979

8080
// Strings
81-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`", ConsoleColor.DarkGreen),
81+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`", ConsoleColor.Cyan),
8282
}
8383
},
8484
{
8585
SerializableLanguage.TypeScript, new List<SyntaxRule>
8686
{
8787
// TypeScript-specific keywords
88-
new(@"\b(abstract|as|asserts|async|await|break|case|catch|class|const|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|if|implements|import|in|infer|instanceof|interface|is|keyof|let|module|namespace|new|null|of|return|super|switch|this|throw|try|type|typeof|undefined|unique|unknown|var|void|while|with|yield)\b", ConsoleColor.Magenta),
88+
new(@"\b(abstract|as|asserts|async|await|break|case|catch|class|const|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|if|implements|import|in|infer|instanceof|interface|is|keyof|let|module|namespace|new|null|of|return|super|switch|this|throw|try|type|typeof|undefined|unique|unknown|var|void|while|with|yield)\b", ConsoleColor.Red),
8989

9090
// Types and type operators
91-
new(@"\b(any|boolean|number|string|symbol|never|object|bigint|readonly|private|protected|public|static)\b", ConsoleColor.DarkCyan),
91+
new(@"\b(any|boolean|number|string|symbol|never|object|bigint|readonly|private|protected|public|static)\b", ConsoleColor.White),
9292

9393
// Classes and interfaces
94-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
94+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
9595

9696
// Generics
97-
new(@"<[^>]+>", ConsoleColor.Yellow),
97+
new(@"<[^>]+>", ConsoleColor.Magenta),
9898

9999
// Decorators
100100
new(@"@\w+", ConsoleColor.DarkYellow),
101101

102102
// Numbers
103-
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Green),
103+
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Blue),
104104

105105
// Strings
106-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`", ConsoleColor.DarkGreen),
106+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`", ConsoleColor.Cyan),
107107
}
108108
},
109109
{
110110
SerializableLanguage.Java, new List<SyntaxRule>
111111
{
112112
// Keywords
113-
new(@"\b(abstract|assert|break|case|catch|class|const|continue|default|do|else|enum|extends|final|finally|for|if|implements|import|instanceof|interface|native|new|package|private|protected|public|return|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|volatile|while)\b", ConsoleColor.Magenta),
113+
new(@"\b(abstract|assert|break|case|catch|class|const|continue|default|do|else|enum|extends|final|finally|for|if|implements|import|instanceof|interface|native|new|package|private|protected|public|return|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|volatile|while)\b", ConsoleColor.Red),
114114

115115
// Types
116-
new(@"\b(boolean|byte|char|double|float|int|long|short|void|var)\b", ConsoleColor.DarkCyan),
116+
new(@"\b(boolean|byte|char|double|float|int|long|short|void|var)\b", ConsoleColor.White),
117117

118118
// Class names and custom types
119-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
119+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
120120

121121
// Method declarations
122-
new(@"(?<=\b\w+\s+)\w+(?=\s*\()", ConsoleColor.Yellow),
122+
new(@"(?<=\b\w+\s+)\w+(?=\s*\()", ConsoleColor.Magenta),
123123

124124
// Generics
125125
new(@"<[^>]+>", ConsoleColor.DarkYellow),
@@ -128,51 +128,51 @@ public static class SyntaxHighlighter
128128
new(@"@\w+", ConsoleColor.DarkYellow),
129129

130130
// Numbers
131-
new(@"\b\d+(\.\d+)?[dDfFlL]?\b", ConsoleColor.Green),
131+
new(@"\b\d+(\.\d+)?[dDfFlL]?\b", ConsoleColor.Blue),
132132

133133
// Strings
134-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.DarkGreen),
134+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.Cyan),
135135
}
136136
},
137137
{
138138
SerializableLanguage.PHP, new List<SyntaxRule>
139139
{
140140
// Keywords
141-
new(@"\b(abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|yield|yield from)\b", ConsoleColor.Magenta),
141+
new(@"\b(abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|yield|yield from)\b", ConsoleColor.Red),
142142

143143
// Types and type hints
144-
new(@"\b(bool|boolean|int|integer|float|double|string|array|object|callable|iterable|void|null|mixed|never|true|false)\b", ConsoleColor.DarkCyan),
144+
new(@"\b(bool|boolean|int|integer|float|double|string|array|object|callable|iterable|void|null|mixed|never|true|false)\b", ConsoleColor.White),
145145

146146
// Class names and namespaces
147-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
147+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
148148

149149
// Function declarations
150-
new(@"(?<=\bfunction\s+)\w+", ConsoleColor.Yellow),
150+
new(@"(?<=\bfunction\s+)\w+", ConsoleColor.Magenta),
151151

152152
// Variables
153153
new(@"\$\w+", ConsoleColor.DarkYellow),
154154

155155
// Numbers
156-
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Green),
156+
new(@"\b\d+(\.\d+)?\b", ConsoleColor.Blue),
157157

158158
// Strings
159-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'", ConsoleColor.DarkGreen),
159+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'", ConsoleColor.Cyan),
160160
}
161161
},
162162
{
163163
SerializableLanguage.Ruby, new List<SyntaxRule>
164164
{
165165
// Keywords
166-
new(@"\b(alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\b", ConsoleColor.Magenta),
166+
new(@"\b(alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\b", ConsoleColor.Red),
167167

168168
// Built-in classes and modules
169-
new(@"\b(Array|Hash|String|Integer|Float|Symbol|Range|Regexp|Time|File|Dir|Class|Module|Enumerable|Comparable|Kernel|Process|Thread)\b", ConsoleColor.DarkCyan),
169+
new(@"\b(Array|Hash|String|Integer|Float|Symbol|Range|Regexp|Time|File|Dir|Class|Module|Enumerable|Comparable|Kernel|Process|Thread)\b", ConsoleColor.White),
170170

171171
// Class and module names
172-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
172+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
173173

174174
// Method declarations
175-
new(@"(?<=\bdef\s+)\w+", ConsoleColor.Yellow),
175+
new(@"(?<=\bdef\s+)\w+", ConsoleColor.Magenta),
176176

177177
// Symbols
178178
new(@":\w+", ConsoleColor.DarkYellow),
@@ -181,26 +181,26 @@ public static class SyntaxHighlighter
181181
new(@"@{1,2}\w+", ConsoleColor.DarkYellow),
182182

183183
// Numbers
184-
new(@"\b\d+(\.\d+)?(e[+-]?\d+)?\b", ConsoleColor.Green),
184+
new(@"\b\d+(\.\d+)?(e[+-]?\d+)?\b", ConsoleColor.Blue),
185185

186186
// Strings
187-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|%[qQ]?\{[^}]*\}|%[qQ]?\[[^\]]*\]|%[qQ]?\([^)]*\)|%[qQ]?<[^>]*>", ConsoleColor.DarkGreen),
187+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'|%[qQ]?\{[^}]*\}|%[qQ]?\[[^\]]*\]|%[qQ]?\([^)]*\)|%[qQ]?<[^>]*>", ConsoleColor.Cyan),
188188
}
189189
},
190190
{
191191
SerializableLanguage.Swift, new List<SyntaxRule>
192192
{
193193
// Keywords
194-
new(@"\b(associatedtype|class|deinit|enum|extension|fileprivate|func|import|init|inout|internal|let|open|operator|private|precedencegroup|protocol|public|rethrows|static|struct|subscript|typealias|var|break|case|continue|default|defer|do|else|fallthrough|for|guard|if|in|repeat|return|switch|where|while|as|Any|catch|false|is|nil|super|self|Self|throw|throws|true|try)\b", ConsoleColor.Magenta),
194+
new(@"\b(associatedtype|class|deinit|enum|extension|fileprivate|func|import|init|inout|internal|let|open|operator|private|precedencegroup|protocol|public|rethrows|static|struct|subscript|typealias|var|break|case|continue|default|defer|do|else|fallthrough|for|guard|if|in|repeat|return|switch|where|while|as|Any|catch|false|is|nil|super|self|Self|throw|throws|true|try)\b", ConsoleColor.Red),
195195

196196
// Types
197-
new(@"\b(Int|Double|Float|Bool|String|Character|Optional|Array|Dictionary|Set|Result|Error)\b", ConsoleColor.DarkCyan),
197+
new(@"\b(Int|Double|Float|Bool|String|Character|Optional|Array|Dictionary|Set|Result|Error)\b", ConsoleColor.White),
198198

199199
// Type names and protocols
200-
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Cyan),
200+
new(@"\b[A-Z][a-zA-Z0-9_]*\b", ConsoleColor.Gray),
201201

202202
// Function declarations
203-
new(@"(?<=\bfunc\s+)\w+", ConsoleColor.Yellow),
203+
new(@"(?<=\bfunc\s+)\w+", ConsoleColor.Magenta),
204204

205205
// Property wrappers and attributes
206206
new(@"@\w+", ConsoleColor.DarkYellow),
@@ -209,10 +209,10 @@ public static class SyntaxHighlighter
209209
new(@"<[^>]+>", ConsoleColor.DarkYellow),
210210

211211
// Numbers
212-
new(@"\b\d+(\.\d+)?([eE][+-]?\d+)?\b", ConsoleColor.Green),
212+
new(@"\b\d+(\.\d+)?([eE][+-]?\d+)?\b", ConsoleColor.Blue),
213213

214214
// Strings
215-
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.DarkGreen),
215+
new(@"""[^""\\]*(?:\\.[^""\\]*)*""", ConsoleColor.Cyan),
216216
}
217217
}
218218
};

src/Riverside.JsonBinder.Console/InteractiveMode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static void ConvertJsonToClasses()
8787
try
8888
{
8989
string result = JsonSerializer.ConvertTo(json, language);
90-
System.Console.ForegroundColor = ConsoleColor.Green;
90+
System.Console.ForegroundColor = ConsoleColor.Blue;
9191
System.Console.WriteLine($"\n{language} Classes:\n");
9292
System.Console.ResetColor();
9393

0 commit comments

Comments
 (0)