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

Expose LE_CURRENT_MODE to user #67

Open
user18130814200115-2 opened this issue Sep 28, 2024 · 2 comments
Open

Expose LE_CURRENT_MODE to user #67

user18130814200115-2 opened this issue Sep 28, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@user18130814200115-2
Copy link

When using yash, I am sometimes confused as to which mode I am in, specifailly vi-command or vi-insert. I would like to put this info in my prompt, though there seems to be no way to expose this to the end user.

I have done some digging through the code, and the LE_CURRENT_MODE variable seems to keep track of this, though it is not exported to the shell.

Would it be possible to export this variable for use in prompts and such?

Thanks, and keep up the great work

@user18130814200115-2 user18130814200115-2 added the enhancement New feature or request label Sep 28, 2024
@magicant
Copy link
Owner

Thanks for the suggestion.
Currently the prompt is only evaluated when starting a new line, so something like YASH_PS1='$LE_CURRENT_MODE \$ ' would not work even if the variable was exposed.

Possible solutions and alternatives:

  • Reevaluate the prompt string after every key input
    • I'm not very in favor of this because it would increase redraws of the edited line and slow things down.
  • Reevaluate the prompt string after mode changes
    • Possible compromise to reduce the redraw overhead
  • Show something like Vim's status line
    • Seemingly the easiest option for the user to enable, compared to the other alternatives that would require more complicated configurations
  • Change the cursor shape depending on the mode
    • Cursor shapes are not supported by all terminals. Need to figure out a safe way to detect if the terminal support is available?

@user18130814200115-2
Copy link
Author

I see the problem more clearly now, and I agree with you that re-drawing the prompt on every keypress is not a great way of handling this.

If it were possible to re-draw the prompt on mode change, set a prompt per mode, or have a redraw-prompt action which we might map alongside the mode switch. That would be great from a user's point of view (in my option), though it seems like a rather big change from the developer's point of view.


However, the cursor shape is also a great option, and perhaps more directly actionable.

One way to check if a given terminal supports cursor shape modification is DECRQSS. If the terminal in question supports DECRQSS, then \033P$q q\033\\ would return ^[P1$r followed by the escape sequence to do so.

There may however be terminals which do implement cursor changing through CSIs, while not supporting DECRQSS. In this case we might be able to query terminfo, csr, cnorm, and cinvis instead. That being said, Xterm has supported DECRQSS since 1996, and DECRQSS cursor change since 2012, so I think we should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants