packages feed

slate 0.10.0.0 → 0.11.0.0

raw patch · 3 files changed

+57/−10 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.md view
@@ -18,6 +18,8 @@  ## Install +You can either download a release from [here](https://github.com/evuez/slate/releases) or install it using [stack](https://docs.haskellstack.org/) (requires stack >= 1.6).+ ```shell $ stack install slate ```@@ -26,7 +28,6 @@  <pre> $ slate --help- slate - a note taking tool.  Usage: slate COMMAND@@ -41,6 +42,8 @@                            done notes otherwise.   todo                     Mark a note as todo when given a note ID, display                            todo notes otherwise.+  doing                    Toggle highlighting on a note when given a note ID,+                           display notes marked as doing otherwise.   remove                   Remove a note.   display                  Display a slate.   rename                   Rename a slate.@@ -64,6 +67,7 @@  $ slate status 1 done, 1 todo (2 total).+▮▮▮▮▮▮▮▮▮▮▮▮▮▮▯▯▯▯▯▯▯▯▯▯▯▯▯▯  $ slate add "Fake note" $ slate display
slate.cabal view
@@ -1,11 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.27.0.+-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack ----- hash: 05ce519ad09a3080cf323932dc67f8f23ef49a1548fe61dedd2c0da298836bf7+-- hash: d019482639897778ad0de66e9777ed7e55617c47cb7c5e4fa748a230bc2ad249  name:           slate-version:        0.10.0.0+version:        0.11.0.0 synopsis:       A note taking CLI tool. description:    Please see the README on Github at <https://github.com/evuez/slate#readme> homepage:       https://github.com/evuez/slate#readme@@ -17,7 +17,6 @@ license-file:   LICENSE build-type:     Simple cabal-version:  >= 1.10- extra-source-files:     ChangeLog.md     README.md
src/Lib.hs view
@@ -51,6 +51,8 @@          (Maybe NoteId)   | Todo Slate          (Maybe NoteId)+  | Doing Slate+          (Maybe NoteId)   | Remove Slate            NoteId   | Display Slate@@ -80,6 +82,9 @@ todo :: Parser Command todo = Todo <$> name <*> optional (argument auto (metavar "NOTE ID")) +doing :: Parser Command+doing = Doing <$> name <*> optional (argument auto (metavar "NOTE ID"))+ remove :: Parser Command remove = Remove <$> name <*> argument auto (metavar "NOTE ID") @@ -125,6 +130,12 @@           todo           (progDesc              "Mark a note as todo when given a note ID, display todo notes otherwise.")) <>+     command+       "doing"+       (info+          doing+          (progDesc+             "Toggle highlighting on a note when given a note ID, display notes marked as doing otherwise.")) <>      command "remove" (info remove (progDesc "Remove a note.")) <>      command "display" (info display (progDesc "Display a slate.")) <>      command "rename" (info rename (progDesc "Rename a slate.")) <>@@ -140,6 +151,8 @@ execute (Done s Nothing) = getSlatePath s >>= (\x -> displaySlate x "done") execute (Todo s (Just n)) = getSlatePath s >>= (\x -> markAsTodo x n) execute (Todo s Nothing) = getSlatePath s >>= (\x -> displaySlate x "todo")+execute (Doing s (Just n)) = getSlatePath s >>= (\x -> markAsDoing x n)+execute (Doing s Nothing) = getSlatePath s >>= (\x -> displaySlate x "doing") execute (Remove s n) = getSlatePath s >>= (\x -> removeNote x n) execute (Display s f) = getSlatePath s >>= (\x -> displaySlate x f) execute (Rename sc sn) = renameSlate sc sn@@ -219,9 +232,15 @@   contents <- readFile s   let notes = zipWith displayNote [0 ..] (lines contents)   putStr $ unlines $ filter (not . isNoteDone) notes+displaySlate s "doing" = do+  contents <- readFile s+  let notes = zipWith displayNote [0 ..] (lines contents)+  putStr $ unlines $ filter isNoteDoing notes displaySlate _ f = putStrLn $ "\"" ++ f ++ "\" is not a valid filter."  displayNote :: Int -> String -> String+displayNote line (' ':'-':' ':'[':_:']':' ':'>':note) =+  "\x1B[7m" ++ padInt line 2 ++ " -" ++ (toAnsi note) ++ "\x1B[0m" displayNote line (' ':'-':' ':'[':' ':']':note) =   padInt line 2 ++ " -" ++ (toAnsi note) displayNote line (' ':'-':' ':'[':'x':']':note) =@@ -232,9 +251,14 @@  isNoteDone :: String -> Bool isNoteDone (' ':'-':' ':'[':'x':']':_) = True-isNoteDone ('\x1B':_) = True+isNoteDone ('\x1B':'[':'9':'m':_) = True isNoteDone _ = False +isNoteDoing :: String -> Bool+isNoteDoing (' ':'-':' ':'[':' ':']':' ':'>':_) = True+isNoteDoing ('\x1B':'[':'7':'m':_) = True+isNoteDoing _ = False+ padInt :: Int -> Int -> String padInt n s = replicate (s - length (show n)) '0' ++ show n @@ -244,6 +268,7 @@   let (x, y:t) = splitAt n (lines contents)       c =         case y of+          ' ':'-':' ':'[':' ':']':' ':'>':note -> " - [x]" ++ note           ' ':'-':' ':'[':' ':']':note -> " - [x]" ++ note           note -> note       tmp = s ++ ".tmp"@@ -262,6 +287,26 @@   writeFile tmp (unlines $ x ++ c : t)   renameFile tmp s +markAsDoing :: FilePath -> Int -> IO ()+markAsDoing s n = do+  contents <- readFile s+  let ls = zipWith (removeDoingMarkForOthers n) [0 ..] (lines contents)+  let (x, y:t) = splitAt n ls+      c =+        case y of+          ' ':'-':' ':'[':m:']':' ':'>':note -> " - [" ++ [m] ++ "]" ++ note+          ' ':'-':' ':'[':_:']':note -> " - [ ] >" ++ note+          note -> note+      tmp = s ++ ".tmp"+  writeFile tmp (unlines $ x ++ c : t)+  renameFile tmp s++removeDoingMarkForOthers :: Int -> Int -> String -> String+removeDoingMarkForOthers k l p@(' ':'-':' ':'[':m:']':' ':'>':n)+  | k /= l = " - [" ++ [m] ++ "]" ++ n+  | otherwise = p+removeDoingMarkForOthers _ _ n = n+ removeNote :: FilePath -> Int -> IO () removeNote s n = do   contents <- readFile s@@ -299,15 +344,14 @@       dt = fromIntegral t :: Double       pd = round $ 28 * dd / (dt + dd)       pt = round $ 28 * dt / (dt + dd)+      p = round $ dd / (dd + dt) * 100 :: Integer   putStrLn $     (show d) ++     " done, " ++     (show t) ++     " todo (" ++-    (show $ d + t) ++-    " total).\n" ++-    "\x1B[32m" ++-    (replicate pd '▮') ++ "\x1B[0m" ++ (replicate pt '▮') ++ "\n" ++ ss+    (show p) +++    "% done).\n" ++ (replicate pd '▮') ++ (replicate pt '▯') ++ "\n" ++ ss  getSyncStatus :: FilePath -> IO String getSyncStatus s = do