-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.hs
28 lines (26 loc) · 1.1 KB
/
Display.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Display(displayAsCell, renderMachine) where
import Tape
import Machine
import Data.List
import Control.Concurrent
import System.Process
displayAsCell :: Int -> [String] -> String
displayAsCell spaces l@(x:xs) =top ++ "\n" ++(replicate spaces ' ') ++ middle ++ "\n" ++ bottom
where middle = "| "++ (Data.List.foldl (++) "" (intersperse " | " l)) ++ " |" ++ " ..."
top = (replicate spaces ' ') ++ replicate (length middle) '-'
bottom = top
renderMachine :: Float -> Machine -> IO ()
renderMachine fps (Machine _ _ _ _ _ tp headPos currst) = let
numspaces | headPos <=5 = 20 - headPos*4
| otherwise = 0
cellElems = Prelude.map cell_value $ tape_cells tp
displayElems | headPos <=5 = take 15 cellElems
| otherwise = take 15 $ drop (headPos-5) cellElems
delay = ceiling (1000000 / fps)
in
do
threadDelay delay
system "clear"
putStrLn $ displayAsCell numspaces displayElems
putStrLn $ (replicate 20 ' ')++ " ^"
putStrLn $ displayAsCell 19 ["STATE: "++ (\(State x) -> x) currst]