summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs5
-rw-r--r--src/Patat/Presentation/Display.hs7
-rw-r--r--src/Patat/Presentation/Interactive.hs20
3 files changed, 19 insertions, 13 deletions
diff --git a/src/Main.hs b/src/Main.hs
index bfeca9c..0fccfde 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -9,6 +9,7 @@ module Main where
import Control.Applicative ((<$>), (<*>))
import Control.Concurrent (forkIO, threadDelay)
import qualified Control.Concurrent.Chan as Chan
+import Control.Exception (finally)
import Control.Monad (forever, unless, when)
import qualified Data.Aeson.Extended as A
import Data.Monoid (mempty, (<>))
@@ -131,8 +132,10 @@ main = do
else interactiveLoop options pres
where
interactiveLoop :: Options -> Presentation -> IO ()
- interactiveLoop options pres0 = do
+ interactiveLoop options pres0 = (`finally` Ansi.showCursor) $ do
IO.hSetBuffering IO.stdin IO.NoBuffering
+ Ansi.hideCursor
+
-- Spawn the initial channel that gives us commands based on user input.
commandChan0 <- Chan.newChan
_ <- forkIO $ forever $
diff --git a/src/Patat/Presentation/Display.hs b/src/Patat/Presentation/Display.hs
index 1738e23..cb562d7 100644
--- a/src/Patat/Presentation/Display.hs
+++ b/src/Patat/Presentation/Display.hs
@@ -26,10 +26,11 @@ import Patat.PrettyPrint ((<$$>), (<+>))
import qualified Patat.PrettyPrint as PP
import Patat.Theme (Theme (..))
import qualified Patat.Theme as Theme
+import Prelude
import qualified System.Console.ANSI as Ansi
import qualified System.Console.Terminal.Size as Terminal
+import qualified System.IO as IO
import qualified Text.Pandoc.Extended as Pandoc
-import Prelude
--------------------------------------------------------------------------------
@@ -69,11 +70,11 @@ displayWithBorders Presentation {..} f = do
active = show (sidx + 1) ++ " / " ++ show (length pSlides)
activeWidth = length active
- Ansi.setCursorPosition (rows - 2) 0
+ Ansi.setCursorPosition (rows - 1) 0
PP.putDoc $ " " <> borders (prettyInlines theme pAuthor)
Ansi.setCursorColumn (columns - activeWidth - 1)
PP.putDoc $ borders $ PP.string active
- putStrLn ""
+ IO.hFlush IO.stdout
--------------------------------------------------------------------------------
diff --git a/src/Patat/Presentation/Interactive.hs b/src/Patat/Presentation/Interactive.hs
index d7d7d53..830f0ff 100644
--- a/src/Patat/Presentation/Interactive.hs
+++ b/src/Patat/Presentation/Interactive.hs
@@ -27,6 +27,7 @@ data PresentationCommand
| First
| Last
| Reload
+ | UnknownCommand String
--------------------------------------------------------------------------------
@@ -48,7 +49,7 @@ readPresentationCommand = do
"0" -> return First
"G" -> return Last
"r" -> return Reload
- _ -> readPresentationCommand
+ _ -> return (UnknownCommand k)
where
readKey :: IO String
readKey = do
@@ -77,14 +78,15 @@ updatePresentation
:: PresentationCommand -> Presentation -> IO UpdatedPresentation
updatePresentation cmd presentation = case cmd of
- Exit -> return ExitedPresentation
- Forward -> return $ goToSlide $ \(s, f) -> (s, f + 1)
- Backward -> return $ goToSlide $ \(s, f) -> (s, f - 1)
- SkipForward -> return $ goToSlide $ \(s, _) -> (s + 10, 0)
- SkipBackward -> return $ goToSlide $ \(s, _) -> (s - 10, 0)
- First -> return $ goToSlide $ \_ -> (0, 0)
- Last -> return $ goToSlide $ \_ -> (numSlides presentation, 0)
- Reload -> reloadPresentation
+ Exit -> return ExitedPresentation
+ Forward -> return $ goToSlide $ \(s, f) -> (s, f + 1)
+ Backward -> return $ goToSlide $ \(s, f) -> (s, f - 1)
+ SkipForward -> return $ goToSlide $ \(s, _) -> (s + 10, 0)
+ SkipBackward -> return $ goToSlide $ \(s, _) -> (s - 10, 0)
+ First -> return $ goToSlide $ \_ -> (0, 0)
+ Last -> return $ goToSlide $ \_ -> (numSlides presentation, 0)
+ Reload -> reloadPresentation
+ UnknownCommand _ -> return (UpdatedPresentation presentation)
where
numSlides :: Presentation -> Int
numSlides pres = length (pSlides pres)