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. 🎉

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Jan 8, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [sharkdp/bat](https://github.com/sharkdp/bat) | minor | `v0.24.0` -> `v0.25.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>sharkdp/bat (sharkdp/bat)</summary>

### [`v0.25.0`](https://github.com/sharkdp/bat/blob/HEAD/CHANGELOG.md#v0250)

[Compare Source](sharkdp/bat@v0.24.0...v0.25.0)

#### Features

-   Set terminal title to file names when Paging is not Paging::Never [#&#8203;2807](sharkdp/bat#2807) ([@&#8203;Oliver-Looney](https://github.com/Oliver-Looney))
-   `bat --squeeze-blank`/`bat -s` will now squeeze consecutive empty lines, see [#&#8203;1441](sharkdp/bat#1441) ([@&#8203;eth-p](https://github.com/eth-p)) and [#&#8203;2665](sharkdp/bat#2665) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   `bat --squeeze-limit` to set the maximum number of empty consecutive when using `--squeeze-blank`, see [#&#8203;1441](sharkdp/bat#1441) ([@&#8203;eth-p](https://github.com/eth-p)) and [#&#8203;2665](sharkdp/bat#2665) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   `PrettyPrinter::squeeze_empty_lines` to support line squeezing for bat as a library, see [#&#8203;1441](sharkdp/bat#1441) ([@&#8203;eth-p](https://github.com/eth-p)) and [#&#8203;2665](sharkdp/bat#2665) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   Syntax highlighting for JavaScript files that start with `#!/usr/bin/env bun` [#&#8203;2913](sharkdp/bat#2913) ([@&#8203;sharunkumar](https://github.com/sharunkumar))
-   `bat --strip-ansi={never,always,auto}` to remove ANSI escape sequences from bat's input, see [#&#8203;2999](sharkdp/bat#2999) ([@&#8203;eth-p](https://github.com/eth-p))
-   Add or remove individual style components without replacing all styles [#&#8203;2929](sharkdp/bat#2929) ([@&#8203;eth-p](https://github.com/eth-p))
-   Automatically choose theme based on the terminal's color scheme, see [#&#8203;2896](sharkdp/bat#2896) ([@&#8203;bash](https://github.com/bash))
-   Add option `--binary=as-text` for printing binary content, see issue [#&#8203;2974](sharkdp/bat#2974) and MR [#&#8203;2976](sharkdp/bat#2976) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   Make shell completions available via `--completion <shell>`, see issue [#&#8203;2057](sharkdp/bat#2057) and MR [#&#8203;3126](sharkdp/bat#3126) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   Syntax highlighting for puppet code blocks within Markdown files, see [#&#8203;3152](sharkdp/bat#3152) ([@&#8203;liliwilson](https://github.com/liliwilson))

#### Bugfixes

-   Fix long file name wrapping in header, see [#&#8203;2835](sharkdp/bat#2835) ([@&#8203;FilipRazek](https://github.com/FilipRazek))
-   Fix `NO_COLOR` support, see [#&#8203;2767](sharkdp/bat#2767) ([@&#8203;acuteenvy](https://github.com/acuteenvy))
-   Fix handling of inputs with OSC ANSI escape sequences, see [#&#8203;2541](sharkdp/bat#2541) and [#&#8203;2544](sharkdp/bat#2544) ([@&#8203;eth-p](https://github.com/eth-p))
-   Fix handling of inputs with combined ANSI color and attribute sequences, see [#&#8203;2185](sharkdp/bat#2185) and [#&#8203;2856](sharkdp/bat#2856) ([@&#8203;eth-p](https://github.com/eth-p))
-   Fix panel width when line 10000 wraps, see [#&#8203;2854](sharkdp/bat#2854) ([@&#8203;eth-p](https://github.com/eth-p))
-   Fix compile issue of `time` dependency caused by standard library regression [#&#8203;3045](sharkdp/bat#3045) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Fix override behavior of --plain and --paging, see issue [#&#8203;2731](sharkdp/bat#2731) and MR [#&#8203;3108](sharkdp/bat#3108) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   Fix bugs in `$LESSOPEN` support, see [#&#8203;2805](sharkdp/bat#2805) ([@&#8203;Anomalocaridid](https://github.com/Anomalocaridid))

#### Other

-   Upgrade to Rust 2021 edition [#&#8203;2748](sharkdp/bat#2748) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Refactor and cleanup build script [#&#8203;2756](sharkdp/bat#2756) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Checks changelog has been written to for MRs in CI [#&#8203;2766](sharkdp/bat#2766) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
    -   Use GitHub API to get correct MR submitter [#&#8203;2791](sharkdp/bat#2791) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Minor benchmark script improvements [#&#8203;2768](sharkdp/bat#2768) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Update Arch Linux package URL in README files [#&#8203;2779](sharkdp/bat#2779) ([@&#8203;brunobell](https://github.com/brunobell))
-   Update and improve `zsh` completion, see [#&#8203;2772](sharkdp/bat#2772) ([@&#8203;okapia](https://github.com/okapia))
-   More extensible syntax mapping mechanism [#&#8203;2755](sharkdp/bat#2755) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Use proper Architecture for Debian packages built for musl, see [#&#8203;2811](sharkdp/bat#2811) ([@&#8203;Enselic](https://github.com/Enselic))
-   Pull in fix for unsafe-libyaml security advisory, see [#&#8203;2812](sharkdp/bat#2812) ([@&#8203;dtolnay](https://github.com/dtolnay))
-   Update git-version dependency to use Syn v2, see [#&#8203;2816](sharkdp/bat#2816) ([@&#8203;dtolnay](https://github.com/dtolnay))
-   Update git2 dependency to v0.18.2, see [#&#8203;2852](sharkdp/bat#2852) ([@&#8203;eth-p](https://github.com/eth-p))
-   Improve performance when color output disabled, see [#&#8203;2397](sharkdp/bat#2397) and [#&#8203;2857](sharkdp/bat#2857) ([@&#8203;eth-p](https://github.com/eth-p))
-   Relax syntax mapping rule restrictions to allow brace expansion [#&#8203;2865](sharkdp/bat#2865) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Apply clippy fixes [#&#8203;2864](sharkdp/bat#2864) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Faster startup by offloading glob matcher building to a worker thread [#&#8203;2868](sharkdp/bat#2868) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Display which theme is the default one in basic output (no colors), see [#&#8203;2937](sharkdp/bat#2937) ([@&#8203;sblondon](https://github.com/sblondon))
-   Display which theme is the default one in colored output, see [#&#8203;2838](sharkdp/bat#2838) ([@&#8203;sblondon](https://github.com/sblondon))
-   Add aarch64-apple-darwin ("Apple Silicon") binary tarballs to releases, see [#&#8203;2967](sharkdp/bat#2967) ([@&#8203;someposer](https://github.com/someposer))
-   Update the Lisp syntax, see [#&#8203;2970](sharkdp/bat#2970) ([@&#8203;ccqpein](https://github.com/ccqpein))
-   Use bat's ANSI iterator during tab expansion, see [#&#8203;2998](sharkdp/bat#2998) ([@&#8203;eth-p](https://github.com/eth-p))
-   Support 'statically linked binary' for aarch64 in 'Release' page, see [#&#8203;2992](sharkdp/bat#2992) ([@&#8203;tzq0301](https://github.com/tzq0301))
-   Update options in shell completions and the man page of `bat`, see [#&#8203;2995](sharkdp/bat#2995) ([@&#8203;akinomyoga](https://github.com/akinomyoga))
-   Update nix dev-dependency to v0.29.0, see [#&#8203;3112](sharkdp/bat#3112) ([@&#8203;decathorpe](https://github.com/decathorpe))
-   Bump MSRV to [1.74](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html), see [#&#8203;3154](sharkdp/bat#3154) ([@&#8203;keith-hall](https://github.com/keith-hall))
-   Update clircle dependency to remove winapi transitive dependency, see [#&#8203;3113](sharkdp/bat#3113) ([@&#8203;niklasmohrin](https://github.com/niklasmohrin))

#### Syntaxes

-   `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see [#&#8203;2819](sharkdp/bat#2819) ([@&#8203;victor-gp](https://github.com/victor-gp))
-   Upgrade JQ syntax, see [#&#8203;2820](sharkdp/bat#2820) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
-   Add syntax mapping for quadman quadlets [#&#8203;2866](sharkdp/bat#2866) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Map containers .conf files to TOML syntax [#&#8203;2867](sharkdp/bat#2867) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Associate `.xsh` files with `xonsh` syntax that is Python, see [#&#8203;2840](sharkdp/bat#2840) ([@&#8203;anki-code](https://github.com/anki-code))
-   Associate JSON with Comments `.jsonc` with `json` syntax, see [#&#8203;2795](sharkdp/bat#2795) ([@&#8203;mxaddict](https://github.com/mxaddict))
-   Associate JSON-LD `.jsonld` files with `json` syntax, see [#&#8203;3037](sharkdp/bat#3037) ([@&#8203;vorburger](https://github.com/vorburger))
-   Associate `.textproto` files with `ProtoBuf` syntax, see [#&#8203;3038](sharkdp/bat#3038) ([@&#8203;vorburger](https://github.com/vorburger))
-   Associate GeoJSON `.geojson` files with `json` syntax, see [#&#8203;3084](sharkdp/bat#3084) ([@&#8203;mvaaltola](https://github.com/mvaaltola))
-   Associate `.aws/{config,credentials}`, see [#&#8203;2795](sharkdp/bat#2795) ([@&#8203;mxaddict](https://github.com/mxaddict))
-   Associate Wireguard config `/etc/wireguard/*.conf`, see [#&#8203;2874](sharkdp/bat#2874) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Add support for [CFML](https://www.adobe.com/products/coldfusion-family.html), see [#&#8203;3031](sharkdp/bat#3031) ([@&#8203;brenton-at-pieces](https://github.com/brenton-at-pieces))
-   Map `*.mkd` files to `Markdown` syntax, see issue [#&#8203;3060](sharkdp/bat#3060) and MR [#&#8203;3061](sharkdp/bat#3061) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
-   Add syntax mapping for CITATION.cff, see [#&#8203;3103](sharkdp/bat#3103) ([@&#8203;Ugzuzg](https://github.com/Ugzuzg))
-   Add syntax mapping for kubernetes config files [#&#8203;3049](sharkdp/bat#3049) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Adds support for pipe delimiter for CSV [#&#8203;3115](sharkdp/bat#3115) ([@&#8203;pratik-m](https://github.com/pratik-m))
-   Add syntax mapping for `/etc/pacman.conf` [#&#8203;2961](sharkdp/bat#2961) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
-   Associate `uv.lock` with `TOML` syntax, see [#&#8203;3132](sharkdp/bat#3132) ([@&#8203;fepegar](https://github.com/fepegar))

#### Themes

-   Patched/improved themes for better Manpage syntax highlighting support, see [#&#8203;2994](sharkdp/bat#2994) ([@&#8203;keith-hall](https://github.com/keith-hall)).

#### `bat` as a library

-   Changes to `syntax_mapping::SyntaxMapping` [#&#8203;2755](sharkdp/bat#2755) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
    -   `SyntaxMapping::get_syntax_for` is now correctly public
    -   \[BREAKING] `SyntaxMapping::{empty,builtin}` are removed; use `SyntaxMapping::new` instead
    -   \[BREAKING] `SyntaxMapping::mappings` is replaced by `SyntaxMapping::{builtin,custom,all}_mappings`
-   Make `Controller::run_with_error_handler`'s error handler `FnMut`, see [#&#8203;2831](sharkdp/bat#2831) ([@&#8203;rhysd](https://github.com/rhysd))
-   Improve compile time by 20%, see [#&#8203;2815](sharkdp/bat#2815) ([@&#8203;dtolnay](https://github.com/dtolnay))
-   Add `theme::theme` for choosing an appropriate theme based on the
    terminal's color scheme, see [#&#8203;2896](sharkdp/bat#2896) ([@&#8203;bash](https://github.com/bash))
    -   \[BREAKING] Remove `HighlightingAssets::default_theme`. Use `theme::default_theme` instead.
-   Add `PrettyPrinter::print_with_writer` for custom output destinations, see [#&#8203;3070](sharkdp/bat#3070) ([@&#8203;kojix2](https://github.com/kojix2))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45MS40IiwidXBkYXRlZEluVmVyIjoiMzkuOTEuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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