summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasperVanDerJeugt <>2016-10-31 10:59:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-10-31 10:59:00 (GMT)
commit5ed76916df8d34c9e5f436555797b2c980b71d0e (patch)
treec86f86668f18deacf632f0105376a02dbe64c776
parentbbd085267e4ee57fd8fd77f2471864835658651a (diff)
version 0.3.3.00.3.3.0
-rw-r--r--CHANGELOG.md4
-rw-r--r--patat.cabal6
-rw-r--r--src/Main.hs32
-rw-r--r--src/Patat/Presentation/Display.hs11
-rw-r--r--src/Patat/Theme.hs5
5 files changed, 48 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a66f1d..65bba9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+- 0.3.3.0 (2016-10-31)
+ * Add a `--version` flag.
+ * Add support for `pandoc-1.18` which includes a new `LineBlock` element.
+
- 0.3.2.0 (2016-10-20)
* Keep running even if errors are encountered during reload.
diff --git a/patat.cabal b/patat.cabal
index 5068a78..35bcadc 100644
--- a/patat.cabal
+++ b/patat.cabal
@@ -1,5 +1,5 @@
Name: patat
-Version: 0.3.2.0
+Version: 0.3.3.0
Synopsis: Terminal-based presentations using Pandoc
Description: Terminal-based presentations using Pandoc
License: GPL-2
@@ -24,7 +24,7 @@ Executable patat
Default-language: Haskell2010
Build-depends:
- aeson >= 0.11 && < 1.1,
+ aeson >= 0.9 && < 1.1,
ansi-terminal >= 0.6 && < 0.7,
ansi-wl-pprint >= 0.6 && < 0.7,
base >= 4.6 && < 4.10,
@@ -35,7 +35,7 @@ Executable patat
highlighting-kate >= 0.6 && < 0.7,
mtl >= 2.2 && < 2.3,
optparse-applicative >= 0.12 && < 0.14,
- pandoc >= 1.17 && < 1.18,
+ pandoc >= 1.16 && < 1.19,
terminal-size >= 0.3 && < 0.4,
text >= 1.2 && < 1.3,
time >= 1.4 && < 1.7,
diff --git a/src/Main.hs b/src/Main.hs
index 6527cbd..fa434da 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -10,7 +10,7 @@ import Control.Applicative ((<$>), (<*>))
import Control.Concurrent (forkIO, threadDelay)
import qualified Control.Concurrent.Chan as Chan
import Control.Monad (forever, unless, when)
-import Data.Monoid ((<>))
+import Data.Monoid (mempty, (<>))
import Data.Time (UTCTime)
import Data.Version (showVersion)
import qualified Options.Applicative as OA
@@ -19,7 +19,7 @@ import qualified Paths_patat
import qualified System.Console.ANSI as Ansi
import System.Directory (doesFileExist,
getModificationTime)
-import System.Exit (exitFailure)
+import System.Exit (exitFailure, exitSuccess)
import qualified System.IO as IO
import qualified Text.PrettyPrint.ANSI.Leijen as PP
import Prelude
@@ -27,17 +27,18 @@ import Prelude
--------------------------------------------------------------------------------
data Options = Options
- { oFilePath :: !FilePath
+ { oFilePath :: !(Maybe FilePath)
, oForce :: !Bool
, oDump :: !Bool
, oWatch :: !Bool
+ , oVersion :: !Bool
} deriving (Show)
--------------------------------------------------------------------------------
parseOptions :: OA.Parser Options
parseOptions = Options
- <$> (OA.strArgument $
+ <$> (OA.optional $ OA.strArgument $
OA.metavar "FILENAME" <>
OA.help "Input file")
<*> (OA.switch $
@@ -54,6 +55,10 @@ parseOptions = Options
OA.long "watch" <>
OA.short 'w' <>
OA.help "Watch file for changes")
+ <*> (OA.switch $
+ OA.long "version" <>
+ OA.help "Display version info and exit" <>
+ OA.hidden)
--------------------------------------------------------------------------------
@@ -79,6 +84,11 @@ parserInfo = OA.info (OA.helper <*> parseOptions) $
--------------------------------------------------------------------------------
+parserPrefs :: OA.ParserPrefs
+parserPrefs = OA.prefs OA.showHelpOnError
+
+
+--------------------------------------------------------------------------------
errorAndExit :: [String] -> IO a
errorAndExit msg = do
mapM_ (IO.hPutStrLn IO.stderr) msg
@@ -98,8 +108,18 @@ assertAnsiFeatures = do
--------------------------------------------------------------------------------
main :: IO ()
main = do
- options <- OA.customExecParser (OA.prefs OA.showHelpOnError) parserInfo
- errOrPres <- readPresentation (oFilePath options)
+ options <- OA.customExecParser parserPrefs parserInfo
+
+ when (oVersion options) $ do
+ putStrLn (showVersion Paths_patat.version)
+ exitSuccess
+
+ filePath <- case oFilePath options of
+ Just fp -> return fp
+ Nothing -> OA.handleParseResult $ OA.Failure $
+ OA.parserFailure parserPrefs parserInfo OA.ShowHelpText mempty
+
+ errOrPres <- readPresentation filePath
pres <- either (errorAndExit . return) return errOrPres
unless (oForce options) assertAnsiFeatures
diff --git a/src/Patat/Presentation/Display.hs b/src/Patat/Presentation/Display.hs
index 3acf601..99762e3 100644
--- a/src/Patat/Presentation/Display.hs
+++ b/src/Patat/Presentation/Display.hs
@@ -1,4 +1,5 @@
--------------------------------------------------------------------------------
+{-# LANGUAGE CPP #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
@@ -206,6 +207,16 @@ prettyBlock theme (Pandoc.Div _attrs blocks) = prettyBlocks theme blocks
prettyBlock _theme Pandoc.Null = mempty
+#if MIN_VERSION_pandoc(1,18,0)
+-- 'LineBlock' elements are new in pandoc-1.18
+prettyBlock theme@Theme {..} (Pandoc.LineBlock inliness) =
+ let ind = PP.NotTrimmable (themed themeLineBlock "| ") in
+ PP.wrapAt Nothing $
+ PP.indent ind ind $
+ PP.vcat $
+ map (prettyInlines theme) inliness
+#endif
+
--------------------------------------------------------------------------------
prettyBlocks :: Theme -> [Pandoc.Block] -> PP.Doc
diff --git a/src/Patat/Theme.hs b/src/Patat/Theme.hs
index 6ace99c..706f825 100644
--- a/src/Patat/Theme.hs
+++ b/src/Patat/Theme.hs
@@ -43,6 +43,7 @@ data Theme = Theme
, themeDefinitionList :: !(Maybe Style)
, themeTableHeader :: !(Maybe Style)
, themeTableSeparator :: !(Maybe Style)
+ , themeLineBlock :: !(Maybe Style)
, themeEmph :: !(Maybe Style)
, themeStrong :: !(Maybe Style)
, themeCode :: !(Maybe Style)
@@ -62,7 +63,7 @@ instance Monoid Theme where
mempty = Theme
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
- Nothing Nothing Nothing Nothing
+ Nothing Nothing Nothing Nothing Nothing
mappend l r = Theme
{ themeBorders = mplusOn themeBorders
@@ -76,6 +77,7 @@ instance Monoid Theme where
, themeDefinitionList = mplusOn themeDefinitionList
, themeTableHeader = mplusOn themeTableHeader
, themeTableSeparator = mplusOn themeTableSeparator
+ , themeLineBlock = mplusOn themeLineBlock
, themeEmph = mplusOn themeEmph
, themeStrong = mplusOn themeStrong
, themeCode = mplusOn themeCode
@@ -107,6 +109,7 @@ defaultTheme = Theme
, themeDefinitionList = dull Ansi.Magenta
, themeTableHeader = dull Ansi.Blue
, themeTableSeparator = dull Ansi.Magenta
+ , themeLineBlock = dull Ansi.Magenta
, themeEmph = dull Ansi.Green
, themeStrong = dull Ansi.Red <> bold
, themeCode = dull Ansi.White <> ondull Ansi.Black