handle exit cond, wip
This commit is contained in:
parent
74fa5cb880
commit
1cf687103f
20
app/Main.hs
20
app/Main.hs
|
@ -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
|
||||
|
@ -64,4 +72,10 @@ coverName :: IO FilePath
|
|||
coverName = (</> "cover.jpg") <$> workingDir
|
||||
|
||||
workingDir :: IO FilePath
|
||||
workingDir = (</> ".wnpClient") <$> getHomeDirectory
|
||||
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 New Issue