summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasperVanDerJeugt <>2017-05-16 11:35:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-05-16 11:35:00 (GMT)
commit6542c59315bf06d3a8b96692044e902e66a6bd18 (patch)
treea2a0fff75aab012bc508d93bb452908418b88615
parent351eb796e7b5dd525c5509ff2a304f5eb26cc6ae (diff)
version 0.5.2.00.5.2.0
-rw-r--r--CHANGELOG.md5
-rw-r--r--README.md4
-rw-r--r--patat.cabal4
-rw-r--r--src/Main.hs4
-rw-r--r--src/Patat/Presentation/Display/CodeBlock.hs56
-rw-r--r--src/Patat/Presentation/Interactive.hs4
-rw-r--r--src/Patat/Theme.hs58
7 files changed, 74 insertions, 61 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93a7bde..66964cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog
+- 0.5.2.0 (2017-05-16)
+ * Add navigation using `PageUp` and `PageDown`.
+ * Use `skylighting` instead of deprecated `highlighting-kate` for syntax
+ highlighting.
+
- 0.5.1.2 (2017-04-26)
* Make build reproducible even if timezone changes (patch by Félix Sipma)
diff --git a/README.md b/README.md
index 2ccfae6..2b6f7f3 100644
--- a/README.md
+++ b/README.md
@@ -115,8 +115,8 @@ Options
Controls
--------
-- **Next slide**: `space`, `enter`, `l`, `→`
-- **Previous slide**: `backspace`, `h`, `←`
+- **Next slide**: `space`, `enter`, `l`, `→`, `PageDown`
+- **Previous slide**: `backspace`, `h`, `←`, `PageUp`
- **Go forward 10 slides**: `j`, `↓`
- **Go backward 10 slides**: `k`, `↑`
- **First slide**: `0`
diff --git a/patat.cabal b/patat.cabal
index be54a43..c6477c5 100644
--- a/patat.cabal
+++ b/patat.cabal
@@ -1,5 +1,5 @@
Name: patat
-Version: 0.5.1.2
+Version: 0.5.2.0
Synopsis: Terminal-based presentations using Pandoc
Description: Terminal-based presentations using Pandoc
License: GPL-2
@@ -35,10 +35,10 @@ Executable patat
containers >= 0.5 && < 0.6,
directory >= 1.2 && < 1.4,
filepath >= 1.4 && < 1.5,
- highlighting-kate >= 0.6 && < 0.7,
mtl >= 2.2 && < 2.3,
optparse-applicative >= 0.12 && < 0.14,
pandoc >= 1.16 && < 1.20,
+ skylighting >= 0.1 && < 0.4,
terminal-size >= 0.3 && < 0.4,
text >= 1.2 && < 1.3,
time >= 1.4 && < 1.8,
diff --git a/src/Main.hs b/src/Main.hs
index d555407..2073453 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -75,8 +75,8 @@ parserInfo = OA.info (OA.helper <*> parseOptions) $
[ "Terminal-based presentations using Pandoc"
, ""
, "Controls:"
- , "- Next slide: space, enter, l, right"
- , "- Previous slide: backspace, h, left"
+ , "- Next slide: space, enter, l, right, pagedown"
+ , "- Previous slide: backspace, h, left, pageup"
, "- Go forward 10 slides: j, down"
, "- Go backward 10 slides: k, up"
, "- First slide: 0"
diff --git a/src/Patat/Presentation/Display/CodeBlock.hs b/src/Patat/Presentation/Display/CodeBlock.hs
index 4888166..149bc68 100644
--- a/src/Patat/Presentation/Display/CodeBlock.hs
+++ b/src/Patat/Presentation/Display/CodeBlock.hs
@@ -8,41 +8,45 @@ module Patat.Presentation.Display.CodeBlock
--------------------------------------------------------------------------------
-import Data.Char (toLower)
-import Data.List (find)
+import Data.Maybe (mapMaybe)
import Data.Monoid (mconcat, (<>))
-import qualified Data.Set as S
+import qualified Data.Text as T
import Patat.Presentation.Display.Table (themed)
import qualified Patat.PrettyPrint as PP
import Patat.Theme
-import qualified Text.Highlighting.Kate as Kate
import Prelude
+import qualified Skylighting as Skylighting
--------------------------------------------------------------------------------
-lower :: String -> String
-lower = map toLower
-
-
---------------------------------------------------------------------------------
-supportedLanguages :: S.Set String
-supportedLanguages = S.fromList (map lower Kate.languages)
+highlight :: [String] -> String -> [Skylighting.SourceLine]
+highlight classes rawCodeBlock = case mapMaybe getSyntax classes of
+ [] -> zeroHighlight rawCodeBlock
+ (syn : _) ->
+ case Skylighting.tokenize config syn (T.pack rawCodeBlock) of
+ Left _ -> zeroHighlight rawCodeBlock
+ Right sl -> sl
+ where
+ getSyntax :: String -> Maybe Skylighting.Syntax
+ getSyntax c = Skylighting.lookupSyntax (T.pack c) syntaxMap
+ config :: Skylighting.TokenizerConfig
+ config = Skylighting.TokenizerConfig
+ { Skylighting.syntaxMap = syntaxMap
+ , Skylighting.traceOutput = False
+ }
---------------------------------------------------------------------------------
-highlight :: [String] -> String -> [Kate.SourceLine]
-highlight classes rawCodeBlock =
- case find (\c -> lower c `S.member` supportedLanguages) classes of
- Nothing -> zeroHighlight rawCodeBlock
- Just lang -> Kate.highlightAs lang rawCodeBlock
+ syntaxMap :: Skylighting.SyntaxMap
+ syntaxMap = Skylighting.defaultSyntaxMap
--------------------------------------------------------------------------------
-- | This does fake highlighting, everything becomes a normal token. That makes
-- things a bit easier, since we only need to deal with one cases in the
-- renderer.
-zeroHighlight :: String -> [Kate.SourceLine]
-zeroHighlight str = [[(Kate.NormalTok, line)] | line <- lines str]
+zeroHighlight :: String -> [Skylighting.SourceLine]
+zeroHighlight str =
+ [[(Skylighting.NormalTok, T.pack line)] | line <- lines str]
--------------------------------------------------------------------------------
@@ -51,24 +55,24 @@ prettyCodeBlock theme@Theme {..} classes rawCodeBlock =
PP.vcat (map blockified sourceLines) <>
PP.hardline
where
- sourceLines :: [Kate.SourceLine]
+ sourceLines :: [Skylighting.SourceLine]
sourceLines =
[[]] ++ highlight classes rawCodeBlock ++ [[]]
- prettySourceLine :: Kate.SourceLine -> PP.Doc
+ prettySourceLine :: Skylighting.SourceLine -> PP.Doc
prettySourceLine = mconcat . map prettyToken
- prettyToken :: Kate.Token -> PP.Doc
+ prettyToken :: Skylighting.Token -> PP.Doc
prettyToken (tokenType, str) =
- themed (syntaxHighlight theme tokenType) (PP.string str)
+ themed (syntaxHighlight theme tokenType) (PP.string $ T.unpack str)
- sourceLineLength :: Kate.SourceLine -> Int
- sourceLineLength line = sum [length str | (_, str) <- line]
+ sourceLineLength :: Skylighting.SourceLine -> Int
+ sourceLineLength line = sum [T.length str | (_, str) <- line]
blockWidth :: Int
blockWidth = foldr max 0 (map sourceLineLength sourceLines)
- blockified :: Kate.SourceLine -> PP.Doc
+ blockified :: Skylighting.SourceLine -> PP.Doc
blockified line =
let len = sourceLineLength line
indent = PP.NotTrimmable " " in
diff --git a/src/Patat/Presentation/Interactive.hs b/src/Patat/Presentation/Interactive.hs
index 6c2dad1..d3977e3 100644
--- a/src/Patat/Presentation/Interactive.hs
+++ b/src/Patat/Presentation/Interactive.hs
@@ -42,10 +42,14 @@ readPresentationCommand = do
"j" -> return SkipForward
"k" -> return SkipBackward
"l" -> return Forward
+ -- Arrow keys
"\ESC[C" -> return Forward
"\ESC[D" -> return Backward
"\ESC[B" -> return SkipForward
"\ESC[A" -> return SkipBackward
+ -- PageUp and PageDown
+ "\ESC[6" -> return Forward
+ "\ESC[5" -> return Backward
"0" -> return First
"G" -> return Last
"r" -> return Reload
diff --git a/src/Patat/Theme.hs b/src/Patat/Theme.hs
index 706f825..d01a71a 100644
--- a/src/Patat/Theme.hs
+++ b/src/Patat/Theme.hs
@@ -24,10 +24,10 @@ import qualified Data.Map as M
import Data.Maybe (mapMaybe, maybeToList)
import Data.Monoid (Monoid (..), (<>))
import qualified Data.Text as T
+import Prelude
+import qualified Skylighting as Skylighting
import qualified System.Console.ANSI as Ansi
-import qualified Text.Highlighting.Kate as Kate
import Text.Read (readMaybe)
-import Prelude
--------------------------------------------------------------------------------
@@ -218,30 +218,30 @@ instance A.FromJSON SyntaxHighlighting where
--------------------------------------------------------------------------------
defaultSyntaxHighlighting :: SyntaxHighlighting
defaultSyntaxHighlighting = mkSyntaxHighlighting
- [ (Kate.KeywordTok, dull Ansi.Yellow)
- , (Kate.ControlFlowTok, dull Ansi.Yellow)
-
- , (Kate.DataTypeTok, dull Ansi.Green)
-
- , (Kate.DecValTok, dull Ansi.Red)
- , (Kate.BaseNTok, dull Ansi.Red)
- , (Kate.FloatTok, dull Ansi.Red)
- , (Kate.ConstantTok, dull Ansi.Red)
- , (Kate.CharTok, dull Ansi.Red)
- , (Kate.SpecialCharTok, dull Ansi.Red)
- , (Kate.StringTok, dull Ansi.Red)
- , (Kate.VerbatimStringTok, dull Ansi.Red)
- , (Kate.SpecialStringTok, dull Ansi.Red)
-
- , (Kate.CommentTok, dull Ansi.Blue)
- , (Kate.DocumentationTok, dull Ansi.Blue)
- , (Kate.AnnotationTok, dull Ansi.Blue)
- , (Kate.CommentVarTok, dull Ansi.Blue)
-
- , (Kate.ImportTok, dull Ansi.Cyan)
- , (Kate.OperatorTok, dull Ansi.Cyan)
- , (Kate.FunctionTok, dull Ansi.Cyan)
- , (Kate.PreprocessorTok, dull Ansi.Cyan)
+ [ (Skylighting.KeywordTok, dull Ansi.Yellow)
+ , (Skylighting.ControlFlowTok, dull Ansi.Yellow)
+
+ , (Skylighting.DataTypeTok, dull Ansi.Green)
+
+ , (Skylighting.DecValTok, dull Ansi.Red)
+ , (Skylighting.BaseNTok, dull Ansi.Red)
+ , (Skylighting.FloatTok, dull Ansi.Red)
+ , (Skylighting.ConstantTok, dull Ansi.Red)
+ , (Skylighting.CharTok, dull Ansi.Red)
+ , (Skylighting.SpecialCharTok, dull Ansi.Red)
+ , (Skylighting.StringTok, dull Ansi.Red)
+ , (Skylighting.VerbatimStringTok, dull Ansi.Red)
+ , (Skylighting.SpecialStringTok, dull Ansi.Red)
+
+ , (Skylighting.CommentTok, dull Ansi.Blue)
+ , (Skylighting.DocumentationTok, dull Ansi.Blue)
+ , (Skylighting.AnnotationTok, dull Ansi.Blue)
+ , (Skylighting.CommentVarTok, dull Ansi.Blue)
+
+ , (Skylighting.ImportTok, dull Ansi.Cyan)
+ , (Skylighting.OperatorTok, dull Ansi.Cyan)
+ , (Skylighting.FunctionTok, dull Ansi.Cyan)
+ , (Skylighting.PreprocessorTok, dull Ansi.Cyan)
]
where
dull c = Style [Ansi.SetColor Ansi.Foreground Ansi.Dull c]
@@ -251,7 +251,7 @@ defaultSyntaxHighlighting = mkSyntaxHighlighting
--------------------------------------------------------------------------------
-nameForTokenType :: Kate.TokenType -> String
+nameForTokenType :: Skylighting.TokenType -> String
nameForTokenType =
unCapitalize . dropTok . show
where
@@ -265,7 +265,7 @@ nameForTokenType =
--------------------------------------------------------------------------------
-nameToTokenType :: String -> Maybe Kate.TokenType
+nameToTokenType :: String -> Maybe Skylighting.TokenType
nameToTokenType = readMaybe . capitalize . (++ "Tok")
@@ -276,7 +276,7 @@ capitalize (x : xs) = toUpper x : xs
--------------------------------------------------------------------------------
-syntaxHighlight :: Theme -> Kate.TokenType -> Maybe Style
+syntaxHighlight :: Theme -> Skylighting.TokenType -> Maybe Style
syntaxHighlight theme tokenType = do
sh <- themeSyntaxHighlighting theme
M.lookup (nameForTokenType tokenType) (unSyntaxHighlighting sh)