From 3989ea17b17b117b35808d3a5ea1279998a3cb29 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 9 Jan 2016 03:24:03 +0000 Subject: code excerpt from thermoprint rewrite --- provider/posts/thermoprint-1.md | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/provider/posts/thermoprint-1.md b/provider/posts/thermoprint-1.md index bd98b71..642d739 100644 --- a/provider/posts/thermoprint-1.md +++ b/provider/posts/thermoprint-1.md @@ -41,7 +41,7 @@ the old one: ## Features -Features I intend to implement include: +git rFeatures I intend to implement include: * A parser for a bbcode-dialect which should be used in both the cli tool and the website (it will probably end up using @@ -64,6 +64,8 @@ Features I intend to implement include: ## Work so far +### Prototype + I already have a prototype. It's quite bug-ridden and has recently developed serious problems actually printing after working satisfactorily for a few weeks. @@ -74,6 +76,50 @@ overall code quality. The [685 lines of code](http://cloc.sourceforge.net/) can be found in the [repo](git://git.yggdrasil.li/thermoprint#master) as well. +### Rewrite + +Currently the [rewrite](git://git.yggdrasil.li/thermoprint#rewrite) contains a +single file of moment -- spec/src/Thermoprint/Printout.hs -- wherein we define +the payload for the api -- our take on a structured document format (somewhat +inspired by +[pandoc](http://hackage.haskell.org/package/pandoc-types/docs/Text-Pandoc-Definition.html)): + +~~~ {.haskell} +-- | A 'Printout' is a sequence of visually seperated 'Paragraph's +type Printout = Seq Paragraph + +-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's +type Paragraph = Seq Chunk + +-- | We introduce both 'Chunk' and 'Paragraph' mainly to allow 'Raw'. +-- +-- Were we to disallow 'Raw', 'Block' would be identical to 'Paragraph' +data Chunk = Cooked Block -- ^ text semantically structured to be rendered in accordance with the display format of printer + | Raw ByteString -- ^ direct instructions to the printer + deriving (Generic, NFData, Show, CoArbitrary) + +-- | 'Block' is the entry point for our structured document format +data Block = Line Line -- ^ a single 'Line' of text + | VSpace Integer -- ^ vertical space of height equivalent to 'Integer' lines + | NewlSep (Seq Block) -- ^ A sequence of 'Block's seperated by newlines + deriving (Generic, NFData, Show, CoArbitrary) + +{- | A 'Line' is one of: + + * a single word + * horizontal space equivalent to the width of 'Integer' `em`. + * a sequence of words seperated by spaces + +We don't export all constructors and instead encourage the use of 'text'. +-} +data Line = Word Text + | HSpace Integer + | SpaceSep (Seq Line) + deriving (Generic, NFData, Show, CoArbitrary) +~~~ + +(The comments are verbatim as of 8307d7e). +