Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Feb 9, 2024
1 parent c01a967 commit 0979190
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
58 changes: 28 additions & 30 deletions lib/Patat/Presentation/Display.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ data Display = DisplayDoc PP.Doc | DisplayImage FilePath deriving (Show)
-- the active slide number and so on.
displayWithBorders
:: Size -> Presentation -> (DisplaySettings -> PP.Doc) -> PP.Doc
displayWithBorders size@(Size rows columns) pres@Presentation {..} f =
displayWithBorders (Size rows columns) pres@Presentation {..} f =
(if null title
then mempty
else
let titleRemainder = columns - titleWidth - titleOffset
wrappedTitle = PP.spaces titleOffset <> PP.string title <> PP.spaces titleRemainder in
borders wrappedTitle <> PP.hardline) <>
mconcat (replicate topMargin PP.hardline) <>
formatWith size (activeSettings pres) body <> PP.hardline <>
body <> PP.hardline <>
PP.goToLine (rows - 2) <>
borders (PP.space <> PP.string author <> middleSpaces <> PP.string active <> PP.space) <>
PP.hardline
Expand All @@ -60,9 +60,11 @@ displayWithBorders size@(Size rows columns) pres@Presentation {..} f =
(sidx, _) = pActiveFragment
settings = activeSettings pres
ds = DisplaySettings
{ dsSize = canvasSize
, dsTheme = fromMaybe Theme.defaultTheme (psTheme settings)
, dsSyntaxMap = pSyntaxMap
{ dsSize = canvasSize
, dsWrap = fromMaybe False $ psWrap settings
, dsMargins = margins settings
, dsTheme = fromMaybe Theme.defaultTheme (psTheme settings)
, dsSyntaxMap = pSyntaxMap
}

-- Compute title.
Expand All @@ -84,13 +86,12 @@ displayWithBorders size@(Size rows columns) pres@Presentation {..} f =
borders = themed ds themeBorders

-- Room left for content
body = f ds
topMargin = case mTop $ margins settings of
Auto -> let (r, _) = PP.dimensions body in (rows - 4 - r) `div` 2
NotAuto x -> x
canvasSize = Size (rows - 2 - topMargin) columns

body = f ds

-- Compute footer.
active
| fromMaybe True $ psSlideNumber settings = show (sidx + 1) ++ " / " ++ show (length pSlides)
Expand Down Expand Up @@ -189,33 +190,30 @@ dumpPresentation pres@Presentation {..} =


--------------------------------------------------------------------------------
formatWith :: Size -> PresentationSettings -> PP.Doc -> PP.Doc
formatWith (Size _ columns) ps doc = wrap $ indent doc
prettyFragment :: DisplaySettings -> Fragment -> PP.Doc
prettyFragment ds (Fragment blocks) =
PP.vcat (map (wrapAndMargin . prettyBlock ds) blocks) <>
case prettyReferences ds blocks of
[] -> mempty
refs -> PP.hardline <> PP.vcat (map wrapAndMargin refs)
where
Margins {..} = margins ps
(_, dcols) = PP.dimensions doc
wrap = case psWrap ps of
Just True ->
wrapAndMargin doc = wrap $ indent doc
where
(Size _ columns) = dsSize ds
Margins {..} = dsMargins ds
(_, dcols) = PP.dimensions doc
wrap =
let right = case mRight of
Auto -> 0
NotAuto x -> x in
PP.wrapAt (Just $ columns - right)
_ -> id
spaces = PP.NotTrimmable $ PP.spaces $ case mLeft of
NotAuto x -> x
Auto -> case mRight of
NotAuto _ -> 0
Auto -> (columns - dcols) `div` 2
indent = PP.indent spaces spaces

if dsWrap ds then PP.wrapAt (Just $ columns - right) else id

--------------------------------------------------------------------------------
prettyFragment :: DisplaySettings -> Fragment -> PP.Doc
prettyFragment ds (Fragment blocks) =
prettyBlocks ds blocks <>
case prettyReferences ds blocks of
[] -> mempty
refs -> PP.hardline <> PP.vcat refs
spaces = PP.NotTrimmable $ PP.spaces $ case mLeft of
NotAuto x -> x
Auto -> case mRight of
NotAuto _ -> 0
Auto -> (columns - dcols) `div` 2
indent = PP.indent spaces spaces


--------------------------------------------------------------------------------
Expand All @@ -241,7 +239,7 @@ prettyBlock ds (Pandoc.BulletList bss) = PP.vcat
| bs <- bss
] <> PP.hardline
where
prefix = " " <> PP.string [marker] <> " "
prefix = PP.string [marker] <> " "
marker = case T.unpack <$> themeBulletListMarkers theme of
Just (x : _) -> x
_ -> '-'
Expand Down
2 changes: 1 addition & 1 deletion lib/Patat/Presentation/Display/CodeBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ prettyCodeBlock ds classes rawCodeBlock =
blockified line =
let len = sourceLineLength line
indent = PP.NotTrimmable " " in

Check warning on line 79 in lib/Patat/Presentation/Display/CodeBlock.hs

View workflow job for this annotation

GitHub Actions / Build on ubuntu-latest

Defined but not used: ‘indent’

Check warning on line 79 in lib/Patat/Presentation/Display/CodeBlock.hs

View workflow job for this annotation

GitHub Actions / Build on ubuntu-latest

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraint
PP.indent indent indent $
-- PP.indent indent indent $
themed ds themeCodeBlock $
" " <>
prettySourceLine line <>
Expand Down
11 changes: 7 additions & 4 deletions lib/Patat/Presentation/Display/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ module Patat.Presentation.Display.Internal


--------------------------------------------------------------------------------
import Patat.Size (Size)
import qualified Patat.PrettyPrint as PP
import qualified Patat.Theme as Theme
import qualified Skylighting as Skylighting
import Patat.Presentation.Internal (Margins)
import qualified Patat.PrettyPrint as PP
import Patat.Size (Size)
import qualified Patat.Theme as Theme
import qualified Skylighting as Skylighting


--------------------------------------------------------------------------------
data DisplaySettings = DisplaySettings
{ dsSize :: !Size
, dsWrap :: !Bool
, dsMargins :: !Margins
, dsTheme :: !Theme.Theme
, dsSyntaxMap :: !Skylighting.SyntaxMap
}
Expand Down

0 comments on commit 0979190

Please sign in to comment.