summaryrefslogtreecommitdiff
path: root/rmtodo.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-08-09 10:58:03 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-08-09 10:58:03 +0800
commit5bdaa1e4ffe40add10f000ee993e6b500c419a37 (patch)
tree46a624488ece8d37fa3580422234ed2b4acc6728 /rmtodo.hs
parent01aa73b269f7ad780233be338affdf3c9288b1ed (diff)
downloadhaskbox-old-5bdaa1e4ffe40add10f000ee993e6b500c419a37.tar.gz
haskbox-old-5bdaa1e4ffe40add10f000ee993e6b500c419a37.tar.bz2
haskbox-old-5bdaa1e4ffe40add10f000ee993e6b500c419a37.zip
add files from home for previous chapters and sandboxes
Diffstat (limited to 'rmtodo.hs')
-rw-r--r--rmtodo.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/rmtodo.hs b/rmtodo.hs
new file mode 100644
index 0000000..2507d86
--- /dev/null
+++ b/rmtodo.hs
@@ -0,0 +1,21 @@
+import System.IO
+import System.Directory
+import Data.List
+
+main = do
+ handle <- openFile "todo.txt" ReadMode
+ (tempName, tempHandle) <- openTempFile "." "temp"
+ contents <- hGetContents handle
+ let todoTasks = lines contents
+ numberedTasks = zipWith (\n line -> show n ++ " - " ++ line) [0..] todoTasks
+ putStrLn "These are your TO-DO items:"
+ putStr $ unlines numberedTasks
+ putStrLn "Which one do you want to delete?"
+ numberString <- getLine
+ let number = read numberString
+ newTodoItems = delete (todoTasks !! number) todoTasks
+ hPutStr tempHandle $ unlines newTodoItems
+ hClose handle
+ hClose tempHandle
+ removeFile "todo.txt"
+ renameFile tempName "todo.txt"