Sitelet https://web.archive.org/web/20201228193501im_/https://github.com/JuliaLang/julia/issues/38256
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

Should lpad/rpad be defined in terms of textwidth instead of code units or have the option to do so? #38256

Open
KristofferC opened this issue Nov 1, 2020 · 6 comments

Comments

@KristofferC
Copy link
Contributor

@KristofferC KristofferC commented Nov 1, 2020

One of the main use cases of lpad and rpad is, at least for me personally, to align things in the terminal. However, lpad and rpad are defined (and documented) to work in terms of code units (i.e. they call length on the input string) which means that when length and textwidth disagree, you get unaligned output:

julia> s1 = "⟨k|H₁|k̃⟩"
"⟨k|H₁|k̃⟩"
julia> s2 = "⟨k|H₁|k⟩"
"⟨k|H₁|k⟩"
julia> textwidth(s1), textwidth(s2)
(8, 8)
julia> rpad(s1, 12) |> textwidth
11
julia> rpad(s2, 12) |> textwidth
12

This can cause bugs like KristofferC/TimerOutputs.jl#94.

Two points of discussions:

  • Should the default be changed to use textwidth instead of length? Perhaps too much of a breaking change.
  • Should there be an option to use textwidth, e.g. with a kwarg?
@rfourquet
Copy link
Contributor

@rfourquet rfourquet commented Nov 1, 2020

I have seen functions like mylpad in a package to workaround this behavior... So yeah, at least providing an option to use textwidth would be great.

Does someone know the usecase for using length instead of textwidth ?

@vtjnash
Copy link
Member

@vtjnash vtjnash commented Nov 12, 2020

Triage said textwidth sounds best here

@vtjnash vtjnash removed the triage label Nov 12, 2020
@JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented Nov 12, 2020

From triage: we can't think of a use case where you would want length.

@rohanxyzg
Copy link

@rohanxyzg rohanxyzg commented Nov 25, 2020

Hey,
I would like to work on this issue.
Thanks!

@StefanKarpinski
Copy link
Member

@StefanKarpinski StefanKarpinski commented Nov 25, 2020

Go for it!

@KristofferC
Copy link
Contributor Author

@KristofferC KristofferC commented Nov 25, 2020

@rohanxyzg, Just a heads up since you post this in a few "good first issue" posts, there is generally no need to "claim" an issue, you can just start working on it and submit a PR when it is finished :).

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

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.