handle exit cond, wip
This commit is contained in:
parent
74fa5cb880
commit
1cf687103f
14
app/Main.hs
14
app/Main.hs
|
@ -9,15 +9,23 @@ 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
|
||||
end <- isEOF
|
||||
if end
|
||||
then sigIntHandler sigTERM
|
||||
else do
|
||||
line <- getLine
|
||||
dispatch line
|
||||
|
||||
|
@ -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
|
|
@ -52,6 +52,7 @@ executable wnpClient
|
|||
, http-conduit
|
||||
, bytestring
|
||||
, filepath
|
||||
, signal
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite wnpClient-test
|
||||
|
|
Loading…
Reference in a new issue