From a508fee0cc6346fa110ab12ba23d876311a68e66 Mon Sep 17 00:00:00 2001 From: Alexander Shirokov Date: Sat, 13 Sep 2025 14:47:02 +0200 Subject: [PATCH] terminal: use fallback values for the terminal size Use the default terminal size if the size cannot be detected. The default value is 80 columns by 24 rows. --- helix-tui/src/terminal.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/helix-tui/src/terminal.rs b/helix-tui/src/terminal.rs index 72f38d7177d7..e05f7b1fb9a9 100644 --- a/helix-tui/src/terminal.rs +++ b/helix-tui/src/terminal.rs @@ -80,7 +80,7 @@ where /// Wrapper around Terminal initialization. Each buffer is initialized with a blank string and /// default colors for the foreground and the background pub fn new(backend: B) -> io::Result> { - let size = backend.size()?; + let size = nonempty_terminal_size(backend.size()); Terminal::with_options( backend, TerminalOptions { @@ -236,6 +236,13 @@ where /// Queries the real size of the backend. pub fn size(&self) -> io::Result { - self.backend.size() + Ok(nonempty_terminal_size(self.backend.size())) } } + +fn nonempty_terminal_size(size: io::Result) -> Rect { + size.unwrap_or_else(|e| { + log::warn!("{}. Using default terminal size", e); + Rect::new(0, 0, 80, 24) + }) +}