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

Add dynamic MAX_PROGRESS_WIDTH global variable to handle long lines #435

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

thmahe
Copy link
Contributor

@thmahe thmahe commented Sep 16, 2024

Description

Add dynamic MAX_PROGRESS_WIDTH global variable that will store longest line printed during progress phase.
Use as a replacement of get_console_width while sizing string during progress.

Initialized with 0, MAX_PROGRESS_WIDTH is updated on each progress step with actual line length as follow:

  • MAX_PROGRESS_WIDTH = MAX(MAX_PROGRESS_WIDTH, next_content_length)

Which warranty that next line even if shorter will contains required spaces in order to flush previous lines (while using terminal).
Outside of a terminal context, lines will have a maximum length based on actual output and not on nonexistent terminal size.

Fixes #434

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested by flashing firmware i.MX board with manual checking of standard output.

Example output

uuu (Universal Update Utility) for nxp imx chips -- libuuu_1.5.182-8-gc3a23e4EOL

Wait for Known USB Device Appear...EOL
�[?25lEOL


3:3-18145A0A 1/ 0 [                                      ] EOL
�[1F�[1F�[1F�[1F


3:3-18145A0A 1/ 5 [                                      ] FB: ucmd setenv fastboot_dev mmcEOL
�[1F�[1F�[1F�[1F
Success 0    Failure 0         EOL
                                                                 
                                                                  
3:3-18145A0A 4/ 5 [                                      ] FB: flash bootloader ./imx-boot-imx8mm-lpddr4-evk-sd.bin-flash_evkEOL
�[1F�[1F�[1F�[1FEOL
Success 0    Failure 0                                           EOL
                                                                  
                                                                  
3:3-18145A0A 5/ 5 [                                      ] FB: Done                                                          EOL

Test Configuration:

  • Operating System: Linux (Ubuntu 22.04)
  • Toolchain: GCC 11.4.0 with glibc 2.38

@nxpfrankli
Copy link
Contributor

It broken normal user case. Print may mass when use correct console. Generally, if uuu work as subprocess, use -v option to print raw log to easy parser by other program.

@thmahe
Copy link
Contributor Author

thmahe commented Sep 16, 2024

Hi @nxpfrankli, thanks for your fast reply. Proposed patch does not break anything when using uuu on a regular console (where tests where conducted)
Spaces count required to hide previous progress result is stored within a variable instead of printing spaces based on terminal width.

uuu/uuu.cpp Outdated Show resolved Hide resolved
@thmahe thmahe force-pushed the improvement/long-line-logging branch from c3a23e4 to 1e6de1f Compare September 17, 2024 12:22
uuu/uuu.cpp Outdated Show resolved Hide resolved
uuu/uuu.cpp Outdated Show resolved Hide resolved
uuu/uuu.cpp Outdated Show resolved Hide resolved
@thmahe thmahe force-pushed the improvement/long-line-logging branch 2 times, most recently from 75515bc to 377eb79 Compare October 3, 2024 09:39
@nxpfrankli
Copy link
Contributor

Please add signed-off at your each commit

Fix long line issue when using `uuu` outside of a terminal. eg: python.subprocess.
Signed-off-by: Thomas Mahé <[email protected]>
@thmahe thmahe force-pushed the improvement/long-line-logging branch from 377eb79 to ee36e09 Compare October 18, 2024 13:52
@thmahe
Copy link
Contributor Author

thmahe commented Oct 18, 2024

Please add signed-off at your each commit

Done

@nxpfrankli nxpfrankli merged commit 6c2141e into nxp-imx:master Oct 18, 2024
@thmahe thmahe deleted the improvement/long-line-logging branch October 21, 2024 08:11
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.

Logging based on terminal size
2 participants