diff --git a/README.md b/README.md index c34311b..33ca911 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ To avoid these cases, it's possible to pass the "--skipTests" option. #### Configuration By default all checks are enabled. Individual checks can be enabled or disabled by using a configuration file. Such a file can be placed, for example, is the root directory of your project. -Running ```dscanner --defaultConfig``` will generate a default configuration file and print the file's location. +Running `dscanner --defaultConfig` will generate a default configuration file and print the file's location. You can also specify the path to a configuration file by using the "--config" option if you want to override the default or the local settings. @@ -306,8 +306,15 @@ and case tokens in the file. ### Syntax Highlighting The "--highlight" option prints the given source file as syntax-highlighted HTML -to the standard output. The CSS styling is currently hard-coded to use the -[Solarized](http://ethanschoonover.com/solarized) color scheme. +to the standard output. The CSS styling uses the [Solarized](http://ethanschoonover.com/solarized) +color scheme by default, but can be customised using the "--theme" option. + +The following themes are available: + +- `solarized` +- `solarized-dark` +- `gruvbox` +- `gruvbox-dark` No example. It would take up too much space diff --git a/src/dscanner/highlighter.d b/src/dscanner/highlighter.d index 86860cd..55fbcb4 100644 --- a/src/dscanner/highlighter.d +++ b/src/dscanner/highlighter.d @@ -10,8 +10,10 @@ import std.array; import dparse.lexer; // http://ethanschoonover.com/solarized -void highlight(R)(ref R tokens, string fileName) +void highlight(R)(ref R tokens, string fileName, string themeName) { + immutable(Theme)* theme = getTheme(themeName); + stdout.writeln(q"[ @@ -20,17 +22,19 @@ void highlight(R)(ref R tokens, string fileName) stdout.writeln("
]");
+", theme.bg, theme.fg, theme.kwrd, theme.com, theme.num, theme.str,
+ theme.op, theme.type, theme.cons);
while (!tokens.empty)
{
@@ -76,3 +80,37 @@ void writeSpan(string cssClass, string value)
stdout.write(``, value.replace("&",
"&").replace("<", "<"), ``);
}
+
+struct Theme
+{
+ string bg;
+ string fg;
+ string kwrd;
+ string com;
+ string num;
+ string str;
+ string op;
+ string type;
+ string cons;
+}
+
+immutable(Theme)* getTheme(string themeName)
+{
+ immutable Theme[string] themes = [
+ "solarized": Theme("#fdf6e3", "#002b36", "#b58900", "#93a1a1", "#dc322f", "#2aa198", "#586e75",
+ "#268bd2", "#859900"),
+ "solarized-dark": Theme("#002b36", "#fdf6e3", "#b58900", "#586e75", "#dc322f", "#2aa198",
+ "#93a1a1", "#268bd2", "#859900"),
+ "gruvbox": Theme("#fbf1c7", "#282828", "#b57614", "#a89984", "#9d0006", "#427b58",
+ "#504945", "#076678", "#79740e"),
+ "gruvbox-dark": Theme("#282828", "#fbf1c7", "#d79921", "#7c6f64",
+ "#cc241d", "#689d6a", "#a89984", "#458588", "#98971a")
+ ];
+
+ immutable(Theme)* theme = themeName in themes;
+ // Default theme
+ if (theme is null)
+ theme = &themes["solarized"];
+
+ return theme;
+}
diff --git a/src/dscanner/main.d b/src/dscanner/main.d
index 1507098..f412dc5 100644
--- a/src/dscanner/main.d
+++ b/src/dscanner/main.d
@@ -65,6 +65,7 @@ else
bool report;
bool skipTests;
bool applySingleFixes;
+ string theme;
string resolveMessage;
string reportFormat;
string reportFile;
@@ -85,6 +86,7 @@ else
getopt(args, std.getopt.config.caseSensitive,
"sloc|l", &sloc,
"highlight", &highlight,
+ "theme", &theme,
"ctags|c", &ctags,
"help|h", &help,
"etags|e", &etags,
@@ -257,7 +259,7 @@ else
if (highlight)
{
auto tokens = byToken(bytes, config, &cache);
- dscanner.highlighter.highlight(tokens, args.length == 1 ? "stdin" : args[1]);
+ dscanner.highlighter.highlight(tokens, args.length == 1 ? "stdin" : args[1], theme);
return 0;
}
else if (tokenDump)