From 1f62eb32a0d4e8718a0becaafa788f33f4ca281e Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 1 Jan 2018 02:37:33 -0800 Subject: [PATCH] Fixed a bug where very narrow terminal sizes would crash the editor. --- src/term_ui/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index fd6ee29..34a96b6 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -319,7 +319,7 @@ impl TermUI { }; let pstring = format!("{}%", percentage); self.screen - .draw(c2.1 - pstring.len(), c1.0, &pstring[..], style); + .draw(c2.1 - pstring.len().min(c2.1), c1.0, &pstring[..], style); // Text encoding info and tab style let nl = match editor.line_ending_type { @@ -338,7 +338,8 @@ impl TermUI { "UTF8:{} {}:{}", nl, soft_tabs_str, editor.soft_tab_width as usize ); - self.screen.draw(c2.1 - 30, c1.0, &info_line[..], style); + self.screen + .draw(c2.1 - 30.min(c2.1), c1.0, &info_line[..], style); // Draw main text editing area self.draw_editor_text(editor, (c1.0 + 1, c1.1), c2);