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

[2.3.0~beta1 regression] Long columns are misaligned #6243

Closed
kit-ty-kate opened this issue Oct 15, 2024 · 7 comments · Fixed by #6244
Closed

[2.3.0~beta1 regression] Long columns are misaligned #6243

kit-ty-kate opened this issue Oct 15, 2024 · 7 comments · Fixed by #6244
Labels
Milestone

Comments

@kit-ty-kate
Copy link
Member

kit-ty-kate commented Oct 15, 2024

$ ./opam-2.3.0-beta1-arm64-linux upgrade
The following actions will be performed:
=== recompile 9 packages
  ↻ dns-client-miou-unix     9.0.1
          [uses happy-eyeballs, happy-eyeballs-miou-unix]
  ↻ h1                       1.0.0                       [uses angstrom]
  ↻ h2                       0.13.0                      [uses angstrom]
  ↻ hpack                    0.13.0                      [uses angstrom]
  ↻ httpcats                 0.0.1
          [uses happy-eyeballs-miou-unix]
  ↻ kit-ty-kate-platform     1                           [uses ocp-index]
  ↻ lambda-term              3.3.2                       [uses zed]
  ↻ uri                      4.4.0                       [uses angstrom]
  ↻ zed                      3.2.3                       [uses uucp, uuseg]
=== upgrade 7 packages
  ↗ angstrom                 0.16.0 to 0.16.1
  ↗ caqti                    1.9.0 to 2.1.2
  ↗ happy-eyeballs           1.2.0 to 1.2.2
  ↗ happy-eyeballs-miou-unix 1.2.1 to 1.2.2
  ↗ ocp-index                1.3.6 to 1.3.6.1~alpha-repo
  ↗ uucp                     15.1.0 to 16.0.0
  ↗ uuseg                    15.1.0 to 16.0.0
=== install 3 packages
  ∗ dune-private-libs        3.16.0
          [required by dune-site]
  ∗ dune-site                3.16.0                      [required by caqti]
  ∗ lwt-dllist               1.0.1                       [required by caqti]

Proceed with ↻ 9 recompilations, ↗ 7 upgrades and ∗ 3 installations? [y/n] n
$ ./opam-2.3.0-alpha1-arm64-linux upgrade
The following actions will be performed:
=== recompile 9 packages
  ↻ dns-client-miou-unix     9.0.1                       [uses happy-eyeballs, happy-eyeballs-miou-unix]
  ↻ h1                       1.0.0                       [uses angstrom]
  ↻ h2                       0.13.0                      [uses angstrom]
  ↻ hpack                    0.13.0                      [uses angstrom]
  ↻ httpcats                 0.0.1                       [uses happy-eyeballs-miou-unix]
  ↻ kit-ty-kate-platform     1                           [uses ocp-index]
  ↻ lambda-term              3.3.2                       [uses zed]
  ↻ uri                      4.4.0                       [uses angstrom]
  ↻ zed                      3.2.3                       [uses uucp, uuseg]
=== upgrade 7 packages
  ↗ angstrom                 0.16.0 to 0.16.1
  ↗ caqti                    1.9.0 to 2.1.2
  ↗ happy-eyeballs           1.2.0 to 1.2.2
  ↗ happy-eyeballs-miou-unix 1.2.1 to 1.2.2
  ↗ ocp-index                1.3.6 to 1.3.6.1~alpha-repo
  ↗ uucp                     15.1.0 to 16.0.0
  ↗ uuseg                    15.1.0 to 16.0.0
=== install 3 packages
  ∗ dune-private-libs        3.16.0                      [required by dune-site]
  ∗ dune-site                3.16.0                      [required by caqti]
  ∗ lwt-dllist               1.0.1                       [required by caqti]

Proceed with ↻ 9 recompilations, ↗ 7 upgrades and ∗ 3 installations? [y/n] n

Funnily enough master (built with glibc) exhibits the same behaviour as 2.3.0~alpha1 so my guess is that this somehow comes from #6237, most likely the upgrade to Alpine 3.20. Maybe a bug in musl?

EDIT: Nevermind i built the wrong branch, i'm able to reproduce with master with glibc also so it's not a musl issue.

@kit-ty-kate kit-ty-kate added this to the 2.3.0~beta2 milestone Oct 15, 2024
@kit-ty-kate
Copy link
Member Author

I was able to bisect quickly and found the origin in #6230. Apparently tput cols says something different depending on whether it's called via execve or system or something like that. I'll find a fix tomorrow

@kit-ty-kate
Copy link
Member Author

Something feels fishy in the standard library:

# let ic, _ = Unix.open_process_args "/usr/bin/tput" [|"/usr/bin/tput"; "cols"|];;
val ic : in_channel = <abstr>
# input_line ic;;
- : string = "107"
# let ic, _, _ = Unix.open_process_args_full "/usr/bin/tput" [|"/usr/bin/tput"; "cols"|] (Unix.environment ());;
val ic : in_channel = <abstr>
# input_line ic;;
- : string = "80"

@kit-ty-kate
Copy link
Member Author

ok, i got to the bottom of this. It looks like you can't get the proper result from tput cols while redirecting all 3 stdout, stdin and stderr. At least one has to be left unredirected.

$ tput cols
215
$ tput cols > /tmp/stdout << EOF
EOF
$ cat /tmp/stdout
215
$ tput cols > /tmp/stdout 2> /tmp/stderr
$ cat /tmp/stdout
215
$ tput cols > /tmp/stdout 2> /tmp/stderr << EOF
EOF
$ cat /tmp/stdout
80

I'll try to think at a fix tomorrow

@dbuenzli
Copy link
Contributor

I guess the idea is that you need one that isatty no ?

@dbuenzli
Copy link
Contributor

Btw. I was curious on how I solved that problem in down as I knew I was not using tput. It's quite ugly :-) (get cursor position, move a large amount to the right this gets clamped if larger than the window size, get cursor position, and move back to initial position).

@kit-ty-kate
Copy link
Member Author

My first thought on how to fix this so far is to bind ioctl(STDOUT_FILENO, TIOCGWINSZ, &win), it's easy to add in our codebase and seems reasonably portable (despite not being POSIX defined)

@dbuenzli
Copy link
Contributor

Looks cleaner.

I'm not sure why I didn't do that in down but perhaps the thinking was let's just assume we have ANSI/VT100 terminal. If that turned out to make it work out of the box with @nojb's recent Windows Console integration, I'm less embarrassed :–)

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 a pull request may close this issue.

2 participants