Skip to content

Commit

Permalink
feat: hide the sourcing of the activation script when starting shell (#…
Browse files Browse the repository at this point in the history
…2319)

Co-authored-by: Ruben Arts <[email protected]>
  • Loading branch information
wolfv and ruben-arts authored Oct 25, 2024
1 parent bb64a64 commit fb85c0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions crates/pixi_pty/src/unix/pty_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl PtySession {
/// Interact with the process. This will put the current process into raw mode and
/// forward all input from stdin to the process and all output from the process to stdout.
/// This will block until the process exits.
pub fn interact(&mut self) -> io::Result<Option<i32>> {
pub fn interact(&mut self, wait_until: Option<&str>) -> io::Result<Option<i32>> {
// Make sure anything we have written so far has been flushed.
self.flush()?;

Expand All @@ -99,6 +99,7 @@ impl PtySession {
// and forward the new terminal size to the process
let mut signals = Signals::new([SIGWINCH])?;

let mut write_stdout = wait_until.is_none();
// Call select in a loop and handle incoming data
let exit_status = loop {
// Make sure that the process is still alive
Expand Down Expand Up @@ -140,7 +141,16 @@ impl PtySession {
// We have new data coming from the process
if select_set.contains(process_stdout_fd) {
let bytes_read = self.process_stdout.read(&mut buf).unwrap_or(0);
if bytes_read > 0 {
if !write_stdout {
if let Some(wait_until) = wait_until {
if buf[..bytes_read]
.windows(wait_until.len())
.any(|window| window == wait_until.as_bytes())
{
write_stdout = true;
}
}
} else if bytes_read > 0 {
io::stdout().write_all(&buf[..bytes_read])?;
io::stdout().flush()?;
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ async fn start_unix_shell<T: Shell + Copy + 'static>(
shell_script.set_env_var(key, value).into_diagnostic()?;
}

const DONE_STR: &str = "=== DONE ===";
shell_script.echo(DONE_STR).into_diagnostic()?;

temp_file
.write_all(shell_script.contents().into_diagnostic()?.as_bytes())
.into_diagnostic()?;
Expand All @@ -170,7 +173,7 @@ async fn start_unix_shell<T: Shell + Copy + 'static>(
let mut process = PtySession::new(command).into_diagnostic()?;
process.send_line(source_command).into_diagnostic()?;

process.interact().into_diagnostic()
process.interact(Some(DONE_STR)).into_diagnostic()
}

/// Starts a nu shell.
Expand Down

0 comments on commit fb85c0b

Please sign in to comment.