-
-
Notifications
You must be signed in to change notification settings - Fork 566
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
Fix the gravity output to use the ${OVER} sequence #2725
Conversation
1926532
to
c52cb8c
Compare
c52cb8c
to
4156d96
Compare
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.
This code has a severe limitation: If \r
is found, it actually needs to be the first character or the rest of the code (removing the immediately preceding line) does not make much sense and causes incorrect behavior.
In other words, I could also say that this code really depends on not more than one line being sent at the same time.
This is true in our current API design (each line is immediately pushed as a chunk), but it may be useful to be somewhat more explicit in the code (see additional review comments).
scripts/pi-hole/js/gravity.js
Outdated
ta.append(string); | ||
|
||
// If a Carriage Return is found ... | ||
if (string.indexOf("\r") === -1) { |
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.
Isn't this functionally equivalent to the easier to read/understand
if (string.indexOf("\r") === -1) { | |
if (string[0] !== '\r') { |
?
See also my main review comment why I think this is the case.
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.
They are not the same:
string.indexOf("\r") === -1
will be false
if \r
is found in the string (in any position).
Your suggestion will be false
only if the first character is \r
.
var string = "test\r";
if (string.indexOf("\r") === -1) {
console.log("CR not found");
} else {
console.log("CR found at "+string.indexOf("\r"));
}
Output: CR found at 4
.
Notes:
- In v5 we always sent one line at a time and we still do it.
- we always sent
\r
as the first character.
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.
Sure that, but your example even underlines my point :-)
Assume we already have
abc
def
ghi
and not receive your chunk test\r
.
The trailing \r
would trigger removing ghi
even though this is completely wrong.
With my suggested change, however, the code would not remove ghi
and the output would become:
abc
def
ghi
test
IMO this is the correct behavior.
scripts/pi-hole/js/gravity.js
Outdated
ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")) + "\n"); | ||
// ... and append the new text to the end of the output, | ||
// without ${OVER} ("CR + ESC[K") or Carriage Return. | ||
ta.append(string.replaceAll("\r[K", "").replaceAll("\r", "")); |
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.
This .replaceAll()
kinda feels wrong to me but being aware of the one-line-after-another chunking, it is still doing what it should - even when it doesn't feel right (subjective feeling all the way).
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.
We can create a function to proper cleanup the string, removing "\r�[K", "\r".
We can even allow the use of color codes and replace them with HTML <span>
tags with CSS classes to use color output (like we had in v5).
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.
Yeah, color codes may be even nicer but it may be over the top. If we want to go entirely crazy we could even make FTL send <span ...> ... </span>
already by itself when requesting via the API.
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.
Let's not get crazy here... formatting should be done by the receiving/displaying component, not the sending one, I think.
Actually that was my assumption, because this was the behavior for v5 and this is the behavior I saw with the current code. We can change that if needed, but: "Do we need to change this?" To tell the truth, I just adapted the code we currently have in In v6 I moved the 2 replace calls to javascript. |
Signed-off-by: RD WebDesign <[email protected]>
22792b8
to
8ef2a64
Compare
Signed-off-by: RD WebDesign <[email protected]>
8ef2a64
to
d62077c
Compare
Signed-off-by: RD WebDesign <[email protected]>
What does this PR aim to accomplish?:
The "OVER" sequence
CR + ESC[K
is not working as expected.The current code is just replacing the "OVER" sequence with a newline and printing the text after the previous line.
Also, the FTL
gravity_parseList()
function is sending only a Carriage Return (\r
) instead of the full OVER sequence, because the web interface is not a terminal. This prints one very long line with the text of all Progress lines contatenated.How does this PR accomplish the above?:
The new code fixes this:
When "OVER" is found, the last line on the screen is REPLACED by the new text (like it was in v5).
Link documentation PRs if any are needed to support this PR:
none
By submitting this pull request, I confirm the following:
git rebase
)