openssh_mux_client/
default_config.rs

1use std::{env, os::unix::ffi::OsStringExt};
2
3use once_cell::sync::OnceCell;
4
5use crate::{NonZeroByteSlice, NonZeroByteVec};
6
7/// Return environment variable `$TERM` if set.
8/// Otherwise, returns empty string.
9pub fn get_term() -> &'static NonZeroByteSlice {
10    static TERM: OnceCell<Option<NonZeroByteVec>> = OnceCell::new();
11    TERM.get_or_init(|| {
12        env::var_os("TERM")
13            .map(OsStringExt::into_vec)
14            .map(NonZeroByteVec::from_bytes_remove_nul)
15    })
16    .as_deref()
17    .unwrap_or_else(|| NonZeroByteSlice::new(&[]).unwrap())
18}