tools/compare.cs: change color theme
This commit is contained in:
parent
b86b7175cb
commit
2f4261e405
|
@ -53,27 +53,34 @@ namespace difftool
|
|||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
// color theme:
|
||||
// http://www.eclipsecolorthemes.org/?view=theme&id=47
|
||||
private const string foregroundFont = "<font color=\"#E2E2E2\">";
|
||||
private const string keywordFont = "<font color=\"#8DCBE2\">";
|
||||
private const string numberFont = "<font color=\"#EAB882\">";
|
||||
private const string stringFont = "<font color=\"#CC9393\">";
|
||||
private const string singleLineCommentFont = "<font color=\"#7F9F7F\">";
|
||||
private const string multiLineCommentFont = "<font color=\"#73879B\">";
|
||||
private const string lineNumberFont = "<font color=\"#C0C0C0\">";
|
||||
|
||||
static private void writeSourceFile(string path, string w, string filename) {
|
||||
string errorLoc = w.Substring(0, w.IndexOf(']'));
|
||||
string f = errorLoc.Substring(1, errorLoc.LastIndexOf(':')-1);
|
||||
int errorLine = Int32.Parse(errorLoc.Substring(1 + errorLoc.LastIndexOf(':')));
|
||||
string[] lines = System.IO.File.ReadAllLines(path + f);
|
||||
string[] keywords = { "void", "bool", "char", "short", "int", "long", "class", "struct", "enum", "for", "if", "while", "using", "namespace", "unsigned", "signed", "private", "protected", "public",
|
||||
"static", "const" };
|
||||
string[] keywords = { "void", "bool", "char", "short", "int", "long", "double", "float",
|
||||
"class", "struct", "union", "enum", "namespace",
|
||||
"for", "if", "while", "using", "return", "unsigned", "signed",
|
||||
"private", "protected", "public",
|
||||
"static", "const", "template", "typename", "auto",
|
||||
"true", "false", "this" };
|
||||
System.IO.StreamWriter file = new System.IO.StreamWriter(path + filename);
|
||||
file.Write("<html><body><pre>" + textToHtml(w) + "\n");
|
||||
int linenr = 1;
|
||||
file.Write("<html><head><title>" + textToHtml(w) + "</title></head><body bgcolor=\"#202020\"><pre>" + foregroundFont + textToHtml(w) + "\n");
|
||||
int linenr = 0;
|
||||
bool multiline = false;
|
||||
foreach (string line in lines) {
|
||||
if (errorLine == linenr)
|
||||
{
|
||||
file.Write("<span style=\"background-color: red\">" + (linenr.ToString() + ": ").Substring(0, 8) + textToHtml(line) + "</span>\n");
|
||||
file.Write("<span style=\"background-color: red\">" + textToHtml(w.Substring(errorLoc.Length+2)) + "</span>\n");
|
||||
linenr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
file.Write((linenr.ToString() + ": ").Substring(0, 8));
|
||||
linenr++;
|
||||
++linenr;
|
||||
file.Write(lineNumberFont + (linenr.ToString() + " ").Substring(0, 8) + "</font>");
|
||||
|
||||
for (int i = 0; i < line.Length;) {
|
||||
if (line[i] == ' ')
|
||||
|
@ -81,6 +88,18 @@ namespace difftool
|
|||
file.Write(line[i]);
|
||||
i++;
|
||||
}
|
||||
else if (multiline)
|
||||
{
|
||||
string currentToken = "";
|
||||
while (i < line.Length && multiline)
|
||||
{
|
||||
currentToken += line[i];
|
||||
i++;
|
||||
if (currentToken.EndsWith("*/"))
|
||||
multiline = false;
|
||||
}
|
||||
file.Write(multiLineCommentFont + textToHtml(currentToken) + "</font>");
|
||||
}
|
||||
else if (isNameChar(line[i]))
|
||||
{
|
||||
string currentToken = "";
|
||||
|
@ -90,9 +109,9 @@ namespace difftool
|
|||
i++;
|
||||
}
|
||||
if (keywords.Contains(currentToken))
|
||||
file.Write("<b>" + currentToken + "</b>");
|
||||
file.Write(keywordFont + currentToken + "</font>");
|
||||
else if (currentToken[0] >= '0' && currentToken[0] <= '9')
|
||||
file.Write("<font color=\"blue\">" + currentToken + "</font>");
|
||||
file.Write(numberFont + currentToken + "</font>");
|
||||
else
|
||||
file.Write(currentToken);
|
||||
}
|
||||
|
@ -106,22 +125,39 @@ namespace difftool
|
|||
if (currentToken.Length > 1 && currentToken[0] == line[i - 1])
|
||||
break;
|
||||
}
|
||||
file.Write("<font color=\"red\">" + textToHtml(currentToken) + "</font>");
|
||||
file.Write(stringFont + textToHtml(currentToken) + "</font>");
|
||||
}
|
||||
else if (line[i] == '/' && i + 1 < line.Length && line[i + 1] == '/')
|
||||
{
|
||||
file.Write("<font color=\"gray\">" + textToHtml(line.Substring(i)) + "</font>");
|
||||
file.Write(singleLineCommentFont + textToHtml(line.Substring(i)) + "</font>");
|
||||
i = line.Length;
|
||||
}
|
||||
else if (line[i] == '/' && i + 1 < line.Length && line[i + 1] == '*')
|
||||
{
|
||||
multiline = true;
|
||||
string currentToken = "/*";
|
||||
i += 2;
|
||||
while (i < line.Length && multiline)
|
||||
{
|
||||
currentToken += line[i];
|
||||
i++;
|
||||
if (currentToken.Length > 3 && currentToken.EndsWith("*/"))
|
||||
multiline = false;
|
||||
}
|
||||
file.Write(multiLineCommentFont + textToHtml(currentToken) + "</font>");
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Write(textToHtml(line.Substring(i,1)));
|
||||
file.Write(textToHtml(line.Substring(i, 1)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
file.Write('\n');
|
||||
|
||||
if (errorLine == linenr)
|
||||
file.Write(" <mark>" + textToHtml(w.Substring(errorLoc.Length + 2)) + "</mark>\n");
|
||||
}
|
||||
file.Write("</pre></body></html>");
|
||||
file.Write("</font></pre></body></html>");
|
||||
file.Close();
|
||||
}
|
||||
|
||||
|
@ -157,13 +193,22 @@ namespace difftool
|
|||
file.WriteLine("<head>");
|
||||
file.WriteLine("<title>Comparison 1.82 / Head</title>");
|
||||
file.WriteLine("</head>");
|
||||
file.WriteLine("<body>");
|
||||
file.WriteLine("<body bgcolor=\"#1e1e1e\">");
|
||||
file.WriteLine(keywordFont);
|
||||
|
||||
file.WriteLine("<h1>Comparison 1.82 / Head</h1>");
|
||||
file.WriteLine("<p>Package: {0}</p>", @"ftp://ftp.se.debian.org/debian/pool/main/f/firefox/firefox_59.0~b4.orig.tar.bz2");
|
||||
file.WriteLine("<p>+ Added warnings {0}</p>", added.Count);
|
||||
file.WriteLine("<p>- Removed warnings {0}</p>", removed.Count);
|
||||
|
||||
file.WriteLine("<svg width=\"{0}\" height=\"{1}\">", 60 + Math.Max(added.Count, removed.Count) + 10, 40);
|
||||
file.WriteLine(" <rect x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" stroke=\"#8DCBE2\" fill=\"#303030\"/>");
|
||||
file.WriteLine(" <text x=\"4\" y=\"15\" font-family=\"Verdana\" font-size=\"10\" fill=\"#8DCBE2\">Added</text>");
|
||||
file.WriteLine(" <text x=\"4\" y=\"30\" font-family=\"Verdana\" font-size=\"10\" fill=\"#8DCBE2\">Removed</text>");
|
||||
file.WriteLine(" <rect x=\"60\" y=\"8\" width=\"{0}\" height=\"8\" fill=\"#40ff40\" />", added.Count);
|
||||
file.WriteLine(" <rect x=\"60\" y=\"23\" width=\"{0}\" height=\"8\" fill=\"#ff4040\" />", removed.Count);
|
||||
file.WriteLine("</svg>");
|
||||
|
||||
file.WriteLine("<h2>Added warnings</h2>");
|
||||
file.WriteLine("<pre>");
|
||||
foreach (string w in added)
|
||||
|
|
Loading…
Reference in New Issue