unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

home and end keys should work in ucm #3418

Open stew opened 2 years ago

stew commented 2 years ago

we had a user asking how to get their and keys doing expected things at the ucm prompt.

By following this page I was able to get these working by putting the following in my ~/.haskeline:

keyseq: "\ESC[H" home
keyseq: "\ESC[F" end

This accomplishes the desired behaviour, but we should set this up for users by default.

@ChrisPenner says:

If anyone wants an easy contribution I think you just need to convert this to runInputTWithPrefs and pass the appropriate Prefs value:

Main.hs lines 60-62

  Line.runInputT
    settings
    (haskelineCtrlCHandling go)
ceedubs commented 2 years ago

convert this to runInputTWithPrefs and pass the appropriate Prefs value

What would the appropriate Prefs value be? It wouldn't override the settings that I have in my ~/.haskeline file, would it? Don't you take my historyDuplicates: IgnoreAll or editMode: Vi from me! 😛. But seriously though.

develop7 commented 2 years ago

If anyone wants an easy contribution I think you just need to convert this to runInputTWithPrefs and pass the appropriate Prefs value:

You can't build this Prefs value programmatically though because Haskeline's Prefs is not an exported module and not only Prefs is not reexported, which results in the only way to build a Prefs value you need is to readPrefs :: FilePath -> IO Prefs (sic!).

What would the appropriate Prefs value be?

It's the one returned from readPrefs <path_of_the_file_with_these_lines>

It wouldn't override the settings that I have in my ~/.haskeline file, would it?

It seems it would, because https://github.com/judah/haskeline/blob/30aafaf7171ba1f42236eea1d69a3c60af99284d/System/Console/Haskeline/InputT.hs#L175 doesn't fall back to readPrefsFromHome, unless we have appended our custom prefs to the existing user's ~/.haskeline content.

To sum this up: in order to get custom prefs taking into account user's custom prefs we need to create a (temporary?) plaintext prefs file, copy ~/.haskeline content there, add Home & End bindings and supply a path to this file to readPrefs.

IMO this issue should be resolved by reporting appropriate issues against haskeline. Thoughts?

ChrisPenner commented 2 years ago

To sum this up: in order to get custom prefs taking into account user's custom prefs we need to create a (temporary?) plaintext prefs file, copy ~/.haskeline content there, add Home & End bindings and supply a path to this file to readPrefs.

Hrmm, yeah that's definitely regrettable.

IMO this issue should be resolved by reporting appropriate issues against haskeline. Thoughts?

Agreed, it does seem like we should be able to set reasonable defaults for our own application.

develop7 commented 2 years ago

Agreed, it does seem like we should be able to set reasonable defaults for our own application.

It's true in general, but IMO this particular issue is out of scope of UCM: the Home & End moving caret to the begin and end of the current line respectively is a default behavior of readline (just checked it by running rltest.c of readlines examples), and therefore haskeline should act same way.

in fact this issue is a exact duplicate of https://github.com/judah/haskeline/issues/30 which is closed at the moment but it apparently shouldn't