From 1e95f1f7c799f4b63b554fc181aed49f0737d8c7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 29 Mar 2015 17:19:36 +0900 Subject: implement staggering of reminders drawn from Emacs --- src/Control/SremConfig.hs | 4 ++++ src/Utility/Emacs.hs | 26 +++++++++++++------------- srem.cabal | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 src/Control/SremConfig.hs diff --git a/src/Control/SremConfig.hs b/src/Control/SremConfig.hs new file mode 100644 index 0000000..ef62cbe --- /dev/null +++ b/src/Control/SremConfig.hs @@ -0,0 +1,4 @@ +module Control.SremConfig where + +intervals :: [Int] +intervals = [60, 15, 0] diff --git a/src/Utility/Emacs.hs b/src/Utility/Emacs.hs index 27f0830..7ea7639 100644 --- a/src/Utility/Emacs.hs +++ b/src/Utility/Emacs.hs @@ -1,13 +1,17 @@ +{-# LANGUAGE DataKinds, TypeOperators #-} + module Utility.Emacs ( getEmacsOutput , parseEmacsOutput) where import Control.Applicative ((<$>)) -import Control.Monad (when, foldM) +import Control.Monad (foldM, when) +import qualified Control.SremConfig as SremConfig import Data.Maybe.Read import System.Directory (getHomeDirectory) import System.Process (readProcess) import Text.Regex.Posix ((=~)) import Types.Reminder +import Data.Modular parseEmacsOutput :: String -> [Reminder] parseEmacsOutput = foldr step [] . drop 2 . lines @@ -29,18 +33,14 @@ parseLine line = do lineMatchStrings = line =~ apptRegexp :: [[String]] staggeredReminders :: Reminder -> Maybe [Reminder] -staggeredReminders r = undefined - --- staggeredReminders :: Int -> Int -> String -> [Reminder] --- staggeredReminders hour mins text = foldl' step [] [60, 15, 0] --- where step rems diff = let hour' --- | diff > mins = hour - 1 --- | otherwise = hour --- -- could do with addition mod 60 --- mins' --- | mins >= diff = mins - diff --- | otherwise = 60 + (mins - diff) --- in rems ++ [Reminder hour' mins' text] +staggeredReminders r = sequence $ foldr step [] SremConfig.intervals + where + step minsBefore rems = + makeReminder (h minsBefore) (m minsBefore) (getReminderText r) : rems + h m = if m > getReminderMinute r + then getReminderHour r - 1 + else getReminderHour r + m m = unMod $ (toMod (getReminderMinute r) :: Int/60) - (toMod m :: Int/60) getEmacsOutput :: IO String getEmacsOutput = do diff --git a/srem.cabal b/srem.cabal index dfc7d87..ad94ce0 100644 --- a/srem.cabal +++ b/srem.cabal @@ -16,5 +16,6 @@ executable srem , directory , process , regex-posix + , modular-arithmetic hs-source-dirs: src default-language: Haskell2010 -- cgit v1.2.3