Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Introduce terminal-width aware animated logging for unmanaged-cluster #2929

Merged
merged 1 commit into from
Jan 25, 2022

Conversation

jpmcb
Copy link
Contributor

@jpmcb jpmcb commented Jan 25, 2022

What this PR does / why we need it

Introduces "terminal-width" aware progress logging.

Using the file descriptor of the attached terminal, we can determine the width of the terminal using Go's standard library. There is a bug (described in depth here) that keeps long lines in small terminals from being replaced.

So, if the progress line is too long, we rebuild a truncated version of it. While this does cut off some information, the next "success" log line is still full length giving the user all the necessary details.

Shout out to @stmcginnis for finding a solution to this in the go std library!!

Details for the Release Notes (PLEASE PROVIDE)

fixed unmanaged-cluster animated logging wrapping during progress logging incorrectly

Which issue(s) this PR fixes

Fixes: #2852

Describe testing done for PR

Normal terminal size still works great:

Screen Shot 2022-01-25 at 9 32 35 AM

Small terminal now won't have the wrapping issue. Lines get replaced as expected:

Screen Shot 2022-01-25 at 9 33 16 AM

note: even though the full path here is getting truncated, the "success" line is still full length and replaces that line successfully giving all the necessary details to the user. Example:

Screen Shot 2022-01-25 at 9 41 11 AM

Special notes for your reviewer

N/a

@jpmcb jpmcb requested a review from a team as a code owner January 25, 2022 16:42
Copy link
Contributor

@joshrosso joshrosso left a comment

Choose a reason for hiding this comment

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

Building off 6a7c336dcb0b78b14a9ae473c24d517bca8cdf22, I see:

image

Inspects the terminal width using the attached terminal's file
descriptor. Then, checks if the generated message will be larger than
the terminal's width.

If so, we rebuild a truncated string that will fit in the terminal width

Signed-off-by: John McBride <[email protected]>
@jpmcb jpmcb force-pushed the unmanaged-term-size branch from 6a7c336 to 13945c2 Compare January 25, 2022 17:00
@jpmcb
Copy link
Contributor Author

jpmcb commented Jan 25, 2022

Hmmmm @joshrosso maybe an old binary? I just pushed again to 13945c2

Here's what I'm seeing on a small terminal:

Screen Shot 2022-01-25 at 10 03 15 AM

Screen Shot 2022-01-25 at 10 03 19 AM

@stmcginnis
Copy link
Contributor

Works right for me on iTerm2. I did need to make sure to rm -fr ~/.config/tanzu to make sure it had to download the BOM again.

image

Will try on my Linux machine to see if it matches what @joshrosso is seeing.

@jpmcb
Copy link
Contributor Author

jpmcb commented Jan 25, 2022

Here's on my linux desktop, PopOS, zsh, using Alacrity terminal:

Normal width

Screenshot from 2022-01-25 10-19-41

Small width

Screenshot from 2022-01-25 10-20-26

@stmcginnis
Copy link
Contributor

Worked as expected for me with default Ubuntu terminal and Sakura terminal.

@stmcginnis stmcginnis merged commit ef42d52 into vmware-tanzu:main Jan 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unmanaged-cluster: Downloading TKR re-prints log message rather than showing progress . characters
4 participants