Check $TERM on pancurses as well

This commit is contained in:
Alexandre Bury 2019-03-03 19:31:13 -08:00
parent f765e9ac07
commit 9cd4f21963

View File

@ -35,6 +35,20 @@ fn find_closest_pair(pair: ColorPair) -> (i16, i16) {
impl Backend { impl Backend {
/// Creates a new pancurses-based backend. /// Creates a new pancurses-based backend.
pub fn init() -> std::io::Result<Box<dyn backend::Backend>> { pub fn init() -> std::io::Result<Box<dyn backend::Backend>> {
// 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"); ::std::env::set_var("ESCDELAY", "25");
// TODO: use pancurses::newterm() // TODO: use pancurses::newterm()