removed haskeline extension

This commit is contained in:
2017-04-28 12:58:11 +02:00
parent a36bab384d
commit 71983ddf3e
2 changed files with 40 additions and 25 deletions

View File

@@ -14,6 +14,6 @@ cabal-version: >=1.10
executable bc
main-is: Main.hs
hs-source-dirs: src/
build-depends: base >=4.9 && <4.10, haskeline, unix
build-depends: base >=4.9 && <4.10, unix
hs-source-dirs: src
default-language: Haskell2010

View File

@@ -1,6 +1,7 @@
module BC.Prompt (startPrompt) where
import System.Console.Haskeline
import Data.Char
import System.IO
import System.Posix.Signals
import BC.Config
@@ -12,14 +13,26 @@ printHeader = do
putStrLn "This is free software with ABSOLUTELY NO WARRANTY.\n"
output :: [Char] -> InputT IO ()
output out = outputStrLn $ returnStr ++ out
output :: String -> IO ()
output out = putStrLn $ returnStr ++ out
readline :: IO (Maybe String)
readline = do
putStr promptStr
hFlush stdout
read' ""
where read' acc = do
c <- getChar
case c of
'\EOT' -> return Nothing
'\n' -> return (Just acc)
c -> read' (acc ++ [c])
prompt :: IO ()
prompt = runInputT defaultSettings $ poll promptStr
where poll p = do
input <- getInputLine p
prompt = do
input <- readline
case input of
Nothing -> do
output "Bye!"
@@ -29,12 +42,14 @@ prompt = runInputT defaultSettings $ poll promptStr
return ()
Just str -> do
output str
poll p
prompt
installHandlers :: IO ()
installHandlers = do
installHandler keyboardSignal (Catch (putStrLn "\n(interrupt) type quit to exit")) Nothing
hSetBuffering stdout NoBuffering
hSetBuffering stdin NoBuffering
return ()