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

Dynamically setting width format no longer working #3605

Closed
matias-eduardo opened this issue May 19, 2024 · 1 comment
Closed

Dynamically setting width format no longer working #3605

matias-eduardo opened this issue May 19, 2024 · 1 comment

Comments

@matias-eduardo
Copy link
Contributor

After #3566, dynamically setting width in the following way stopped working:

fmt.printf(
    "[% -[1]*v][% -[3]*v][% -[5]*v][% -[7]*v][% -[9]*v]\n",
    6, "First",
    30, "Second",
    10, "Third",
    20, "Fourth",
    20, "Fifth",
)

// Expected output:
// [First ][Second                        ][Third     ][Fourth              ][Fifth               ]

// Current output:
// [%!*(string=First)v][%!*(string=Second)v][%!*(string=Third)v][%!*(string=Fourth)v][%!*(string=Fifth)v]
@Feoramund
Copy link
Contributor

Despite it being given in the old examples, that style of format was never supposed to work. The mechanisms in fmt have since been updated to reflect the documentation in accordance with how C's printf works with regards to argument-specified width.

The correct way to specify width by argument is %*[1]v. For example: fmt.printf("%*[1]s", "Hellope", 16)

@Kelimion Kelimion closed this as completed Jun 1, 2024
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

No branches or pull requests

3 participants