ncurses: panic with error message if $TERM is unset

This commit is contained in:
Alexandre Bury 2019-03-03 18:24:04 -08:00
parent 4f34e97f27
commit dcee6da16a

View File

@ -59,6 +59,14 @@ fn write_to_tty(bytes: &[u8]) -> io::Result<()> {
impl Backend { impl Backend {
/// Creates a new ncurses-based backend. /// Creates a new ncurses-based backend.
pub fn init() -> Box<dyn backend::Backend> { pub fn init() -> Box<dyn backend::Backend> {
// Check the $TERM variable.
if std::env::var("TERM")
.map(|var| var.is_empty())
.unwrap_or(true)
{
panic!("$TERM is unset. Cannot initialize ncurses interface.");
}
// Change the locale. // Change the locale.
// For some reasons it's mandatory to get some UTF-8 support. // For some reasons it's mandatory to get some UTF-8 support.
ncurses::setlocale(ncurses::LcCategory::all, ""); ncurses::setlocale(ncurses::LcCategory::all, "");