simple repl
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
bin/
|
||||
dist/
|
||||
|
5
bc.cabal
5
bc.cabal
@@ -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
|
||||
|
@@ -1,5 +1,7 @@
|
||||
module Bc.Prompt where
|
||||
module BC.Config where
|
||||
|
||||
versionStr = "0.1.0.0"
|
||||
|
||||
prompt = "> "
|
||||
promptStr = "> "
|
||||
|
||||
returnStr = "=> "
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user