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.HTTP.Simple
|
||||||
import Network.URI
|
import Network.URI
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
import System.Exit
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import System.Signal
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
setLocaleEncoding utf8
|
setLocaleEncoding utf8
|
||||||
createDirectoryIfMissing False =<< workingDir
|
createDirectoryIfMissing False =<< workingDir
|
||||||
join $ (writeFile <$> fileName) <*> pure ""
|
join $ (writeFile <$> fileName) <*> pure ""
|
||||||
|
installHandler sigINT sigIntHandler
|
||||||
|
installHandler sigTERM sigIntHandler
|
||||||
forever $ do
|
forever $ do
|
||||||
line <- getLine
|
end <- isEOF
|
||||||
dispatch line
|
if end
|
||||||
|
then sigIntHandler sigTERM
|
||||||
|
else do
|
||||||
|
line <- getLine
|
||||||
|
dispatch line
|
||||||
|
|
||||||
dispatch :: String -> IO ()
|
dispatch :: String -> IO ()
|
||||||
dispatch ('T' : 'I' : 'T' : 'L' : 'E' : ':' : title) = writeToFile title 0
|
dispatch ('T' : 'I' : 'T' : 'L' : 'E' : ':' : title) = writeToFile title 0
|
||||||
|
@ -64,4 +72,10 @@ coverName :: IO FilePath
|
||||||
coverName = (</> "cover.jpg") <$> workingDir
|
coverName = (</> "cover.jpg") <$> workingDir
|
||||||
|
|
||||||
workingDir :: IO FilePath
|
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
|
, http-conduit
|
||||||
, bytestring
|
, bytestring
|
||||||
, filepath
|
, filepath
|
||||||
|
, signal
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
test-suite wnpClient-test
|
test-suite wnpClient-test
|
||||||
|
|
Loading…
Reference in a new issue