aboutsummaryrefslogtreecommitdiff
path: root/src/Ghci.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-01-06 21:28:36 +0100
committerTom Smeding <tom@tomsmeding.com>2025-01-06 21:28:36 +0100
commitdb075620db9e9da77276f0999b9cb09502920ab3 (patch)
tree45ee55447617442605d5a1f96d38d5c372cbc058 /src/Ghci.hs
parente5ef33adc831b0176f39b81ca8913108ef9c30fe (diff)
Add :version command
Diffstat (limited to 'src/Ghci.hs')
-rw-r--r--src/Ghci.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Ghci.hs b/src/Ghci.hs
index d16d2a0..ae3bac9 100644
--- a/src/Ghci.hs
+++ b/src/Ghci.hs
@@ -26,7 +26,7 @@ import qualified Data.ByteString.Short as BSS
import Data.Char (isSpace, toLower)
import Data.List (nub)
import Foreign (allocaBytes)
-import System.IO (hFlush, hIsClosed, hGetBufSome, hPutStrLn, stdout, stderr, Handle)
+import System.IO (hFlush, hIsClosed, hGetBufSome, hGetLine, hPutStrLn, stdout, stderr, Handle)
import System.Process
import System.Random (getStdRandom, uniformR)
import System.Timeout (timeout, Timeout)
@@ -47,6 +47,7 @@ data Ghci = Ghci
{ ghciProc :: ProcessHandle
, ghciStdin :: Handle
, ghciStdout :: Handle
+ , ghciVersion :: String
}
data ParseSettings = ParseSettings
@@ -73,13 +74,22 @@ makeGhci = do
, std_in = CreatePipe
, std_out = UseHandle pipeIn
, std_err = UseHandle pipeIn }
+
+ versionLine <- hGetLine pipeOut
+ let version
+ | take 19 versionLine == "yahb2-ghci-version=" =
+ takeWhile (not . isSpace) (drop 19 versionLine)
+ | otherwise =
+ "<unknown, sorry>"
+
ghciPutStrLn stdinH ":set -interactive-print=Yahb2Defs.limitedPrint"
ghciPutStrLn stdinH ":m"
ghciPutStrLn stdinH ":script initdefs.hs"
hFlush stdinH
return Ghci { ghciProc = proch
, ghciStdin = stdinH
- , ghciStdout = pipeOut }
+ , ghciStdout = pipeOut
+ , ghciVersion = version }
runStmtClever :: Ghci -> ParseSettings -> String -> IO (Ghci, Result String)
runStmtClever ghci pset line =
@@ -96,6 +106,10 @@ runStmtClever ghci pset line =
hFlush stdout
ghci' <- makeGhci
return (ghci', Exited)
+ | cmd == "version" ->
+ -- no startsWith because :version is not a ghci command, and we
+ -- don't want to shadow other actual ghci commands
+ return (ghci, Return (ghciVersion ghci))
_ -> runStmt ghci pset line
_ -> runStmt ghci pset line
where