Skip to content

Commit 96b0f0a

Browse files
authored
feat: add Q_AUTOCOMPLETE_DISABLED env var (#563)
1 parent eb30007 commit 96b0f0a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

crates/figterm/src/main.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ use fig_log::{
5252
LogArgs,
5353
initialize_logging,
5454
};
55-
use fig_os_shim::Context;
55+
use fig_os_shim::{
56+
Context,
57+
Env,
58+
};
5659
use fig_proto::local::{
5760
self,
5861
EnvironmentVariable,
@@ -344,6 +347,14 @@ where
344347
shell_enabled && !insertion_locked && !preexec
345348
}
346349

350+
const Q_DISABLE_AUTOCOMPLETE: &str = "Q_DISABLE_AUTOCOMPLETE";
351+
352+
fn autocomplete_enabled(env: &Env) -> bool {
353+
env.get_os(Q_DISABLE_AUTOCOMPLETE).is_none_or(|s| s.is_empty())
354+
}
355+
356+
static AUTOCOMPLETE_ENABLED: LazyLock<bool> = LazyLock::new(|| autocomplete_enabled(&Env::new()));
357+
347358
async fn send_edit_buffer<T>(
348359
term: &Term<T>,
349360
sender: &Sender<Hostbound>,
@@ -352,6 +363,10 @@ async fn send_edit_buffer<T>(
352363
where
353364
T: EventListener,
354365
{
366+
if !*AUTOCOMPLETE_ENABLED {
367+
return Ok(());
368+
}
369+
355370
match term.get_current_buffer() {
356371
Some(edit_buffer) => {
357372
if let Some(cursor_idx) = edit_buffer.cursor_idx.and_then(|i| i.try_into().ok()) {
@@ -986,3 +1001,22 @@ fn main() {
9861001
},
9871002
}
9881003
}
1004+
1005+
#[cfg(test)]
1006+
mod tests {
1007+
use super::*;
1008+
1009+
#[test]
1010+
fn autocomplete_enabled_test() {
1011+
assert!(autocomplete_enabled(&Env::new_fake()));
1012+
assert!(autocomplete_enabled(&Env::from_slice(&[(Q_DISABLE_AUTOCOMPLETE, "")])));
1013+
assert!(!autocomplete_enabled(&Env::from_slice(&[(
1014+
Q_DISABLE_AUTOCOMPLETE,
1015+
"1"
1016+
)])));
1017+
assert!(!autocomplete_enabled(&Env::from_slice(&[(
1018+
Q_DISABLE_AUTOCOMPLETE,
1019+
"1"
1020+
)])));
1021+
}
1022+
}

0 commit comments

Comments
 (0)