|Maintainer||Brent Yorgey <email@example.com>|
Format specially marked blocks as interactive ghci sessions. Uses some ugly but effective code for interacting with an external ghci process taken from lhs2TeX.
- type ProcessInfo = (Handle, Handle, Handle, ProcessHandle)
- ghciEval :: GhciInput -> ReaderT ProcessInfo IO GhciOutput
- withGhciProcess :: FilePath -> ReaderT ProcessInfo IO a -> IO a
- isLiterate :: String -> Bool
- stopGhci :: ProcessInfo -> IO ()
- magic :: String
- extract' :: Handle -> IO String
- extract :: String -> String
- breaks :: ([a] -> Bool) -> [a] -> ([a], [a])
- formatInlineGhci :: FilePath -> Pandoc -> IO Pandoc
Information about a running process: stdin, stdout, stderr, and a handle.
Evaluate an expression using an external
Start an external ghci process, run a computation with access to it, and finally stop the process.
Stop a ghci process by passing it
:q and waiting for it to exit.
To extract the answer from
ghci's output we use a simple technique
which should work in most cases: we print the string
and after the expression we are interested in. We assume that
everything that appears before the first occurrence of
magic on the
same line is the prompt, and everything between the first
magic plus prompt is the result we look for.
Given the path to the
.lhs source and its representation as a
formatInlineGhci finds any
in it, runs them through
ghci, and formats the results as an
Lines beginning in the first column of the block are interpreted as inputs. Lines indented by one or more space are interpreted as expected outputs. Consecutive indented lines are interpreted as one multi-line expected output, with a number of spaces removed from the beginning of each line equal to the number of spaces at the start of the first indented line.
If the output for a given input is the same as the expected output (or if no expected output is given), the result is typeset normally. If the actual and expected outputs differ, the actual output is typeset first in red, then the expected output in blue.