|
20 | 20 | {-# OPTIONS_GHC -Wno-unused-matches #-} |
21 | 21 | {-# OPTIONS_GHC -Wno-unused-imports #-} |
22 | 22 |
|
23 | | -module Repl where |
| 23 | +module Repl |
| 24 | + ( main |
| 25 | + , main' |
| 26 | + ) where |
24 | 27 |
|
25 | 28 | import Nix hiding ( exec |
26 | 29 | , try |
@@ -60,9 +63,15 @@ import System.Console.Repline ( Cmd |
60 | 63 | import qualified System.Console.Repline |
61 | 64 | import qualified System.Exit |
62 | 65 |
|
| 66 | +-- | Repl entry point |
| 67 | +main :: (MonadNix e t f m, MonadIO m, MonadMask m) => m () |
| 68 | +main = main' Nothing |
63 | 69 |
|
64 | | -main :: (MonadNix e t f m, MonadIO m, MonadMask m) => m () |
65 | | -main = flip evalStateT initState |
| 70 | +-- | Principled version allowing to pass initial value for context. |
| 71 | +-- |
| 72 | +-- Passed value is stored in context with "input" key. |
| 73 | +main' :: (MonadNix e t f m, MonadIO m, MonadMask m) => Maybe (NValue t f m) -> m () |
| 74 | +main' iniVal = flip evalStateT (initState iniVal) |
66 | 75 | $ System.Console.Repline.evalRepl |
67 | 76 | banner |
68 | 77 | cmd |
@@ -96,8 +105,12 @@ data IState t f m = IState |
96 | 105 | , replDbg :: Bool -- ^ Enable REPL debug output, dumping IState on each command |
97 | 106 | } deriving (Eq, Show) |
98 | 107 |
|
99 | | -initState :: MonadIO m => IState t f m |
100 | | -initState = IState Nothing mempty False |
| 108 | +initState :: MonadIO m => Maybe (NValue t f m) -> IState t f m |
| 109 | +initState mIni = |
| 110 | + IState |
| 111 | + Nothing |
| 112 | + (maybe mempty (\x -> Data.HashMap.Lazy.fromList [("input", x)]) mIni) |
| 113 | + False |
101 | 114 |
|
102 | 115 | type Repl e t f m = HaskelineT (StateT (IState t f m) m) |
103 | 116 |
|
|
0 commit comments