From 9cd4f21963f5761e20f0bc7f831303bdcb1050db Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 3 Mar 2019 19:31:13 -0800 Subject: [PATCH] Check $TERM on pancurses as well --- src/backend/curses/pan.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index b77ee83..620af0f 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -35,6 +35,20 @@ fn find_closest_pair(pair: ColorPair) -> (i16, i16) { impl Backend { /// Creates a new pancurses-based backend. pub fn init() -> std::io::Result> { + // Check the $TERM variable (at least on unix). + // Otherwise we'll just abort. + // TODO: On windows, is there anything to check? + if cfg!(unix) + && std::env::var("TERM") + .map(|var| var.is_empty()) + .unwrap_or(true) + { + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + "$TERM is unset. Cannot initialize pancurses interface.", + )); + } + ::std::env::set_var("ESCDELAY", "25"); // TODO: use pancurses::newterm()