tab_api/env.rs
1use log::debug;
2use tokio::process::Command;
3
4/// Instructs the command module that it should interact with the terminal in raw mode
5/// If false, the environment may not be a terminal pty.
6/// The integration tests disable this flag.
7pub fn is_raw_mode() -> bool {
8 std::env::var("TAB_RAW_MODE")
9 .ok()
10 .map(|raw| raw.parse().unwrap_or(true))
11 .unwrap_or(true)
12}
13
14/// Environment variables that should be forwarded from the command, to Daemon and pty processes.
15pub const FORWARD_ENV_VARS: &[&str] = &[
16 "TAB_RUNTIME_DIR", // The daemon & pty should inherit the runtime directory of the command client
17 "TAB_RAW_MODE", // Raw mode controls stderr forwarding. When disabled, the command stderr pipe is inherited by the daemon/client
18 "TAB_BIN", // path to the initiating tab binary (where the command was launched). used by integration tests to launch tab within a shell
19];
20
21/// Forwards the environment variables required by tab from the current process, to the child
22/// See FORWARD_ENV_VARS for a list and explanation of forwarded vars.
23pub fn forward_env(child: &mut Command) {
24 for var in crate::env::FORWARD_ENV_VARS.iter().copied() {
25 if let Ok(value) = std::env::var(var) {
26 debug!("forwarding env {} as {}", var, &value);
27 child.env(var, value);
28 }
29 }
30}
31
32/// Forwards the environment variables required by tab from the current process, to the child
33/// See FORWARD_ENV_VARS for a list and explanation of forwarded vars.
34pub fn forward_env_std(child: &mut std::process::Command) {
35 for var in crate::env::FORWARD_ENV_VARS.iter().copied() {
36 if let Ok(value) = std::env::var(var) {
37 debug!("forwarding env {} as {}", var, &value);
38 child.env(var, value);
39 }
40 }
41}