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

Problem with line wrapping for bat #2515

Closed
1 task done
craigtmoore opened this issue Feb 12, 2020 · 4 comments
Closed
1 task done

Problem with line wrapping for bat #2515

craigtmoore opened this issue Feb 12, 2020 · 4 comments

Comments

@craigtmoore
Copy link

craigtmoore commented Feb 12, 2020

  • I was not able to find an open or closed issue matching what I'm seeing

I created an issue #824 and they recommended that I push the issue upstream.

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.24.1.windows.2
cpu: x86_64
built from commit: 992f0773022527b1b0cb1e0c13aec97dd5248053
sizeof-long: 4
sizeof-size_t: 8
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

───────┬───────────────────────────────────────────────────────────────────────
       │ File: C:/Program Files/Git/etc/install-options.txt
───────┼───────────────────────────────────────────────────────────────────────
   1   │ Editor Option: Notepad++
   2   │ Custom Editor Path:
   3   │ Path Option: Cmd
   4   │ SSH Option: OpenSSH
   5   │ Tortoise Option: false
   6   │ CURL Option: OpenSSL
   7   │ CRLF Option: CRLFAlways
   8   │ Bash Terminal Option: MinTTY
   9   │ Performance Tweaks FSCache: Enabled
  10   │ Use Credential Manager: Enabled
  11   │ Enable Symlinks: Disabled
  12   │ Enable Builtin Interactive Add: Disabled
───────┴───────────────────────────────────────────────────────────────────────
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

I'm trying to use bat to view stdout and files from the termainal.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

Bash

$ bat --help | bat
───────┬───────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼───────────────────────────────────────────────────────────────────────
   1   │ bat 0.12.1
   2   │ A cat(1) clone with syntax highlighting and Git integration.
   3   │
   4   │ USAGE:
   5   │     bat.exe [OPTIONS] [FILE]...
   6   │     bat.exe <SUBCOMMAND>
   7   │
   8   │ OPTIONS:
   9   │     -l, --language <language>
  10   │             Explicitly set the language for syntax highlighting. The l
       │ anguage can be specified as a
  11   │             name (like 'C++' or 'LaTeX') or possible file extension (l
       │ ike 'cpp', 'hpp' or 'md'). Use
  12   │             '--list-languages' to show all supported language names an
       │ d file extensions.
  13   │     -L, --list-languages
  14   │             Display a list of supported languages for syntax highlight
       │ ing.
  • What did you expect to occur after running these commands?

I expected that when bat attempted to assess the terminal width using:
https://github.com/mitsuhiko/console/blob/a999e34bbbf66886aa7420dc6e2d7cc264ade959/src/windows_term.rs#L77-L87
the bash terminal would return the correct width.

  • What actually happened instead?

bat wraps all lines at 80 characters, instead of at the width of the terminal

@rimrul
Copy link
Member

rimrul commented Feb 13, 2020

Bash Terminal Option: MinTTY

running in bash

windows_term.rs

That could already be your problem. That method tries to use winapi calls to get the size of a conhost window, but it's running in a unix TTY. Unless you linked the wrong file and it's actually using unix_term.rs to determine it's size, I'd expect that to fail.

You'd probably need to compile your own MSys2 bat to get this to work in MinTTY. If you don't care about MinTTY you could alternatively reinstall Git for Windows with the windows console option.

@rimrul
Copy link
Member

rimrul commented Feb 13, 2020

mintty/mintty#482 confirms my expectations: GetConsoleScreenBufferInfo doesn't work in MinTTY. isatty/ioctl would work when compiled as an MSys2 application.

@rimrul
Copy link
Member

rimrul commented Feb 13, 2020

And looking at rust-lang/rust, there doesn't seem to be a way to build rust for MSys2, so building bat for MSys2 is probably an unreasonable endeavour.

That reduces your sane options to

  • reinstalling Git for Windows w/o MinTTY
  • living with the fact that bat can't determine the size of a MinTTY window
  • moving from bat to something that can.
  • create a PR to bat that adds a parameter to manually set the wrapping width and set it using a wrapper and an alias.

Edit: does winpty bat work? I probably should've thought of that first.

@craigtmoore
Copy link
Author

Yes winpty bat does work, though it doesn't work if you try to pipe to it, i.e. this doesn't work bat --help | winpty bat, but winpty bat someFile does work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants