From d5c39015fb75662f5ae572aa04cdf20d5b8baac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Mon, 9 Sep 2013 16:13:53 -0300 Subject: Compose mode --- src/Lazymail/Utils.hs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Lazymail/Utils.hs (limited to 'src/Lazymail/Utils.hs') diff --git a/src/Lazymail/Utils.hs b/src/Lazymail/Utils.hs new file mode 100644 index 0000000..a31db63 --- /dev/null +++ b/src/Lazymail/Utils.hs @@ -0,0 +1,56 @@ +{- Miscellaneous functions written apart in order to avoid + - cyclics module imports + - + - Copyright 2013 Raúl Benencia + - + - Licensed under the GNU GPL version 3 or higher + -} + +module Lazymail.Utils ( newDialogWindow, drawNotification + , liftCurses, drawCroppedString + ) where + +import Control.Monad.Trans ( liftIO ) +import Control.Monad.Reader +import Control.Monad.State +import UI.NCurses + +import Lazymail.Print +import Lazymail.Types +import Lazymail.State + +newDialogWindow :: LazymailState -> Curses (Integer, Integer, Window) +newDialogWindow st = + let rows = 3 + cols st = 9 * ((scrColsAsInteger st) `div` 10) + startCol st = 2 * ((scrColsAsInteger st) `div` 20) + startRow st = (div (scrRowsAsInteger st) 2) - 1 + in do + w <- newWindow 3 (cols st) (startRow st) (startCol st) + updateWindow w $ drawBox Nothing Nothing + render + return (rows, cols st, w) + +drawNotification :: String -> LazymailCurses () +drawNotification errorMessage = do + st <- get + (_, cols, w) <- liftCurses $ newDialogWindow st + liftCurses $ do + updateWindow w $ do + moveCursor 1 1 + drawString errorMessage + render + waitFor w (\ev -> ev == EventCharacter 'q' || ev == EventCharacter 'Q' || ev == EventCharacter '\n') + closeWindow w + +waitFor :: Window -> (Event -> Bool) -> Curses () +waitFor w p = loop where + loop = do + ev <- getEvent w Nothing + case ev of + Nothing -> loop + Just ev' -> if p ev' then return () else loop + +liftCurses = lift . lift + +drawCroppedString st str = drawString $ normalizeLen (screenColumns st) str -- cgit v1.2.3