Crate linebreak

source ·
Expand description

This crate is a library for breaking a given text into lines within a specified width. This crate also supports per-line indentation.

§Install

In Cargo.toml, write this crate as a dependency.

[dependencies]
linebreak = "0.1.0"

§Usage

The usage example of LineIter struct in this crate is as follows:

use linebreak::LineIter;

fn main() {
    let text = "Welcome to The Rust Programming Language, an introductory \
      book about Rust. The Rust programming language helps you write faster, \
      more reliable software. High-level ergonomics and low-level control are \
      often at odds in programming language design; Rust challenges that \
      conflict. Through balancing powerful technical capacity and a great \
      developer experience, Rust gives you the option to control low-level \
      details (such as memory usage) without all the hassle traditionally \
      associated with such control.";

    let mut iter = LineIter::new(&text, 80);
    iter.set_indent("_______");

    println!("....:....1....:....2....:....3....:....4....:....5....:....6\
              ....:....7....:....8");
    while let Some(line) = iter.next() {
        println!("{}", line);
    }
}

The output of the above code is as follows:

....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
_______Welcome to The Rust Programming Language, an introductory book about
_______Rust. The Rust programming language helps you write faster, more reliable
_______software. High-level ergonomics and low-level control are often at odds
_______in programming language design; Rust challenges that conflict. Through
_______balancing powerful technical capacity and a great developer experience,
_______Rust gives you the option to control low-level details (such as memory
_______usage) without all the hassle traditionally associated with such control.

Structs§

  • LineIter is the struct that outputs the given string line by line. This struct can control the overall line width and the indentation from any desired line.
  • Size is the struct for storing the size of the current terminal.

Functions§

  • Returns the display width of the specified character. A display width is determined by the Unicode Standard Annex #11 (UAX11) East-Asian-Width.
  • Checks whether the specified codepoint is one of the printable characters that includes letters, marks, numbers, punctuations, symbols from Unicode categories L, M, N, P, S, and the ASCII space character.
  • Returns the column number of the current terminal.
  • Returns the size of the current terminal.
  • Returns the display width of the specified text. This function calculates the width of the text taking into account the letter width determined by the Unicode Standard Annex #11 (UAX11) East-Asian-Width.