prompt: added emacs-like shortcuts

This commit is contained in:
2017-06-03 22:41:19 -04:00
parent 84a0fbe4ec
commit c7777dec03
2 changed files with 11 additions and 5 deletions

View File

@@ -17,8 +17,6 @@ We support all builtin functions, but have no IO (no `print`).
## TODO
- A good readline copy (haskeline is sadly out of the question for this project)
- Add keyboard shortcuts
- Comment parsing
- Closures that can modify the parent environment (but do away with the `local` keyword).
- Better arbitrary precision floats

View File

@@ -212,15 +212,23 @@ readline state = read' "" 0
putStr [c]
read' (take pos acc ++ [c] ++ drop pos acc) (pos+1) pstate
else
if ord c == 18 -- 18 == Ctrl+R
then do
case ord c of
1 -> -- == cursor to beginning
read' acc 0 pstate
2 -> -- == cursor left
read' acc (if pos > 0 then pos-1 else pos) pstate
5 -> -- == cursor to end
read' acc (length acc) pstate
6 -> -- == cursor right
read' acc (if pos < length acc then pos+1 else pos) pstate
18 -> do -- == Ctrl+R
mnacc <- reverseSearch pstate acc
case mnacc of
Just nacc -> do
putStr nacc
return (Just nacc)
_ -> read' acc pos pstate
else read' acc pos pstate
_ ->read' acc pos pstate
clamp n min max
| n < min = min
| n > max = max