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

Cursor style is overridden when exiting nushell #8452

Closed
scallaway opened this issue Mar 14, 2023 · 11 comments
Closed

Cursor style is overridden when exiting nushell #8452

scallaway opened this issue Mar 14, 2023 · 11 comments
Labels
configuration Issue related to nu's configuration line editor Issues related to reedline
Milestone

Comments

@scallaway
Copy link

Describe the bug

For all my terminals, I have the cursor set to the block-style at all times.

When I enter nushell, the default is to have the cursor in line-style.

However, when I exit nushell, the terminal continues to use the line-style for the cursor in the current session.

I have confirmed this is both the case with Kitty terminal on linux and Windows terminal (with WSL) on Windows 11.

How to reproduce

This is easiest to see when you have a tmux instance open (so you can compare).

  1. Update the config for your terminal to use block-style cursors
  2. Open a session of nushell
  3. Verify that the cursor is line-style (by default)
  4. Exit the session
  5. See that the cursor remains in the line-style

It's worth noting at this point that if you open another tmux session, then the cursor style is as you originally configured (block-style in my case).

Expected behavior

I'd expect the cursor style to not be overridden once you've exited a nushell session.

Screenshots

image

Before booting into a shell

image

inside the shell session

image

outside the session after exit

Configuration

| key                | value                                    |
| ------------------ | ---------------------------------------- |
| version            | 0.77.0                                   |
| branch             | main                                     |
| commit_hash        | fd09609b44b53d41ac7929e90708cdeba7bfb571 |
| build_os           | linux-x86_64                             |
| build_target       | x86_64-unknown-linux-gnu                 |
| rust_version       | rustc 1.66.1 (90743e729 2023-01-10)      |
| rust_channel       | 1.66.1-x86_64-unknown-linux-gnu          |
| cargo_version      | cargo 1.66.1 (ad779e08b 2023-01-10)      |
| build_time         | 2023-03-14 19:46:05 +00:00               |
| build_rust_channel | debug                                    |
| features           | default, zip                             |
| installed_plugins  |                                          |

Additional context

No response

@fdncred
Copy link
Collaborator

fdncred commented Mar 14, 2023

You can change your cursor shape in the config file like this

let-env config = {
... other stuff
    cursor_shape: {
        emacs: line # block, underscore, line (line is the default)
        vi_insert: block # block, underscore, line (block is the default)
        vi_normal: underscore # block, underscore, line  (underscore is the default)
    }
}

Also, if your terminal supports xterm sequences you can follow these rules, outside of nushell, to reset your cursor shape.

CSI Ps SP q
          Set cursor style (DECSCUSR), VT520.
            Ps = 0  ⇒  blinking block.
            Ps = 1  ⇒  blinking block (default).
            Ps = 2  ⇒  steady block.
            Ps = 3  ⇒  blinking underline.
            Ps = 4  ⇒  steady underline.
            Ps = 5  ⇒  blinking bar, xterm.
            Ps = 6  ⇒  steady bar, xterm.

So, for a steady block you'd type

echo -e "\033[2 q"

reference

@aetherplex
Copy link

Is it possible to change the default cursor to block?

@sholderbach sholderbach added line editor Issues related to reedline configuration Issue related to nu's configuration labels Mar 19, 2023
@fdncred
Copy link
Collaborator

fdncred commented Mar 20, 2023

Is it possible to change the default cursor to block?

I don't understand @aetherplex, I explained how to change it in the comment above yours. Am I misunderstanding your question?

@scallaway
Copy link
Author

@fdncred

I think what you've suggested for changing the cursor is perfectly valid, however I think I'd prefer to understand why it's changing the terminal cursor when I'm not in a nushell session.

Surely any changes that are made inside the session should be reverted when exited?

@fdncred
Copy link
Collaborator

fdncred commented Mar 21, 2023

@scallaway, my question was directed at @aetherplex.

Regarding your question about after nushell, maybe you're right. I'm not sure. Cursors are usually controlled by the terminal or the prompt. We're a few versions behind on our crossterm crate, which controls this. I'm not sure if there is a change in it or not. We also could have a bug in reedline or nushell that is causing this. It'll take a dedicated soul to try and figure that out.

It seems like your terminal is taking a passive approach, meaning that whomever changes the cursor, it will just use that. You could try the echo statement I have above to change it however you see fit. Currently, I think nushell takes the opposite approach, which is to set the cursor no matter what you change it to in the terminal and the only way to change it is to change it in the config.

@cassepipe
Copy link

cassepipe commented Mar 28, 2023

I encounter the same issue.
The terminal is not the issue here, it just obeys the commands the line editor gives it I believe.

If I remember correctly, it is considered good practice for any terminal program to store the state of terminal when it starts and restore that state it as it was before when it exits.

@fdncred
Copy link
Collaborator

fdncred commented Mar 28, 2023

The terminal is not the issue here, it just obeys the commands the line editor gives it I believe.

It can work either way but I get your point.

We'd probably accept a PR to reedline and/or nushell to help with this.

@aerique
Copy link

aerique commented Aug 31, 2023

I have something similar which may or may not have the same cause: I'm playing around with nushell, trying it out, changing some config options, launching it and exiting it again. This is all from Fish shell. In Fish my cursor is a solid block, in nushell I configured it to be a solid block as well but:

When I exit nushell to Fish my cursor is a blinking solid block so I run it like this now to reset it to a non-blinking solid block nu ; echo -en '\e[2 q'.

I do not have this issue with any other programs I launch from Fish, including my own shell I'm developing.

@mb21
Copy link

mb21 commented Sep 7, 2023

Seems crossterm has now a function to get cursor shape so nushell could use that to restore the cursor before exit?

@fdncred
Copy link
Collaborator

fdncred commented Sep 7, 2023

I don't see the function. Is it in crossterm or just in someone's fork?

fdncred pushed a commit that referenced this issue Sep 9, 2023
# Description
There are several cursor shape related issues #7151 #9243 #7271 #8452
#10169, you can't disable the cursor shape feature even if you comment
out the entire `cursor_shape` block in the config.nu, and even worse,
when nushell exits with an error, the cursor shape can't be restored,
that is annoying.

This PR provides an opportunity to disable setting the cursor shape.

# User-Facing Changes
If you use the default config.nu, nothing changes, but if you comment
out `cursor_shape` block or set them to `inherit`, related cursor shape
will not be set.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

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 -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
@fdncred
Copy link
Collaborator

fdncred commented Sep 9, 2023

closing since #10289 landed. let's open a new issue if there are still problems.

@fdncred fdncred closed this as completed Sep 9, 2023
@hustcer hustcer added this to the v0.85.0 milestone Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Issue related to nu's configuration line editor Issues related to reedline
Projects
None yet
Development

No branches or pull requests

8 participants