-
-
Notifications
You must be signed in to change notification settings - Fork 624
Add some color to gravity output #3530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: yubiuser <[email protected]>
|
Why don't we use the escape code directly? FTL should be able to sending everything through the API, cfm. excerpt from what is sent to the browser:
(see that this matches 100% the first four bytes in the stream excerpt above!) Just saying this as there is also bold bold text in the output plus maybe some colors when FTL finds an error in the lists (but I may be misremembering this one). It is kind of odd that |
The issue is: we only send color escape codes via We would need to replace those characters with the relevant CSS class. This is what #3191 did.
You are correct, but I did not want check for all possible replacement text, this will break earlier or later. I just went for the text/symbols that should stay constant |
|
In v5 gravity was never in colors.
In v5 we sent the color codes in 2 cases:
|
Signed-off-by: yubiuser <[email protected]>
|
We decided to change a bit more. Together with pi-hole/pi-hole#6314 and pi-hole/FTL#2538 all escape sequences are send to the web interface and this PR translates them to the corresponding CSS classes |
DL6ER
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works like this but we need to be cautious in the future. The issue is that we may see two escape sequences following each other (like color + bold face) adding two <span> but only one resetting COL_NC adding only one </span>
|
Idea: We could use a counter here - for each |
Signed-off-by: yubiuser <[email protected]>
Signed-off-by: yubiuser <[email protected]>
|
AI refactored code, so untested but you get the idea. // Track the number of opening <span> tags inserted.
let spanCount = 0;
// Mapping of ANSI escape codes to their corresponding CSS class names.
const ansiMappings = {
"\x1b[1m": "text-bold",
"\x1b[90m": "log-gray",
"\x1b[91m": "log-red",
"\x1b[32m": "log-green",
"\x1b[33m": "log-yellow",
"\x1b[94m": "log-blue",
"\x1b[95m": "log-purple",
"\x1b[96m": "log-cyan"
};
// Replace each ANSI escape code with its corresponding HTML tag.
for (const [ansiCode, cssClass] of Object.entries(ansiMappings)) {
line = line.replaceAll(ansiCode, () => {
spanCount++;
return `<span class="${cssClass}">`;
});
}
// Replace the ANSI reset code with the correct number of closing </span> tags.
line = line.replaceAll("\x1b[0m", "</span>".repeat(spanCount));The for loop is a must have IMHO. |
Signed-off-by: yubiuser <[email protected]>
|
I think this is the right approach: replacing sequentially to always add the correct number of closing
|
…once we hit {COL_NC}
Signed-off-by: yubiuser <[email protected]>
What does this PR aim to accomplish?:
Add some color to gravity output. When we call
gravityfrom the web interface, all ANSI escape codes are removed from the output stream fromCOL_TABLEhttps://github.com/pi-hole/pi-hole/blob/ec892ec096cd1adb90b0209d4c0a155953faf813/advanced/Scripts/COL_TABLE#L17-L29
However, we can re-add them because we know the tick and the cross are shown in colors.
By submitting this pull request, I confirm the following:
git rebase)