1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#[cfg(feature = "cache")]
pub mod cache;
#[cfg(feature = "cmdtrait")]
mod cmdtrait;
pub(crate) mod desktops;
pub mod detector;
mod error;
mod structs;

#[cfg(feature = "cache")]
use cache::*;
#[cfg(feature = "cmdtrait")]
pub use cmdtrait::*;
use detector::*;
pub use error::DetectionError;
pub use structs::Terminal;

/// Gets the default terminal  
/// If the `cache` feature is enabled, the result is cached  
/// The cache can be reset with `cache::cache_clear`
pub fn get_terminal() -> Result<Terminal, DetectionError> {
    #[cfg(feature = "cache")]
    if let Ok(term) = cache_get() {
        return Ok(term);
    }
    let term = detect_terminal();
    #[cfg(feature = "cache")]
    if let Ok(term) = term.as_ref() {
        let _ = cache_set(term.clone());
    };
    term
}

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;