Skip to content

Commit ffa542a

Browse files
committed
Fix #83: Large memory usage
Wrapping at small widths cause excessive memory usage when printing unicode, so set a minimum width of text of 40.
1 parent c2181be commit ffa542a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/print/unicode.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,18 @@ fn create_wrapping_options<'a>(
232232
} else if atty::is(atty::Stream::Stdout) {
233233
let width = crossterm::terminal::size()
234234
.map_err(|err| err.to_string())?
235-
.0;
236-
let width = if width as usize > graph_width {
237-
width as usize - graph_width
235+
.0 as usize;
236+
let text_width = width.saturating_sub(graph_width);
237+
if text_width < 40 {
238+
// If too little space left for text, do not wrap at all
239+
None
238240
} else {
239-
1
240-
};
241-
Some(
242-
textwrap::Options::new(width)
243-
.initial_indent(indent1)
244-
.subsequent_indent(indent2),
245-
)
241+
Some(
242+
textwrap::Options::new(text_width)
243+
.initial_indent(indent1)
244+
.subsequent_indent(indent2),
245+
)
246+
}
246247
} else {
247248
None
248249
};

0 commit comments

Comments
 (0)