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

Word wrapping #1887

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Word wrapping #1887

wants to merge 13 commits into from

Conversation

Cimbali
Copy link

@Cimbali Cimbali commented Jun 13, 2024

I wanted to use word wrapping and saw #1648 so here’s a preliminary PR, to discuss what needs changing/rewording/testing. In short, I’ve added a second callback similar to GetLinePrefix that defines wrapping points. They return a tuple of:

  1. wrap position (self-explanatory)
  2. number of chars to remove. Typically to remove the whitespace that was wrapped.* You can also return -1 to truncate the line.
  3. continuation text: any formatted text to insert before the line break to indicate continuation. Typically a hyphen if breaking a word in 2, or a in a code block to indicate a non-semantic break, etc.

A default wrapping function is provided to do word wrapping (and it can even be re-used and tuned for different purposes). It can be activated with word_wrap=True on windows. For actual hyphenation a user would have to provide their own function.

* E.g. if you want to wrap the text example wrapped text on 7 columns, you either break before the first space and remove it, or before and then your next line starts with a space (which looks weird). On 15 columns you’d have a similar problem but either break as example / wrapped / text without character removal, or example wrapped / text, so allowing character removal is good for efficiency of justified text.

@Cimbali
Copy link
Author

Cimbali commented Jun 17, 2024

I’ve added an example that showcases the feature, here’s what it looks like with:

  1. no wrapping
  2. default word wrapping
  3. customised word wrapping with line continuation markers
  4. truncation (with a "..." marker)

image

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

Successfully merging this pull request may close these issues.

1 participant