| 1 | | Documentation is TODO. |
| | 1 | = Custom Key Bindings = |
| | 2 | |
| | 3 | As of version 0.4.1, the user may specify custom key bindings in their `.haskeline` file. The two new settings are: |
| | 4 | - {{{keyseq: <string> <key>}}} (POSIX-only: add a new key sequence) |
| | 5 | - {{{bind: <key> <key>}}} (bind the first key to the actions of the second key) |
| | 6 | |
| | 7 | where {{{<string>}}} is a Haskell string and {{{<key>}}} is either: |
| | 8 | - a single character |
| | 9 | - `f<n>` (a function key) |
| | 10 | - `left, right, down, up` |
| | 11 | - `backspace, delete, home, end, killline` |
| | 12 | - `return, tab, escape` |
| | 13 | - `ctrl-<key>`, `shift-<key>`, `meta-<key>` |
| | 14 | |
| | 15 | Note that the `meta-` key is `ALT` on Windows. |
| | 16 | |
| | 17 | These features are pretty new, so feedback and suggestions are encouraged. |
| | 18 | |
| | 19 | == Examples == |
| | 20 | |
| | 21 | The following lines will cause the backspace key to move one character to the left nondestructively, and meta-backspace to delete the character to the left of the cursor: |
| | 22 | {{{ |
| | 23 | bind: backspace left |
| | 24 | bind: meta-backspace backspace |
| | 25 | }}} |
| | 26 | |
| | 27 | |
| | 28 | === Control-left/right === |
| | 29 | |
| | 30 | The following instructions will make `ctrl-left` and `ctrl-right` skip words. |
| | 31 | |
| | 32 | First, we check `KeyBindings` to see that `M-B` and `M-F` are bound by default to the commands we want. So the necessary `bind` commands are: |
| | 33 | {{{ |
| | 34 | bind: ctrl-left meta-b |
| | 35 | bind: ctrl-right meta-f |
| | 36 | }}} |
| | 37 | |
| | 38 | That's sufficient on Windows, but for POSIX systems a couple more steps are needed. Normally Haskeline looks up a key sequence in the system `terminfo` database; however `ctrl-left` and `ctrl-right` don't have a standard capability name, so Haskeline needs to be told manually what their key sequence is. |
| | 39 | |
| | 40 | To find out their control sequences, you can do something like: |
| | 41 | {{{ |
| | 42 | $ ghc -e getLine |
| | 43 | <press ctrl-left, then return>^[[5D |
| | 44 | "\ESC[5D" |
| | 45 | $ ghc -e getLine |
| | 46 | <press ctrl-right, then return>^[[5C |
| | 47 | "\ESC[5C" |
| | 48 | }}} |
| | 49 | |
| | 50 | Thus we add the following lines (which will be ignored on Windows): |
| | 51 | {{{ |
| | 52 | keyseq: "\ESC[5D" ctrl-left |
| | 53 | keyseq: "\ESC[5C" ctrl-right |
| | 54 | }}} |
| | 55 | |