Skip to content

Commit

Permalink
Merge pull request #373 from mgeisler/release-0.14.0
Browse files Browse the repository at this point in the history
Release 0.14.0
  • Loading branch information
mgeisler authored Jun 5, 2021
2 parents 85d2c1c + 1be7943 commit 65277f5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 32 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,14 @@ jobs:
let q = [`repo:${context.repo.owner}/${context.repo.repo}`,
'is:pr', 'is:merged', `merged:>${cutoff}`]
// Need to use https://octokit.github.io/rest.js/v18#pagination!
const prs = await github.search.issuesAndPullRequests({
const prs = await github.paginate(github.search.issuesAndPullRequests, {
q: q.join(' '),
sort: 'created',
order: 'asc',
})
core.info(`Found ${prs.data.items.length} merged PRs`)
core.info(`Found ${prs.length} merged PRs`)
const changelog = prs.data.items.map(
const changelog = prs.map(
pr => `* [#${pr.number}](${pr.html_url}): ${pr.title}`
).join('\n')
core.exportVariable('CHANGELOG', changelog)
Expand Down
117 changes: 93 additions & 24 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,110 @@
This file lists the most important changes made in each release of
`textwrap`.

## Unreleased
## Version 0.14.0 (2021-06-05)

This is a major feature release which adds new generic type parameters
to the `Options` struct. These parameters lets you statically
configure the wrapping algorithm and the word separator:

* `wrap_algorithms::WrapAlgorithm`: this trait replaces the old
`core::WrapAlgorithm` enum. The enum variants are now two structs:
`wrap_algorithms::FirstFit` and `wrap_algorithms::OptimalFit`.

* `WordSeparator`: this new trait lets you specify how words are
separated in the text. Until now, Textwrap would simply split on
spaces. While this works okay for Western languages, it fails to
take emojis and East-Asian languages into account.

The new `AsciiSpace` and `UnicodeBreakProperties` structs implement
the trait. The latter is available if the new optional
`unicode-linebreak` Cargo feature is enabled.
This is a major feature release which makes Textwrap more configurable
and flexible. The high-level API of `textwrap::wrap` and
`textwrap::fill` remains unchanged, but low-level structs have moved
around.

Common usages of textwrap stays unchanged, but if you previously
spelled out the full type for `Options`, you now need to take the
extra type parameters into account. This means that
The biggest change is the introduction of new generic type parameters
to the `Options` struct. These parameters lets you statically
configure the wrapping algorithm, the word separator, and the word
splitter. If you previously spelled out the full type for `Options`,
you now need to take the extra type parameters into account. This
means that

```rust
let options: Options<HyphenSplitter> = Options::new(80);
```

need to change to
changes to

```rust
let options: Options<wrap_algorithms::FirstFit, AsciiSpace, HyphenSplitter> = Options::new(80);
let options: Options<
wrap_algorithms::FirstFit,
word_separators::AsciiSpace,
word_splitters::HyphenSplitter,
> = Options::new(80);
```

You won’t see any chance if you call `wrap` directly with a width or
with an `Options` constructed on the fly.
This is quite a mouthful, so we suggest using type inferrence where
possible. You won’t see any chance if you call `wrap` directly with a
width or with an `Options` value constructed on the fly. Please open
an issue if this causes problems for you!

### New `WordSeparator` Trait

* [#332](https://github.com/mgeisler/textwrap/pull/332): Add
`WordSeparator` trait to allow customizing how words are found in a
line of text. Until now, Textwrap would always assume that words are
separated by ASCII space characters. You can now customize this as
needed.

* [#313](https://github.com/mgeisler/textwrap/pull/313): Add support
for using the Unicode line breaking algorithm to find words. This is
done by adding a second implementation of the new `WordSeparator`
trait. The implementation uses the unicode-linebreak crate, which is
a new optional dependency.

With this, Textwrap can be used with East-Asian languages such as
Chinese or Japanese where there are no spaces between words.
Breaking a long sequence of emojis is another example where line
breaks might be wanted even if there are no whitespace to be found.
Feedback would be appreciated for this feature.


### Indent

* [#353](https://github.com/mgeisler/textwrap/pull/353): Trim trailing
whitespace from `prefix` in `indent`.

Before, empty lines would get no prefix added. Now, empty lines have
a trimmed prefix added. This little trick makes `indent` much more
useful since you can now safely indent with `"# "` without creating
trailing whitespace in the output due to the trailing whitespace in
your prefix.

* [#354](https://github.com/mgeisler/textwrap/pull/354): Make `indent`
about 20% faster by preallocating the output string.


### Documentation

* [#308](https://github.com/mgeisler/textwrap/pull/308): Document
handling of leading and trailing whitespace when wrapping text.

### WebAssembly Demo

* [#310](https://github.com/mgeisler/textwrap/pull/310): Thanks to
WebAssembly, you can now try out Textwrap directly in your browser.
Please try it out: https://mgeisler.github.io/textwrap/.

### New Generic Parameters

* [#331](https://github.com/mgeisler/textwrap/pull/331): Remove outer
boxing from `Options`.

* [#357](https://github.com/mgeisler/textwrap/pull/357): Replace
`core::WrapAlgorithm` enum with a `wrap_algorithms::WrapAlgorithm`
trait. This allows for arbitrary wrapping algorithms to be plugged
into the library.

* [#358](https://github.com/mgeisler/textwrap/pull/358): Switch
wrapping functions to use a slice for `line_widths`.

* [#368](https://github.com/mgeisler/textwrap/pull/368): Move
`WordSeparator` and `WordSplitter` traits to separate modules.
Before, Textwrap had several top-level structs such as
`NoHyphenation` and `HyphenSplitter`. These implementations of
`WordSplitter` now lives in a dedicated `word_splitters` module.
Similarly, we have a new `word_separators` module for
implementations of `WordSeparator`.

* [#369](https://github.com/mgeisler/textwrap/pull/369): Rename
`Options::splitter` to `Options::word_splitter` for consistency with
the other fields backed by traits.

## Version 0.13.4 (2021-02-23)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "textwrap"
version = "0.13.4"
version = "0.14.0"
authors = ["Martin Geisler <[email protected]>"]
description = "Powerful library for word wrapping, indenting, and dedenting strings"
documentation = "https://docs.rs/textwrap/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ drawn on a [HTML5 canvas using WebAssembly][wasm-demo].
To use the textwrap crate, add this to your `Cargo.toml` file:
```toml
[dependencies]
textwrap = "0.13"
textwrap = "0.14"
```

By default, this enables word wrapping with support for Unicode
Expand Down
21 changes: 21 additions & 0 deletions images/textwrap-0.14.0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
//! The full dependency graph, where dashed lines indicate optional
//! dependencies, is shown below:
//!
//! <img src="https://raw.githubusercontent.com/mgeisler/textwrap/master/images/textwrap-0.13.4.svg">
//! <img src="https://raw.githubusercontent.com/mgeisler/textwrap/master/images/textwrap-0.14.0.svg">
//!
//! ## Default Features
//!
Expand Down Expand Up @@ -177,7 +177,7 @@
//! [terminal_size]: https://docs.rs/terminal_size/
//! [hyphenation]: https://docs.rs/hyphenation/
#![doc(html_root_url = "https://docs.rs/textwrap/0.13.4")]
#![doc(html_root_url = "https://docs.rs/textwrap/0.14.0")]
#![forbid(unsafe_code)] // See https://github.com/mgeisler/textwrap/issues/210
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
Expand Down

0 comments on commit 65277f5

Please sign in to comment.