simple repl

This commit is contained in:
2017-04-28 11:54:10 +02:00
parent 639a513ad4
commit a36bab384d
4 changed files with 34 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1 +1 @@
bin/
dist/

View File

@@ -6,7 +6,6 @@ license: MIT
license-file: LICENSE
author: Veit Heller
maintainer: veit@veitheller.de
copyright:
category: Language
build-type: Simple
extra-source-files: ChangeLog.md, README.md
@@ -14,7 +13,7 @@ cabal-version: >=1.10
executable bc
main-is: Main.hs
other-modules:
build-depends: base >=4.9 && <4.10
hs-source-dirs: src/
build-depends: base >=4.9 && <4.10, haskeline, unix
hs-source-dirs: src
default-language: Haskell2010

View File

@@ -1,5 +1,7 @@
module Bc.Prompt where
module BC.Config where
versionStr = "0.1.0.0"
prompt = "> "
promptStr = "> "
returnStr = "=> "

View File

@@ -1,24 +1,45 @@
module BC.Prompt (startPrompt) where
import System.Console.Haskeline
import System.Posix.Signals
import BC.Config
printHeader :: IO ()
printHeader = do
putStrLn "bc (better calculator) version " ++ versionStr
putStrLn $ "bc (better calculator) version " ++ versionStr
putStrLn "Copyright 2017 Veit Heller"
putStrLn "This is free software with ABSOLUTELY NO WARRANTY.\n"
output :: [Char] -> InputT IO ()
output out = outputStrLn $ returnStr ++ out
prompt :: IO ()
prompt = runInputT settings $ poll prompt
prompt = runInputT defaultSettings $ poll promptStr
where poll p = do
input <- getInputLine p
case input of
Nothing -> return ""
Just str -> return str
input <- getInputLine p
case input of
Nothing -> do
output "Bye!"
return ()
Just "quit" -> do
output "Bye!"
return ()
Just str -> do
output str
poll p
installHandlers :: IO ()
installHandlers = do
installHandler keyboardSignal (Catch (putStrLn "\n(interrupt) type quit to exit")) Nothing
return ()
startPrompt :: IO ()
startPrompt = do
printHeader
installHandlers
prompt