-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.hs
54 lines (46 loc) · 1.45 KB
/
Menu.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Menu (
showMenu,
checkFile
) where
import Algorithm
import System.IO
showMenu :: IO ()
showMenu = do
putStrLn "1 - Check set of words in terminal"
putStrLn "2 - Check set of words written in file"
anwser <- getLine
case anwser of
"1" -> checkInTerminal
"2" -> checkFileMenu
otherwise -> do
putStrLn $ "What?\n"
showMenu
checkInTerminal :: IO ()
checkInTerminal = do
putStrLn "Write down words of code in separate lines"
putStrLn "Finish reading set of words by writing \".\""
words <- getListUntil "." []
showResult (Algorithm.isListCode words)
getListUntil :: String -> [String] -> IO [String]
getListUntil end list = do
line <- getLine
if line == end
then return $ reverse list
else getListUntil end (line:list)
checkFileMenu :: IO ()
checkFileMenu = do
putStrLn "Write path to the file"
path <- getLine
checkFile path
checkFile :: FilePath -> IO ()
checkFile path = do
fileRaw <- readFile path
(showResult.(Algorithm.isListCode).splitLines) fileRaw
where
split on = foldl (\(y:ys) x -> if (on x) then ([]:(y:ys)) else ((y ++ [x]):ys)) [[]]
splitLines = reverse.(\x -> if (head x) == [] then (tail x) else x).(split (== '\n'))
showResult :: Bool -> IO ()
showResult result = do
case result of
True -> putStrLn "This set of words can be code."
False -> putStrLn "This set of words CANNOT be code."