This project provides a high-level line-editing API via FFI bindings to the Editline library. It aims to implement basic readline functionality in Idris. Perhaps the name editline-idris would be suitable if the API was a bit more complete. :stuck_out_tongue:
To use this library, first build and install Editline.
Install the package using:
idris --install baseline-idris.ipkg
examples/Basic.idr:
module Main
import Baseline
loop : IO ()
loop = do
str <- baseline "$> "
case str of
Nothing => putStrLn "Exit!"
Just "" => loop
Just s => do
putStrLn ("You typed: " ++ s)
loop
main : IO ()
main = do
addDictEntries
[ "multidiscipline"
, "multivitamin"
, "multiplex"
, "monocrystalline"
, "streamline"
, "waterline"
, "skyline"
, "online"
, "byline" ]
loopexamples/Effect.idr:
module Main
import Effect.Baseline
import Effect.StdIO
import Effects
import Baseline
program : Eff () [BASELINE, STDIO]
program = do
readHistory ".history"
addDictEntries
[ "multidiscipline"
, "multivitamin"
, "multiplex"
, "monocrystalline"
, "streamline"
, "waterline"
, "skyline"
, "online"
, "byline" ]
loop
writeHistory ".history"
putStrLn "Exit!"
where
loop : Eff () [BASELINE, STDIO]
loop = case !(baseline "$> ") of
Just "" => loop
Just s => do
putStrLn ("You typed: " ++ s)
loop
otherwise => pure ()
main : IO ()
main = run programSee examples/History.idr or above snippet. 👆
Run the readline prompt and save input to history.
Add an entry to tab completion dictionary.
Add multiple entries to tab completion dictionary.
Recover saved history from file.
Save history to file.
*) Use import Effect.Baseline.
- Ability to take callback for custom tab completion (requires FFI support)
- Implement more of Editline's API
- Readline-like reverse search