Permalink
Browse files

get some readline love

  • Loading branch information...
Patrick Thomson
Patrick Thomson committed Apr 24, 2012
1 parent 418fc2a commit a008d012646e62e8f3746bd53d4210b90561d2f2
Showing with 16 additions and 12 deletions.
  1. +1 −0 hs-dcpu.cabal
  2. +15 −12 src/Main.hs
View
@@ -25,6 +25,7 @@ Executable hdasm
mtl >= 2,
parsec >= 3.1,
pretty == 1.0.1.2,
+ readline == 1.0.1.0,
QuickCheck >= 2.3,
test-framework >= 0.6,
test-framework-quickcheck2 >= 0.2.7
View
@@ -4,24 +4,27 @@ module Main where
import Assembler
import Parser
import Pretty
+ import Data.Maybe
+ import System.Console.Readline
import Text.Parsec (parseTest)
main :: IO ()
main = do
- putStrLn "hs-dcpu started in interactive mode. Ctrl-C exits."
+ putStrLn "hs-dcpu started in interactive mode. Ctrl-D exits."
inputLoop
where
inputLoop :: IO ()
inputLoop = do
- putStr ">>> "
- prog <- getLine
- let e = parse program "" (pack prog)
- case e of
- (Left err) -> print err
- (Right pro) -> do
- print pro
- let asm = doAssembly pro
- print $ pretty <$> asm
-
- inputLoop
+ p <- readline ">>> "
+ case p of
+ Nothing -> return ()
+ Just prog -> do
+ let e = parse program "" (pack prog)
+ case e of
+ (Left err) -> print err
+ (Right pro) -> do
+ print pro
+ let asm = doAssembly pro
+ print $ pretty <$> asm
+ inputLoop

0 comments on commit a008d01

Please sign in to comment.