sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.06k stars 1.24k forks source link

Scrolling in iterm2 does not work #2367

Open iamtodor opened 1 year ago

iamtodor commented 1 year ago

What steps will reproduce the bug?

  1. if I run bat .zshrc.backup in the macos terminal I'm able to scroll all the content of the file. Initially, on my screen, there are 30 lines and I can scroll it up to the last 102 lines.
  2. if I run bat .zshrc.backup in iterm2 I'm not able to scroll all the content of the file until I press enter to load more rows and then I will be able to scroll up and down from 1 to 102 line.

What happens? The scrolling does not work

What did you expect to happen instead?

The scrolling does work

How did you install bat?

homebrew

bat version and environment

bat .zshrc.backup --diagnostic
#### Software version

bat 0.22.1

#### Operating system

macOS 12.6 (Darwin 21.6.0)

#### Command-line

```bash
bat .zshrc.backup --diagnostic

Environment variables

SHELL=/bin/zsh
PAGER=less
LESS=-R
LANG=<not set>
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

# Uncomment the following line if you are using less version >= 551 and want to
# enable mouse scrolling support in `bat` when running inside tmux. This might
# disable text selection, unless you press shift.
# --pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse"

# Syntax mappings: map a certain filename pattern to a language.
#   Example 1: use the C++ syntax for Arduino .ino files
#   Example 2: Use ".gitignore"-style highlighting for ".ignore" files
--map-syntax "zshrc:Bourne Again Shell (bash)"
--map-syntax "zshenv:Bourne Again Shell (bash)"
--map-syntax "Brewfile:Bourne Again Shell (bash)"

Custom assets metadata

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

Custom assets

'/Users/iamtodor/.cache/bat' not found

Compile time information

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

might be related to https://github.com/sharkdp/bat/issues/188

iamtodor commented 1 year ago

Also, found more or less related issues https://github.com/sharkdp/bat/issues/508 https://github.com/sharkdp/bat/issues/509 https://github.com/sharkdp/bat/issues/526 https://github.com/sharkdp/bat/issues/556

sharkdp commented 1 year ago

So.. did you find a solution in one of the other issues?

iamtodor commented 1 year ago

@sharkdp nope, I did not. Did you find it?

iamtodor commented 1 year ago

@sharkdp could you please help me with where to look? I tried this solution https://github.com/sharkdp/bat/issues/508#issuecomment-464838961 but it does not work for me.

Am I missing something?

iamtodor commented 1 year ago

@sharkdp could you please take a look?

iamtodor commented 1 year ago

@sharkdp could you please take a look here?

unphased commented 1 year ago

bat --pager="less -R" works for me but I would love to have bat just figure out how to not override less flags for us. Running bat 0.12.1 here. For now just gonna alias bat to bat --pager="less -R".

sharkdp commented 1 year ago

Look, guys. I don't have a Mac. Someone else will have to work on this / figure this out.

keith-hall commented 1 year ago

bat --pager="less -R" works for me but I would love to have bat just figure out how to not override less flags for us. Running bat 0.12.1 here. For now just gonna alias bat to bat --pager="less -R".

Bat 0.12.1 was released in 2019... Did you consider that it may already work better in a recent version @unphased ?

unphased commented 1 year ago

@keith-hall That's a solid point. On this Ubuntu 20.04 system it's provided via apt and there is still no newer version available from there. On my mac it's provided from homebrew and on version 0.18, and this is not an issue there.

This has prompted me to update my env setup scripts to go back to preparing bat via cargo instead of apt again. Plus, getting it from apt installs it as batcat and I had to make another symlink for that too.

litoj commented 1 year ago

I know this may sound obvious, but have you tried uncommenting the suggested line --pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse"? It worked for me, though I am not on a Mac.

lesha-co commented 8 months ago

Since the issue is still open I would like to share my experience. I had this issue on freshly installed iterm2, then I ran bat --pager="less -R" and then happened two things: first, it worked, second, iterm asked whether I would like mouse scrolling to interact with these programs. After clicking yes bat works as intended even without --pager switch

so either bat remembers --pager(?) or it's just a question of enabling some setting in iterm2

iamtodor commented 8 months ago

for me running bat --pager="less -R" gives nothing :(

eth-p commented 7 months ago

@iamtodor, can you try enabling mouse reporting and mouse wheel events in iTerm? You'll also need to add the --mouse option to less (either through bat --pager="less -R --mouse" or by setting the LESS environment variable to LESS="--mouse") to have it ask the terminal to report mouse/scroll wheel inputs.

Also, are you using tmux, screen, or some other multiplexer? Those have their own mouse event support that may prevent the events from being properly passed along to less.

iamtodor commented 7 months ago

@eth-p surprisingly this one bat --pager="less -R --mouse" works for me!

Nope, I do not use any multiplexer, just vanilla iterm2