Closed typkrft closed 4 years ago
Unfortunately, not at the moment. There's nothing technically preventing us from implementing word wrapping that splits on whitespace or parsed syntax tokens, but I'm skeptical of taking a naïve approach to it becsuse it could alter the meaning of the printed code.
Sublime syntax files don't specify how languages are supposed to handle wrapping, indentation and whitespace, and making assumptions about that would not have held for every language. For example, some languages like Python or Sass use indentation for determining blocks. If bat inserted a hard wrap in one of these languages and didn't get the indentation correct, it could mean something entirely different than what the unwraped code meant.
Yeah I totally get that. I generally don't use bat for looking at code. My primary use for it is to attractively format article summaries I've pulled from newsboat with sumy. So an option would be great --text-wrap or something, but I totally get that this may be an edge case and not worth the effort. Thanks for the great program regardless.
If you are mainly interested in text, you could have a look at par
(https://en.wikipedia.org/wiki/Par_(command)). It's an "ancient" tool, but works great.
As the desired width, you would take the actual terminal width (tput cols
) and subtract the width of bat
s sidebar (9 characters for full style):
bat /tmp/txt | par $(($(tput cols) - 9)) | bat
(you would obviously put this into a shell function or similar)
Line numbers are obviously not related to the original line numbers. Git changes also wouldn't work.
Amazing. I'd never even heard of that command. Truly appreciate the assistance. This is completely satisfactory and this issue can be closed as far as I'm concerned.
Is it possible to wrap before a word instead of in the middle of a word?