elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.75k stars 303 forks source link

Programmable status text #551

Open notramo opened 6 years ago

notramo commented 6 years ago

A readline built-in „notification” system would be cool. This would draw a line over the prompt line, similarly as it does when the user press an unbound key combination, or reaches end of history, but instead printing the next notification in a new line, the new notification would overwrite the old (so it would remain in the same line).

When the user hits Enter, the notification line would be deleted (similarly as the right prompt), and the left prompt would move a line up (into the place of the notification) before running the command.

Markup would be cool for highlighting some parts of the notification.

Use case: implementing a lot of powerful stuff.

The git status, and the long running command notification can be done simply with an echo, without using the readline, but if these informations are not enough important for somebody to make it persistent. So the user reads it, then it will be deleted by the autocompletion after starting typing a command.

Since the autocompletion, and the „next argument type” completion depends on the current readline buffer, and changes along with it, these could benefit from this feature.

It could be more powerful if it maintain a stack of notifications in memory. The notification command would return an unique id, then the notification can be deleted later. Example:

notification_id = (edit:notify "Shift-Enter to run: <bold>git add dirhistfilter.elv; git diff --cached</bold>")
sleep 1.5
edit:delete-notification $notification_id

So after 1.5 second, the previous notification would be visible again.

zzamboni commented 6 years ago

This might be cool, although I would suggest the notifications to appear below the prompt line, like when you enter a syntax error.

elvish____emacs_d
xiaq commented 2 years ago

I would like to make a distinction between notifications and status texts.

Since notifications are already supported and the original description maps more into the status text category, I am going to reword this issue to reflect that.

xiaq commented 2 years ago

The easiest way to support this is adding another "below prompt" that appears below the buffer - like how rprompt appears to the right.

This way I can also outsource the business of maintaining which lines should appear - the editor itself just needs to know when to call the "below prompt", and the prompt callback is responsible for deciding which lines to show.