Skip to content

restore cursor shape when exits - #9314

Merged
fdncred merged 1 commit into
nushell:mainfrom
nibon7:cursor_shape
May 30, 2023
Merged

fdncred merged 1 commit into
nushell:mainfrom
nibon7:cursor_shape

Conversation

@nibon7

@nibon7 nibon7 commented May 29, 2023

Copy link
Copy Markdown
Contributor

Description

This PR restores cursor shape when nushell exists.

Fixes #9243

Related nushell/reedline#574

User-Facing Changes

  • windows
windows_ps.mp4
  • linux
linux_alacritty.mp4
  • macos
mac_iterm2.mp4

Tests + Formatting

After Submitting

@fdncred

fdncred commented May 29, 2023

Copy link
Copy Markdown
Contributor

Seems reasonable. I'm guessing from the code that the drop(line_editor) is what is resetting the cursor? What happens on panic? What happens with parameters like -c?

@nibon7

nibon7 commented May 30, 2023

Copy link
Copy Markdown
Contributor Author

I'm guessing from the code that the drop(line_editor) is what is resetting the cursor?

Yeah, when the reedline object is destructed, cursor shape will be reset.

What happens on panic?

When a panic occurs, stack unwinding is triggered. During the stack unwinding process, the destructor functions of objects that implement the Drop trait will be called.

If the reedline object still exists on the stack when a panic occurs, the destructor will be executed and the cursor shape will be reset.
Screenshot from 2023-05-30 08-57-49

If you set "panic=abort" in Cargo.toml, when a panic occurs, nushell will immediately abort rather than perform any further cleanup, and the cursor shape will not be reset.

Screenshot from 2023-05-30 10-31-42

What happens with parameters like -c?

This change has nothing to do with it as nu -c invokes evaluate_commands which doesn't create a Reedline instance and the cursor never changed.

PS: nu /path/to/script.nu doesn't create a Reedline instance too.

@fdncred

fdncred commented May 30, 2023

Copy link
Copy Markdown
Contributor

Ok, thanks for the hard work and research @nibon7. Let's give this a try.

@fdncred
fdncred merged commit 560c2e6 into nushell:main May 30, 2023
@nibon7
nibon7 deleted the cursor_shape branch May 31, 2023 00:05
@Tyarel8 Tyarel8 mentioned this pull request Jun 10, 2026
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.

Cursor style is changed after exit

2 participants