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

Printers prefixes with same width #270

Closed
kinoute opened this issue Oct 9, 2021 · 8 comments
Closed

Printers prefixes with same width #270

kinoute opened this issue Oct 9, 2021 · 8 comments
Labels
proposal Proposal to add a new feature to pterm

Comments

@kinoute
Copy link
Contributor

kinoute commented Oct 9, 2021

Hello there,

I was wondering if it might possible to make all the Printers prefixes with the same width? Right now it looks like this:

Capture d’écran 2021-10-09 à 18 59 58

If the width was the same for every kind of prefix, the alignment would look much nicer.

Thanks!

@kinoute kinoute added the proposal Proposal to add a new feature to pterm label Oct 9, 2021
@kinoute
Copy link
Contributor Author

kinoute commented Oct 9, 2021

BTW, it seems SpinnerPrinters don't have this problem:

Capture d’écran 2021-10-09 à 19 07 10

@MarvinJWendt
Copy link
Member

MarvinJWendt commented Oct 10, 2021

Hi @kinoute, the SpinnerPrinter doesn't have this issue as it doesn't have the Info printer, every other printer has the same width 😉 I'd actually also like them to have the same width, but we cannot center the Info printer (due to its text length), and we found that it looked kinda weird to have the same width on it, as the text Info would have more padding to one side than the other. Also, the user can create his own PrefixPrinters which might be longer than any other printer, so we cannot set one specific width. If a user creates a PrefixPrinter with the prefix "WEB-SERVICE" for example, that one would be longer than the other ones.

@ccremer
Copy link

ccremer commented Oct 10, 2021

I just modified the Info Prefixprinter's prefix, e.g.
pterm.Info.WithPrefix(pterm.Prefix{Text: " INFO ", Style: pterm.Info.Prefix.Style})

At least the background colors and the messages would then be aligned.

image

@kinoute
Copy link
Contributor Author

kinoute commented Oct 11, 2021

@MarvinJWendt Thanks for the great explanation, I now understand the problem.

@ccremer Great tip, thanks! Do you think there is a way to force this custom Prefix every time and everywhere we call pterm.Info (instead of using WithPrefix every time) ?

@ccremer
Copy link

ccremer commented Oct 11, 2021

If I'm not mistaken, you can simply overwrite the default pterm.Info with the new printer, e.g.
pterm.Info = *pterm.Info.WithPrefix(pterm.Prefix{Text: " INFO ", Style: pterm.Info.Prefix.Style})

@kinoute
Copy link
Contributor Author

kinoute commented Oct 11, 2021

@ccremer This works flawlessly, thank you very much. I use "INFOS" instead to correctly aligned the text with the other labels.

I didn't know we could override that easy a feature of a library over all an app. I thought I would have to add this line on every package, apparently I don't have to, one line in main is enough. Guess I have still a lot of things to learn in Go!

@ccremer
Copy link

ccremer commented Oct 11, 2021

Glad to help. pterm.Info is an exposed global variable and not a constant, so you can change it anytime.

@MarvinJWendt
Copy link
Member

Closing due to inactivity
If this issue gets relevant again, feel free to drop a comment (mention me @MarvinJWendt) and I will reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal to add a new feature to pterm
Projects
None yet
Development

No branches or pull requests

3 participants