Skip to content

Conversation

@NORMAL-EX
Copy link
Contributor

Summary

Closes #3079

This PR adds a new word option to the --wrap argument that wraps text at word boundaries (spaces) instead of breaking in the middle of words.

Changes

  1. wrapping.rs: Added Word variant to WrappingMode enum
  2. clap_app.rs: Added word to the allowed values for --wrap
  3. app.rs: Handle word option and map to WrappingMode::Word
  4. printer.rs: Implemented word wrapping logic that:
    • Wraps at word boundaries (spaces) when possible
    • Falls back to character wrapping for words longer than the terminal width
    • Trims leading spaces after wrapping to avoid indentation issues
  5. doc/short-help.txt and doc/long-help.txt: Updated help text

Usage

# Word wrapping
bat --wrap=word file.txt

# With terminal width
echo "Lorem ipsum dolor sit amet" | bat --wrap=word --terminal-width=20

Behavior

Mode Description
auto Default behavior (character wrap in non-interactive, no wrap in interactive)
never No wrapping
character Wrap at any character
word Wrap at word boundaries, fall back to character wrap for long words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant