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

Extend format status output - Allow to change also order of description in NINJA_STATUS #1045

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pali
Copy link

@pali pali commented Oct 28, 2015

Align all edge numbers to same length when formatting output

So when updating status output on terminal, make sure that all numbers will
be always aligned at same length. Even if progress variables change number
of characters.


Allow to change also order of description in NINJA_STATUS

This commit adds new format string %d for printing description. When %d is
not specified in NINJA_STATUS, then description is automatically printed at
the end of line.

This allows to add additional strings after description, for example
changing colors on ANSI terminals via NINJA_STATUS variable.

@pali
Copy link
Author

pali commented Feb 12, 2016

Hi! Can you review my patches?

@tfarina
Copy link
Contributor

tfarina commented Feb 12, 2016

@pali can you collapse all these patches into one? I believe that will make it easier to be reviewed.

@pali
Copy link
Author

pali commented Feb 12, 2016

Hm.. there are more patches as before... and some not mine. Have you did some git push --force? Looks like there are more changes since I created this pull request in Oct 2015.

@pali
Copy link
Author

pali commented Feb 12, 2016

I cherry-picked those two my commits on top of current master.

@pali
Copy link
Author

pali commented Mar 4, 2016

Is there anything wrong with my patch?

@pali
Copy link
Author

pali commented Jul 15, 2016

@tfarina so it is OK now? Ready for merge?

@tfarina
Copy link
Contributor

tfarina commented Jul 16, 2016

@pali, sorry, it is not my call. The decision makers are @nico and/or @evmar.

@pali
Copy link
Author

pali commented Aug 7, 2016

@nico, @evmar. any objects?

@@ -168,6 +168,9 @@ string BuildStatus::FormatProgressStatus(
string out;
char buf[32];
int percent;
char total_edges_str[32];
snprintf(total_edges_str, sizeof(total_edges_str), "%d", total_edges_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: total_edges_ can change over the course of a build, so this isn't guaranteed. The most common thing in fact is for the total edge count to be overestimated and then reduced in the case where a command doesn't modify its outputs.

Copy link
Author

Choose a reason for hiding this comment

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

I think that this is not a problem. It is just used as an estimate for length alignment. It just provide better output for next print...

@evmar
Copy link
Collaborator

evmar commented Aug 8, 2016

Sorry for not looking at this earlier. The single pull request with a vague description makes it easy to overlook! I think the %d change is pretty reasonable but I think the alignment one may not work as you expect.

@pali
Copy link
Author

pali commented Aug 8, 2016

Alignment in all snprintf calls make sure that all "%d" formats will be aligned to same length. As during one FormatProgressStatus call is total_edges the highest number which can "%_d" format.

Also that number total_edges_ is not directly used. But its logarithm, so if number of edges do not start exponentially increasing or decreasing then output is pretty constant and good aligned also when doing progress.

@pali
Copy link
Author

pali commented Aug 8, 2016

@evmar Let me know if you are going accept this patch in some way and if something is needed to rework...

@pali pali changed the title Extend format status output Extend format status output - Allow to change also order of description in NINJA_STATUS Nov 20, 2016
@pali
Copy link
Author

pali commented Nov 20, 2016

@evmar I updated github pull request description from commit messages (sorry for vague description on github, moreover it is github fault, that it hides git commits itself!)

@evmar can you look at above comments ↑↑↑?

@pali
Copy link
Author

pali commented Dec 26, 2016

@evmar: PING

@pali
Copy link
Author

pali commented Apr 13, 2017

@evmar gentle PING

@jhasse
Copy link
Collaborator

jhasse commented Nov 14, 2018

This looks quite useful, especially if we add support for colors in NINJA_STATUS. Would you be willing to rebase this on current master?

@pali
Copy link
Author

pali commented Nov 14, 2018

I already did it more times. But nobody replied.

@pali
Copy link
Author

pali commented Nov 15, 2018

So is still somebody interesting in this patch after rebasing? And can review it?

@jhasse
Copy link
Collaborator

jhasse commented Nov 16, 2018

Yes, I would do it.

So when updating status output on terminal, make sure that all numbers will
be always aligned at same length. Even if progress variables change number
of characters.
@pali
Copy link
Author

pali commented Nov 16, 2018

@jhasse Done!

@jhasse
Copy link
Collaborator

jhasse commented Nov 16, 2018

Thanks :) Please have a look at the CI failures.

This commit adds new format string %d for printing description. When %d is
not specified in NINJA_STATUS, then description is automatically printed at
the end of line.

This allows to add additional strings after description, for example
changing colors on ANSI terminals via NINJA_STATUS variable.
@pali
Copy link
Author

pali commented Nov 16, 2018

Done!

@jhasse
Copy link
Collaborator

jhasse commented Nov 16, 2018

Thanks. This will come in handy when #1494 is merged.

Code looks good, though I don't like the need for %*d. Maybe use %D for the description instead?

@jhasse jhasse added this to the 1.10.0 milestone Nov 16, 2018
@pali
Copy link
Author

pali commented Nov 16, 2018

I don't like the need for %*d

printf's %*d is one of the main points of this pull request. It aligns all numbers to the same length when formatting.

Maybe use %D for the description instead?

I used lowercase d for NINJA_STATUS format as all other NINJA_STATUS format characters are lowercase.

@jhasse
Copy link
Collaborator

jhasse commented Nov 16, 2018

Ah, I thought that was because it would clash with %d from the description otherwise. Sorry, I didn't read it more clearly.

Can you split the PR in "Align all edge numbers to same length when formatting output" (not sure if we want this by default, needs discussion) and "Allow to change also order of description in NINJA_STATUS"?

@pali
Copy link
Author

pali commented Nov 16, 2018

Reason for aligning is that output format does not change so drastically when printing it in-place on terminal. Before this change, when updating 1/100 to 10/100 and then to 100/100 it changes 3 times width of text. So if you have custom NINJA_STATUS, text in that status move on that line... After this you would see 1/100, 10/100 and 100/100, always this text consist of 7 characters and with custom NINJA_STATUS text, it would not move and stay on same position.

Second commit allows to put description at any position and to have it on stable position, that alignment from first commit is really needed.

@jhasse
Copy link
Collaborator

jhasse commented Nov 16, 2018

I understand the reasoning. Users may rely on the old behavior though and it changes Ninja's default output. A way to change the behavior, maybe %S instead of %s, might still be nice to have.

I used lowercase d for NINJA_STATUS format as all other NINJA_STATUS format characters are lowercase.

Yeah, keep that. I was completely wrong there, nvm ;)

@pali
Copy link
Author

pali commented Dec 17, 2018

@jhasse anything else is needed to process this pull request? or it is just waiting for #1494?

@jhasse
Copy link
Collaborator

jhasse commented Dec 17, 2018

No, this is independent of #1494.

I'm still not sure about the "Align all edge numbers to same length when formatting output" part. What do you think about

A way to change the behavior, maybe %S instead of %s, might still be nice to have.

?

(btw: As for all frontend stuff, I'm a fan of #1210 instead of extending Ninja itself)

@pali
Copy link
Author

pali commented Dec 17, 2018

And what with %u, %r and %f then?

@evmar
Copy link
Collaborator

evmar commented Dec 18, 2018

BTW, one of my design regrets in Ninja is that we have this mechanism for generating command line strings internally (via "$foo ${other}") and then we didn't reuse it for status. Not sure if it's worth thinking about here though.

@jhasse
Copy link
Collaborator

jhasse commented Aug 2, 2019

And what with %u, %r and %f then?

Good point. Hm ... maybe it would indeed be better to go with #1210 / #1600 for such changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants