Skip to content

In unix like system, set foreground process while running external command - #6206

Merged
sholderbach merged 15 commits into
nushell:mainfrom
WindSoilder:fg_name
Aug 2, 2022
Merged

sholderbach merged 15 commits into
nushell:mainfrom
WindSoilder:fg_name

Conversation

@WindSoilder

Copy link
Copy Markdown
Contributor

Description

Closes: #6156 #3861

Screenshots:

  1. run ipython inside tmux session.

图片

Hi, @rosshadden, would you please check if the implementation suited for your need? I'm not really confident with the implementation because it's really tricky to me :-( I've just do manually testing and it seems ok to me.

Tests

Make sure you've done the following:

  • Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.
  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.
  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

@WindSoilder WindSoilder changed the title In unix like system: while running external command, set it as foreground name In unix like system, set foreground while running external command Aug 1, 2022
@WindSoilder WindSoilder changed the title In unix like system, set foreground while running external command In unix like system, set foreground process while running external command Aug 1, 2022
@fdncred

fdncred commented Aug 1, 2022

Copy link
Copy Markdown
Contributor

oh, wow! wasn't expecting this anytime soon. nice work! this may be one of those things that is ok to not in windows because I'm not positive but I don't think windows supports such a thing.

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read up on the assumptions/safety requirements of the syscalls used on different platforms, but this API hides potential unsafety behind comments. Either we can locally prove the calls are safe given rust guarantees about the std::process module and document with a safety comment, make them unsafe and document the safe use of those wrappers at the Rust call site (spaghetti code of the relevant function :/ ) or try to build a safe wrapper around that.

Comment thread crates/nu-system/src/foreground.rs Resolved
Comment thread crates/nu-system/src/foreground.rs Resolved
@WindSoilder
WindSoilder marked this pull request as draft August 1, 2022 22:12
Comment thread crates/nu-system/src/foreground.rs Resolved
@WindSoilder
WindSoilder marked this pull request as ready for review August 2, 2022 04:12
@WindSoilder
WindSoilder requested a review from sholderbach August 2, 2022 04:13

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the quick changes!

Comment thread crates/nu-system/src/foreground.rs Resolved
@WindSoilder
WindSoilder marked this pull request as draft August 2, 2022 10:15
@WindSoilder
WindSoilder marked this pull request as ready for review August 2, 2022 10:28
@sholderbach

Copy link
Copy Markdown
Member

Ah shit I forgot about the unused variable problem with cfg :D

@WindSoilder

Copy link
Copy Markdown
Contributor Author

Ah shit I forgot about the unused variable problem with cfg :D

I love clippy :-D I'll leave to other side pub(super), and investigate if we can implement something like this on Windows.

If not, the dummy implementation can be removed.

@sholderbach

Copy link
Copy Markdown
Member

There is a commonly supported ANSI sequence to set the terminal title (crossterm has a windows implementation as well https://docs.rs/crossterm/latest/crossterm/terminal/struct.SetTitle.html), that might be helpful to do it manually instead of relying on the process detection

@WindSoilder

Copy link
Copy Markdown
Contributor Author

I think terminal title is different to something mentioned in #6156 .

But setting terminal title would also be interesting, thanks for your tip :-D

@fdncred

fdncred commented Aug 2, 2022

Copy link
Copy Markdown
Contributor

@sholderbach @WindSoilder Keep in mind, if you decide to start changing the window/tab title that you are now encroaching on the shell_integration changes, which is fine, but one of these title setting things may overwrite the other. You may just want to set the process stuff for now and deal with the title in a separate PR if needbe.

@sholderbach

Copy link
Copy Markdown
Member

Right, yeah let's land this PR first.

@sholderbach
sholderbach merged commit 376d22e into nushell:main Aug 2, 2022
@rawsp33d

rawsp33d commented Aug 2, 2022

Copy link
Copy Markdown

It works; thank you @WindSoilder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make nushell set/forward/proxy currently running process like other shells

5 participants