CLI interface + restructuration + precision fixes Fermat Factorization
This commit is contained in:
25
app/Utils.hs
Normal file
25
app/Utils.hs
Normal file
@@ -0,0 +1,25 @@
|
||||
module Utils (askNumber, askChoice) where
|
||||
|
||||
import Text.Read (readMaybe)
|
||||
import System.Exit (exitSuccess)
|
||||
|
||||
-- Ask user for an integer > 1, or exit on invalid input
|
||||
askNumber :: String -> IO Integer
|
||||
askNumber s = do
|
||||
putStrLn s
|
||||
input <- getLine
|
||||
case readMaybe input of
|
||||
Just n | n > 1 -> return n
|
||||
_ -> do
|
||||
putStrLn "Not a valid integer"
|
||||
exitSuccess
|
||||
|
||||
askChoice :: Int -> IO Int
|
||||
askChoice maxChoice = do
|
||||
putStrLn "Enter your choice:"
|
||||
input <- getLine
|
||||
case readMaybe input of
|
||||
Just n | n >= 1 && n <= maxChoice -> return n
|
||||
_ -> do
|
||||
putStrLn "Invalid choice"
|
||||
exitSuccess
|
||||
Reference in New Issue
Block a user