Skip to content
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

Tweak the Update Gravity output #2589

Merged
merged 3 commits into from
May 24, 2023
Merged

Conversation

rdwebdesign
Copy link
Member

@rdwebdesign rdwebdesign commented May 18, 2023

What does this PR aim to accomplish?

This PR is intended to show the progress of the new parseList function introduced by pi-hole/FTL#1559 and pi-hole/pi-hole#5275.

The new pihole-FTL gravity parseList command starts every message (including error messages) with \r, to allow overwriting lines on the command line output.

The problem is: this brakes the web interface output and no output is shown for this command.

Replacing the initial \r allows the correct output.

How does this PR accomplish the above?

Kepping the original str_replace and adding a second one, to replace any remaining \r with '<------'.

Note:

Use all 3 branches when testing: FTL, core and web.

Link documentation PRs if any are needed to support this PR:

none


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

Replaces every `\r` returned by `pihole-FTL gravity parseList` with a
known string to allow overwriting the previous line.

Signed-off-by: RD WebDesign <[email protected]>
@rdwebdesign rdwebdesign requested a review from a team May 19, 2023 19:15
@yubiuser
Copy link
Member

I tried it and with this PR I can see the progress counting. However I fail to see a single occurrence of <------

Is this expected?

@rdwebdesign
Copy link
Member Author

Yes.

The <------ string is used only internally and it is replaced.

@yubiuser
Copy link
Member

Ah I see... it's the code right below. You search for the position in the line string and remove everything you don't want.

@rdwebdesign
Copy link
Member Author

rdwebdesign commented May 22, 2023

The logic is:

gravity.sh output is used both on the console and the web interface.

On the console, it uses a carriage return followed by an escape code (ESC+[K) to "go back to the start of the line and clear from the cursor to the end of the line". This is used to allow "overprinting" lines, on the same place (similar to PADD).

This escape sequence is sent to PHP/javascript. PHP replace it with <------. If the string appears on the middle of the line, PHP strips the text before the <------.

The text is sent to javascript with <------. The java script code removes it and removes the last printed line, causing the same "overprint" effect.

@yubiuser
Copy link
Member

Thanks. Maybe you could adjust the code comments a bit, because the part replacing ${OVER} was removed but is used as explanation in the code.

@rdwebdesign
Copy link
Member Author

rdwebdesign commented May 22, 2023

I didn't remove the ${OVER} part. I expanded, but I think I could improve the comments.

The $OVER sequence can be written in different forms:

  • FTL uses \r\x1b[K;
  • PHP uses \r\e[K;
  • Shell is using the character, but github is not able to show it. The same happened with the previous PHP code (the character was not shown on github or some text editors). My second commit fixed this.

I will try to rewrite this comment to allow a better understanding.

@rdwebdesign rdwebdesign requested a review from yubiuser May 23, 2023 01:53
Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. My main issue was that I did not know that \r\e[K and \r�[K are the same thing.

@rdwebdesign
Copy link
Member Author

Yeah,

\e = \x1b = ESC (ASCII code = 27)

@rdwebdesign rdwebdesign merged commit d27f56d into devel May 24, 2023
@rdwebdesign rdwebdesign deleted the tweak/update_gravity_output branch May 24, 2023 02:31
@DL6ER DL6ER mentioned this pull request May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants