Browse code
More reorganization and clarification
fiddlerwoaroof authored on 27/09/2015 17:24:15
Showing 3 changed files
Showing 3 changed files
... | ... |
@@ -25,11 +25,12 @@ a = runST $ do |
25 | 25 |
|
26 | 26 |
mvWAddStr2 :: HSCurses.Window -> Int -> Int -> String -> IO () |
27 | 27 |
mvWAddStr2 w y x s = do |
28 |
- (rows, cols) <- HSCurses.scrSize |
|
29 |
- when ((y >= 0) && (x >=0) && (x < cols) && (y < rows)) $ do |
|
28 |
+ (rows, cols) <- HSCurses.scrSize |
|
29 |
+ when ((y >= 0) && (x >= 0) && (x < cols) && (y < rows)) $ |
|
30 | 30 |
let space = cols - x |
31 |
- let s2 = take space s |
|
32 |
- HSCurses.mvWAddStr w y x s2 |
|
31 |
+ s2 = take space s |
|
32 |
+ in |
|
33 |
+ HSCurses.mvWAddStr w y x s2 |
|
33 | 34 |
|
34 | 35 |
dispatch :: HSCurses.Key -> IO () |
35 | 36 |
dispatch _ = return () |
... | ... |
@@ -38,12 +39,9 @@ mainLoop :: Int -> Handle -> Int -> Bool -> IO () |
38 | 39 |
mainLoop lim filein cols infinitep = do |
39 | 40 |
n <- stToIO $ newSTRef 1 |
40 | 41 |
when True $ forever $ do |
41 |
- let getX = stToIO $ readSTRef n |
|
42 |
- x <- getX |
|
43 |
- stToIO $ writeSTRef n (x+1) |
|
44 |
- nextX <- getX |
|
45 |
- let handleInputp = not infinitep && ( nextX `mod` lim == 0) |
|
42 |
+ (x,nextX) <- initialize n |
|
46 | 43 |
|
44 |
+ let handleInputp = not infinitep && ( nextX `mod` lim == 0) |
|
47 | 45 |
eofp <- atEnd |
48 | 46 |
if eofp then threadDelay 100 |
49 | 47 |
else do |
... | ... |
@@ -52,6 +50,13 @@ mainLoop lim filein cols infinitep = do |
52 | 50 |
|
53 | 51 |
HSCurses.refresh |
54 | 52 |
where |
53 |
+ initialize n = do |
|
54 |
+ let getX = stToIO $ readSTRef n |
|
55 |
+ x <- getX |
|
56 |
+ stToIO $ writeSTRef n (x+1) |
|
57 |
+ nextX <- getX |
|
58 |
+ return (x,nextX) |
|
59 |
+ |
|
55 | 60 |
atEnd = hIsEOF filein |
56 | 61 |
getLineFromFile = hGetLine filein |
57 | 62 |
showDivider x lim = |