Skip to content

Commit 9106acf

Browse files
committed
feat: Allow users to override the timeout
1 parent 11a5381 commit 9106acf

File tree

1 file changed

+52
-12
lines changed
  • crates/completest-pty/src

1 file changed

+52
-12
lines changed

crates/completest-pty/src/lib.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ PROMPT='%% '
102102
&self.home
103103
}
104104

105+
/// Set the timeout for completion
106+
pub fn timeout(&mut self, timeout: Duration) {
107+
self.timeout = timeout;
108+
}
109+
105110
/// Register a completion script
106111
pub fn register(&mut self, name: &str, content: &str) -> std::io::Result<()> {
107112
let path = self.home.join(format!("zsh/_{name}"));
@@ -110,15 +115,20 @@ PROMPT='%% '
110115
}
111116

112117
/// Get the output from typing `input` into the shell
113-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
118+
pub fn complete(
119+
&mut self,
120+
input: &str,
121+
term: &Term,
122+
timeout: Duration,
123+
) -> std::io::Result<String> {
114124
let mut command = Command::new("zsh");
115125
command.arg("--noglobalrcs");
116126
command
117127
.env("PATH", &self.path)
118128
.env("TERM", "xterm")
119129
.env("ZDOTDIR", &self.home);
120130
let echo = false;
121-
comptest(command, echo, input, term, self.timeout)
131+
comptest(command, echo, input, term, timeout)
122132
}
123133
}
124134

@@ -132,7 +142,7 @@ impl Runtime for ZshRuntime {
132142
}
133143

134144
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
135-
self.complete(input, term)
145+
self.complete(input, term, self.timeout)
136146
}
137147
}
138148

@@ -207,6 +217,11 @@ PS1='% '
207217
&self.home
208218
}
209219

220+
/// Set the timeout for completion
221+
pub fn timeout(&mut self, timeout: Duration) {
222+
self.timeout = timeout;
223+
}
224+
210225
/// Register a completion script
211226
pub fn register(&mut self, _name: &str, content: &str) -> std::io::Result<()> {
212227
let mut file = std::fs::OpenOptions::new()
@@ -217,7 +232,12 @@ PS1='% '
217232
}
218233

219234
/// Get the output from typing `input` into the shell
220-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
235+
pub fn complete(
236+
&mut self,
237+
input: &str,
238+
term: &Term,
239+
timeout: Duration,
240+
) -> std::io::Result<String> {
221241
let mut command = Command::new("bash");
222242
let inputrc_path = self.home.join(".inputrc");
223243
command
@@ -226,7 +246,7 @@ PS1='% '
226246
.env("INPUTRC", &inputrc_path)
227247
.args([OsStr::new("--rcfile"), self.config.as_os_str()]);
228248
let echo = !input.contains("\t\t");
229-
comptest(command, echo, input, term, self.timeout)
249+
comptest(command, echo, input, term, timeout)
230250
}
231251
}
232252

@@ -240,7 +260,7 @@ impl Runtime for BashRuntime {
240260
}
241261

242262
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
243-
self.complete(input, term)
263+
self.complete(input, term, self.timeout)
244264
}
245265
}
246266

@@ -312,6 +332,11 @@ end;
312332
&self.home
313333
}
314334

335+
/// Set the timeout for completion
336+
pub fn timeout(&mut self, timeout: Duration) {
337+
self.timeout = timeout;
338+
}
339+
315340
/// Register a completion script
316341
pub fn register(&mut self, name: &str, content: &str) -> std::io::Result<()> {
317342
let path = self.home.join(format!("fish/completions/{name}.fish"));
@@ -320,15 +345,20 @@ end;
320345
}
321346

322347
/// Get the output from typing `input` into the shell
323-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
348+
pub fn complete(
349+
&mut self,
350+
input: &str,
351+
term: &Term,
352+
timeout: Duration,
353+
) -> std::io::Result<String> {
324354
let mut command = Command::new("fish");
325355
command
326356
.env("PATH", &self.path)
327357
// fish requires TERM to be set.
328358
.env("TERM", "xterm")
329359
.env("XDG_CONFIG_HOME", &self.home);
330360
let echo = false;
331-
comptest(command, echo, input, term, self.timeout)
361+
comptest(command, echo, input, term, timeout)
332362
}
333363
}
334364

@@ -342,7 +372,7 @@ impl Runtime for FishRuntime {
342372
}
343373

344374
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
345-
self.complete(input, term)
375+
self.complete(input, term, self.timeout)
346376
}
347377
}
348378

@@ -412,6 +442,11 @@ set edit:prompt = (constantly \"% \")
412442
&self.home
413443
}
414444

445+
/// Set the timeout for completion
446+
pub fn timeout(&mut self, timeout: Duration) {
447+
self.timeout = timeout;
448+
}
449+
415450
/// Register a completion script
416451
pub fn register(&mut self, _name: &str, content: &str) -> std::io::Result<()> {
417452
let mut file = std::fs::OpenOptions::new()
@@ -422,13 +457,18 @@ set edit:prompt = (constantly \"% \")
422457
}
423458

424459
/// Get the output from typing `input` into the shell
425-
pub fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
460+
pub fn complete(
461+
&mut self,
462+
input: &str,
463+
term: &Term,
464+
timeout: Duration,
465+
) -> std::io::Result<String> {
426466
let mut command = Command::new("elvish");
427467
command
428468
.env("PATH", &self.path)
429469
.env("XDG_CONFIG_HOME", &self.home);
430470
let echo = false;
431-
comptest(command, echo, input, term, self.timeout)
471+
comptest(command, echo, input, term, timeout)
432472
}
433473
}
434474

@@ -442,7 +482,7 @@ impl Runtime for ElvishRuntime {
442482
}
443483

444484
fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String> {
445-
self.complete(input, term)
485+
self.complete(input, term, self.timeout)
446486
}
447487
}
448488

0 commit comments

Comments
 (0)