1use std::env;
2
3use atty::Stream;
4#[cfg(windows)]
5use ansi_term::enable_ansi_support;
6
7fn bool_env(name: &str) -> bool {
10 if let Some(value) = env::var_os(name) {
11 !(value == "0" || value == "false" || value == "")
12 } else {
13 false
14 }
15}
16
17#[derive(Clone, Default)]
18pub struct Env {
19 pub timetrap_config_file: Option<String>,
20 pub tiempo_config_file: Option<String>,
21 pub supress_warming: bool,
22 pub stdout_is_tty: bool,
23 pub stderr_is_tty: bool,
24}
25
26impl Env {
27 pub fn read() -> Env {
28 #[cfg(windows)]
29 let tty = enable_ansi_support().is_ok();
30 #[cfg(not(windows))]
31 let tty = true;
32
33 Env {
34 timetrap_config_file: env::var("TIMETRAP_CONFIG_FILE").ok(),
35 tiempo_config_file: env::var("TIEMPO_CONFIG").ok(),
36 supress_warming: bool_env("TIEMPO_SUPRESS_TIMETRAP_WARNING"),
37 stdout_is_tty: tty && atty::is(Stream::Stdout),
38 stderr_is_tty: tty && atty::is(Stream::Stderr),
39 }
40 }
41}