https://github.com/foxbenjaminfox/ex_textwrap
Elixir NIF bindings to the textwrap crate, for wrapping and indenting text.
https://github.com/foxbenjaminfox/ex_textwrap
elixir formatting nif textwrap
Last synced: 4 months ago
JSON representation
Elixir NIF bindings to the textwrap crate, for wrapping and indenting text.
- Host: GitHub
- URL: https://github.com/foxbenjaminfox/ex_textwrap
- Owner: foxbenjaminfox
- License: apache-2.0
- Created: 2021-02-12T09:08:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-08T15:50:53.000Z (over 4 years ago)
- Last Synced: 2025-06-04T17:16:38.919Z (4 months ago)
- Topics: elixir, formatting, nif, textwrap
- Language: Elixir
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Textwrap
Textwrap is a set of NIF bindings to the [`textwrap`](https://github.com/mgeisler/textwrap) Rust crate, for wrapping, indenting, and dedenting text.
## Installation
This package is [available in Hex](https://hex.pm/packages/textwrap), and can be installed
by adding `textwrap` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:textwrap, "~> 0.1.0"}
]
end
```## Getting Started
Use `fill/2` to get a wrapped string, or `wrap/2` to get a list of wrapped lines:
```elixir
iex> Textwrap.fill("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor", 30)
"Lorem ipsum dolor sit amet,\nconsectetur adipisicing elit,\nsed do eiusmod tempor"iex> Textwrap.wrap("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor", 30)
["Lorem ipsum dolor sit amet,", "consectetur adipisicing elit,", "sed do eiusmod tempor"]
```The second argument to `fill/2` or `wrap/2` can instead be a keyword list with the desired width as well as [further options](https://hexdocs.pm/textwrap/Textwrap.html#wrap/2):
```elixir
iex> Textwrap.wrap("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor", width: 30, initial_indent: "> ", subsequent_indent: ">> ")
["> Lorem ipsum dolor sit amet,", ">> consectetur adipisicing", ">> elit, sed do eiusmod tempor"]
```The width can either be a positive integer, or `:termwidth`. In the latter case, the width of the terminal connected to standard output is used, or a fallback width of 80 otherwise.
See the [API docs](https://hexdocs.pm/textwrap) for more details.
## License
`textwrap` is distributed under the Apache License, version 2.0.