handle exit cond, wip

This commit is contained in:
qvalentin 2021-06-27 12:03:52 +02:00
parent 74fa5cb880
commit 1cf687103f
2 changed files with 18 additions and 3 deletions

View File

@ -9,17 +9,25 @@ import Network.HTTP.Client
import Network.HTTP.Simple
import Network.URI
import System.Directory
import System.Exit
import System.FilePath
import System.IO
import System.Signal
main :: IO ()
main = do
setLocaleEncoding utf8
createDirectoryIfMissing False =<< workingDir
join $ (writeFile <$> fileName) <*> pure ""
installHandler sigINT sigIntHandler
installHandler sigTERM sigIntHandler
forever $ do
line <- getLine
dispatch line
end <- isEOF
if end
then sigIntHandler sigTERM
else do
line <- getLine
dispatch line
dispatch :: String -> IO ()
dispatch ('T' : 'I' : 'T' : 'L' : 'E' : ':' : title) = writeToFile title 0
@ -65,3 +73,9 @@ coverName = (</> "cover.jpg") <$> workingDir
workingDir :: IO FilePath
workingDir = (</> ".wnpClient") <$> getHomeDirectory
sigIntHandler :: System.Signal.Handler
sigIntHandler _ = do
join $ (writeFile <$> fileName) <*> pure ""
hPutStrLn stderr ("Handle exit")
exitSuccess

View File

@ -52,6 +52,7 @@ executable wnpClient
, http-conduit
, bytestring
, filepath
, signal
default-language: Haskell2010
test-suite wnpClient-test