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

Erratic output when OSC8 sequences are present #2541

Closed
rockorager opened this issue Apr 13, 2023 · 7 comments · Fixed by #2544
Closed

Erratic output when OSC8 sequences are present #2541

rockorager opened this issue Apr 13, 2023 · 7 comments · Fixed by #2544
Labels
bug Something isn't working

Comments

@rockorager
Copy link

Hello -

When bat displays something that already includes an OSC8 sequence, it has erratic output, dependent on the terminal-width. Seemingly, OSC8 ids and urls are included in line-wrapping which leads to strange output depending on where the line is cut.

What steps will reproduce the bug?

Works as expected:

echo '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n' | bat --terminal-width=64

Includes escape characters in output:

echo '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n' | bat --terminal-width=48

No escape characters, but incorrect wrapping:

echo '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n' | bat --terminal-width=40

What happens?

If you keep changing the terminal width, strange things keep happening.

What did you expect to happen instead?

The output should be the same in all above scenarios, as long as terminal-width is greater than the length of the printable section of an OSC8 sequence ("This is a link") in this case.

How did you install bat?

sudo pacman -S bat

bat version and environment

Software version

bat 0.23.0 (871abd2)

Operating system

Linux 6.2.10-arch1-1

Command-line

bat --terminal-width=24 --diagnostic 

Environment variables

SHELL=/usr/bin/zsh
PAGER=<not set>
LESS=<not set>
LANG=en_US.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=<not set>

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

Could not read contents of '/home/tim/.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

Could not read contents of '/home/tim/.cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

'/home/tim/.cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version 
less 608 (PCRE2 regular expressions)
Copyright (C) 1984-2022  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
@rockorager rockorager added the bug Something isn't working label Apr 13, 2023
@keith-hall
Copy link
Collaborator

related: #2158

eth-p added a commit to eth-p/bat that referenced this issue Apr 17, 2023
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
eth-p added a commit to eth-p/bat that referenced this issue Apr 17, 2023
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
eth-p added a commit to eth-p/bat that referenced this issue Apr 17, 2023
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
eth-p added a commit to eth-p/bat that referenced this issue Apr 17, 2023
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
@eth-p
Copy link
Collaborator

eth-p commented Apr 18, 2023

Whoops. Sorry for the spam! Rebasing and force pushing will do that, I guess. 😅

Anyways... this is more along the lines of what you expected, right? New behaviour from my branch is on the left, old behaviour is on the right.

image

Unfortunately this comes with the drawback where the link is treated as two separate hyperlinks, rather than as a single one. I don't think we're able to fix that, though, since it's the job of the terminal emulator to render the link decorations.

@rockorager
Copy link
Author

Wow I was typing in my phone and accidentally closed!

@rockorager rockorager reopened this Apr 18, 2023
@rockorager
Copy link
Author

Anyways... this is more along the lines of what you expected, right? New behaviour from my branch is on the left, old behaviour is on the right.

Yep that looks right!

Unfortunately this comes with the drawback where the link is treated as two separate hyperlinks, rather than as a single one. I don't think we're able to fix that, though, since it's the job of the terminal emulator to render the link decorations.

You can put an id as part of the osc8 string to link two separate lines as the same link.

echo '\e]8;bat-1;http://example.com\e\\This is a link\e]8;;\e\\\n'

Thanks!

@eth-p
Copy link
Collaborator

eth-p commented Apr 18, 2023

You can put an id as part of the osc8 string to link two separate lines as the same link.

Neat! Mind if I fix that in a future PR? This one [edit: meaning #2544] is getting pretty long as-is, and I have some finals to study for :)

@rockorager
Copy link
Author

Neat! Mind if I fix that in a future PR? This one is getting pretty long as-is, and I have some finals to study for :)

Don't mind at all!

eth-p added a commit to eth-p/bat that referenced this issue Feb 8, 2024
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
eth-p added a commit to eth-p/bat that referenced this issue Feb 10, 2024
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
eth-p added a commit to eth-p/bat that referenced this issue Feb 10, 2024
More specifically, the test ensures that OSC sequences don't end up
wrapping the line.
@eth-p
Copy link
Collaborator

eth-p commented Feb 10, 2024

With #2544 merged, this should be fixed in the next release. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants