Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep interactive shell working even after an error #26

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/deno_task_shell/src/shell/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ impl ShellState {
state.token = self.token.child_token();
state
}

pub fn reset_cancellation_token(&mut self) {
self.token = CancellationToken::default();
}
}

#[derive(Debug, PartialEq, Eq)]
Expand Down
4 changes: 3 additions & 1 deletion crates/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ async fn interactive() -> anyhow::Result<()> {

let mut prev_exit_code = 0;
loop {
// Reset cancellation flag
state.reset_cancellation_token();

// Display the prompt and read a line
let readline = if prev_exit_code == 0 {
let cwd = state.cwd().to_string_lossy().to_string();
Expand All @@ -77,7 +80,6 @@ async fn interactive() -> anyhow::Result<()> {
.strip_prefix(home_str)
.map(|stripped| format!("~{}$ ", stripped.replace('\\', "/")))
.unwrap_or_else(|| format!("{}$ ", cwd));

rl.readline(&prompt)
} else {
rl.readline("xxx ")
Expand Down
Loading