1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2024 Takayuki Sato. All Rights Reserved.
// This program is free software under MIT License.
// See the file LICENSE in this distribution for more details.
//! 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.
//!
//! ```toml
//! [dependencies]
//! linebreak = "0.3.1"
//! ```
//!
//! ## Usage
//!
//! The usage example of `LineIter` struct in this crate is as follows:
//!
//! ```rust
//! 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:
//!
//! ```shell
//! ....:....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.
//! ```
pub use LineIter;
pub use Size;
pub use ;
/// Returns the column number of the current terminal.
///
/// If failing to retrieve the column number, this function returns the
/// tentative value `80`.
/// This is because this crate would be used on character output terminals,
/// and errors occure only in special circumstances such as during CI
/// execution.
/// In such circumstances, it is assumed that returning a tentative value would
/// be beneficial than returning an error.
/// Returns the size of the current terminal.
///
/// If failing to retrieve the column number, this function returns the
/// tentative size `{ col: 80, row: 24 }`.
/// This is because this crate would be used on character output terminals,
/// and errors occure only in special circumstances such as during CI
/// execution.
/// In such circumstances, it is assumed that returning a tentative value would
/// be beneficial than returning an error.