-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
bat leaves text behind in pager mode #749
Comments
This would be because of the way that If you prefer it always pages, you can add |
Thanks for your answer. Shouldn't this be the default behavior? |
Oh, that sounds like a different issue than I first thought. If the pager isn't printing and exiting immediately, then we're talking about the With that flag, less is told to not swap to the alternate screen. Without the alternate screen, scrolling the pager contents will cause redraw artifacts to appear in the scrollback. If that's the case, you can set The reason |
@dickshaydle Could you please post the output of set -x
bat --version
bat --config-file
bat --cache-dir
less --version
bat "$(bat --config-file)"
ls "$(bat --cache-dir)"
set +x
echo "BAT_PAGER = '$BAT_PAGER'"
echo "BAT_CONFIG_PATH = '$BAT_CONFIG_PATH'"
echo "BAT_STYLE = '$BAT_STYLE'"
echo "BAT_THEME = '$BAT_THEME'"
echo "BAT_TABS = '$BAT_TABS'"
echo "PAGER = '$PAGER'"
echo "LESS = '$LESS'" And also give some information about your |
>>> set -x # i removed all lines with "_zsh_autosuggest" in it because there was a lot
+precmd:1> [ -z 24708 ']'
+precmd:2> print -Pn '\e]0;24708 - myusername@: /home/myusername\a'
+omz_termsupport_precmd:1> emulate -L zsh
+omz_termsupport_precmd:3> [[ true == true ]]
+omz_termsupport_precmd:4> return
+_zsh_highlight_main__precmd_hook:1> _zsh_highlight_main__command_type_cache=( )
+zsh:3> prompt_context
+prompt_context:1> [[ myusername != ]]
+prompt_context:2> echo -n $'%{\C-[[00m%}%{\C-[[31m%}myusername@%m%{\C-[[00m%}%{\C-[[01;33m%}%~%<<%{\C-[[00m%}'
+zsh:3> git_prompt_info
+git_prompt_info:1> local ref
+git_prompt_info:2> [[+git_prompt_info:2> git config --get oh-my-zsh.hide-status
+git_prompt_info:2> [[ '' != 1 ]]
+git_prompt_info:3> ref=+git_prompt_info:3> git symbolic-ref HEAD
+git_prompt_info:3> ref=''
+git_prompt_info:4> ref=+git_prompt_info:4> git rev-parse --short HEAD
+git_prompt_info:4> ref=''
+git_prompt_info:4> return 0
+zsh:3> svn_prompt_info
+svn_prompt_info:1> local _DISPLAY
+svn_prompt_info:2> in_svn
+in_svn:1> svn info
>>> bat --version
bat 0.12.1
>>> bat --config-file
/home/myusername/.config/bat/config
>>> bat --cache-dir
/home/myusername/.cache/bat
>>> less --version
less 487 (GNU regular expressions)
Copyright (C) 1984-2016 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.
Homepage: http://www.greenwoodsoftware.com/less
>>> bat "$(bat --config-file)"
[bat error]: '/home/myusername/.config/bat/config': No such file or directory (os error 2)
>>> ls "$(bat --cache-dir)"
"/home/myusername/.cache/bat": No such file or directory (os error 2)
>>> echo "BAT_PAGER = '$BAT_PAGER'"
echo "BAT_CONFIG_PATH = '$BAT_CONFIG_PATH'"
echo "BAT_STYLE = '$BAT_STYLE'"
echo "BAT_THEME = '$BAT_THEME'"
echo "BAT_TABS = '$BAT_TABS'"
echo "PAGER = '$PAGER'"
echo "LESS = '$LESS'"
BAT_PAGER = ''
BAT_CONFIG_PATH = ''
BAT_STYLE = ''
BAT_THEME = ''
BAT_TABS = ''
PAGER = 'less'
LESS = '-R -M'
my OS is Linux Mint 19 / Ubuntu 18.4:
>>> uname -a
Linux taschenrechner 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
>>> lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 19 Tara
Release: 19
Codename: tara I've set |
Thank you very much for the feedback. I can not reproduce this. Which terminal emulator are you using? Are you withing a How does |
i'm using gnome-terminal 3.28.1, but same behavior in XTerm(330) and xfce4-terminal 0.8.7.4 (Xfce 4.12). I can reproduce it with less alone now. With a little help of strace ( ...
[pid 12880] execve("/usr/bin/less", ["less", "--RAW-CONTROL-CHARS", "--no-init", "--quit-if-one-
screen"], 0x16f14a0 /* 28 vars */ <unfinished ...>
...
the minimal command line to reproduce for me is from
clearing to screen seems to be pretty reasonable in this case, i guess. I've tested the So what about not using the |
I guess we would have to parse the output of I'm afraid that lots of Linux distributions still ship older versions of |
As for now, I recommend you simply add
to your configuration file, as suggested in the README. |
Let's try to implement this by parsing the output of Then
|
@sharkdp I'm all for adding this feature. It would greatly improve the default experience, especially since the scroll wheel only works when using an alternate screen (i.e. without If we implement this, I would recommend we either cache the results in a tempfile for 24 hours, or only try to parse Adding more |
Good point about the performance impact. I wrote a first implementation of this to run a simple benchmark: use std::process::Command;
fn parse_less_version(output: &[u8]) -> Option<usize> {
if output.starts_with(b"less ") {
let version = std::str::from_utf8(&output[5..]).ok()?;
let end = version.find(' ')?;
version[..end].parse::<usize>().ok()
} else {
None
}
}
fn retrieve_less_version() -> Option<usize> {
let cmd = Command::new("less").arg("--version").output().ok()?;
parse_less_version(&cmd.stdout)
}
fn main() {
for _ in 0..1000 {
println!("{:?}", retrieve_less_version());
}
} The whole program takes 1.755 s ± 0.057 s, so each iteration is below 2 ms. I would really try to avoid any kind of caching mechanism, as this will likely lead to other problems.
Yes, absolutely. We would basically just call
If you are calling it for every input file, you would probably turn off the pager anyway? |
With this change, we do not pass the `--no-init` option in newer versions of less (530 or higher). This fixes #749
I opened a PR that attempts to fix this. |
With this change, we do not pass the `--no-init` option in newer versions of less (530 or higher). This fixes #749
This has been fixed in bat 0.13. |
version: bat 0.12.1
Bat leaves the text behind if it is started like
bat somefile
orbat somefile --pager='less'
if i start it like
bat somefile --pager='less -r'
it works fine and leaves nothing behind as less does.
The text was updated successfully, but these errors were encountered: