Skip to content

Elixir NIF bindings to the textwrap crate, for wrapping and indenting text.

License

Notifications You must be signed in to change notification settings

foxbenjaminfox/ex_textwrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Textwrap

Textwrap is a set of NIF bindings to the textwrap Rust crate, for wrapping, indenting, and dedenting text.

Installation

This package is available in Hex, and can be installed by adding textwrap to your list of dependencies in mix.exs:

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:

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:

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 for more details.

License

textwrap is distributed under the Apache License, version 2.0.

About

Elixir NIF bindings to the textwrap crate, for wrapping and indenting text.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published