mirror of
https://github.com/rodrigosetti/master-plan.git
synced 2024-11-22 04:13:26 +03:00
Add a new command line option: --render-parse-error
This commit is contained in:
parent
88c2a931e5
commit
8ff517d89e
24
CHANGELOG.md
Normal file
24
CHANGELOG.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.3.0] - 2017-08-17
|
||||
|
||||
New option flag: `--render-parse-error` which will render the image with the
|
||||
parsing error text, instead of printing to standard output. Also, the exit code
|
||||
will be normal.
|
||||
|
||||
## [0.2.0] - 2017-08-15
|
||||
|
||||
Changed completely the language syntax. This change breaks compatibility with
|
||||
all existing `.plan` file, but I'm releasing as a minor version because this
|
||||
project's API is still experimental (under version 1.x.x).
|
||||
|
||||
## [0.1.0] - 2017-08-13
|
||||
|
||||
Initial release.
|
10
README.md
10
README.md
@ -48,10 +48,10 @@ planning progress can be recorded.
|
||||
```
|
||||
master-plan - project management tool for hackers
|
||||
|
||||
Usage: master-plan [FILENAME] [-o|--output FILENAME] [--progress-below N]
|
||||
[-c|--color] [-w|--width NUMBER] [--height NUMBER]
|
||||
[-r|--root NAME]
|
||||
[--hide title|description|url|owner|cost|trust|progress]
|
||||
Usage: master-plan [FILENAME] [-o|--output FILENAME] [--progress-below N]
|
||||
[--render-parse-error] [-c|--color] [-w|--width NUMBER]
|
||||
[--height NUMBER] [-r|--root NAME]
|
||||
[--hide title|description|url|owner|cost|trust|progress]
|
||||
See documentation on how to write project plan files
|
||||
|
||||
Available options:
|
||||
@ -59,6 +59,8 @@ Available options:
|
||||
-o,--output FILENAME output file name (.png, .tif, .bmp, .jpg and .pdf
|
||||
supported)
|
||||
--progress-below N only display projects which progress is < N%
|
||||
--render-parse-error instead of printing parsing errors, render as an
|
||||
image
|
||||
-c,--color color each project by progress
|
||||
-w,--width NUMBER width of the output image
|
||||
--height NUMBER height of the output image
|
||||
|
17
app/Main.hs
17
app/Main.hs
@ -24,10 +24,11 @@ import System.Exit (die)
|
||||
import System.IO (stdin)
|
||||
|
||||
-- |Type output from the command line parser
|
||||
data Opts = Opts { inputPath :: Maybe FilePath
|
||||
, outputPath :: Maybe FilePath
|
||||
, projFilter :: ProjFilter -- ^ filter to consider
|
||||
, renderOptions :: RenderOptions }
|
||||
data Opts = Opts { inputPath :: Maybe FilePath
|
||||
, outputPath :: Maybe FilePath
|
||||
, projFilter :: ProjFilter -- ^ filter to consider
|
||||
, renderParsingError :: Bool -- ^ will render the parsing error instead of printing
|
||||
, renderOptions :: RenderOptions }
|
||||
deriving (Show)
|
||||
|
||||
newtype ProjFilter = ProjFilter (ProjectSystem → ProjectExpr → Bool)
|
||||
@ -50,6 +51,8 @@ cmdParser = Opts <$> optional (strArgument ( help "plan file to read from (defau
|
||||
<> help "output file name (.png, .tif, .bmp, .jpg and .pdf supported)"
|
||||
<> metavar "FILENAME" ))
|
||||
<*> (filterParser <|> pure noFilter)
|
||||
<*> switch ( long "render-parse-error"
|
||||
<> help "instead of printing parsing errors, render as an image")
|
||||
<*> renderOptionsParser
|
||||
where
|
||||
renderOptionsParser ∷ Parser RenderOptions
|
||||
@ -111,10 +114,12 @@ filterBinding _ _ b = Just b
|
||||
masterPlan ∷ Opts → IO ()
|
||||
masterPlan opts =
|
||||
do contents <- maybe (TIO.hGetContents stdin) TIO.readFile $ inputPath opts
|
||||
let outfile = fromMaybe (fromMaybe "output" (outputPath opts) ++ ".pdf") $ outputPath opts
|
||||
case P.runParser (fromMaybe "stdin" $ inputPath opts) contents of
|
||||
Left e -> die e
|
||||
Left e -> if renderParsingError opts
|
||||
then renderText outfile (renderOptions opts) (lines e)
|
||||
else die e
|
||||
Right sys@(ProjectSystem b) ->
|
||||
do let sys' = prioritizeSys $ ProjectSystem $ M.mapMaybe
|
||||
(filterBinding sys $ projFilter opts) b
|
||||
let outfile = fromMaybe (fromMaybe "output" (outputPath opts) ++ ".pdf") $ outputPath opts
|
||||
render outfile (renderOptions opts) sys'
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: master-plan
|
||||
version: 0.2.0.0
|
||||
version: 0.3.0
|
||||
synopsis: The project management tool for hackers
|
||||
description: Master Plan is a tool that parses files that describes
|
||||
projects using a simple and powerful syntax in which
|
||||
@ -23,6 +23,7 @@ category: Tools
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
extra-source-files: README.md
|
||||
, CHANGELOG.md
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
|
@ -12,7 +12,9 @@ Portability : POSIX
|
||||
{-# LANGUAGE NoMonomorphismRestriction #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE UnicodeSyntax #-}
|
||||
module MasterPlan.Backend.Graph (render, RenderOptions(..)) where
|
||||
module MasterPlan.Backend.Graph ( render
|
||||
, renderText
|
||||
, RenderOptions(..)) where
|
||||
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad.State
|
||||
@ -36,6 +38,22 @@ leftText = alignedText 0 0.5
|
||||
rightText :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any
|
||||
rightText = alignedText 1 0.5
|
||||
|
||||
-- |Render multiline text
|
||||
multilineText' :: (TypeableFloat n, Renderable (Text n) b)
|
||||
=> FontSlant
|
||||
-> FontWeight
|
||||
-> n -- ^line spacing
|
||||
-> [String] -- ^the lines of text to render
|
||||
-> QDiagram b V2 n Any
|
||||
multilineText' fs fw lineSpace = vsep lineSpace . map (texterific' fs fw)
|
||||
|
||||
-- |Render multiline text
|
||||
multilineText :: (TypeableFloat n, Renderable (Text n) b)
|
||||
=> n -- ^line spacing
|
||||
-> [String] -- ^the lines of text to render
|
||||
-> QDiagram b V2 n Any
|
||||
multilineText = multilineText' FontSlantNormal FontWeightNormal
|
||||
|
||||
-- |Render text with possible overflow by breaking lines and truncating with ...
|
||||
textOverflow' :: (TypeableFloat n, Renderable (Text n) b)
|
||||
=> FontSlant
|
||||
@ -138,6 +156,12 @@ render fp (RenderOptions colorByP w h rootK props) sys =
|
||||
dia = fromMaybe noRootEroor $ renderTree colorByP props <$> evalState (toRenderModel sys rootK) []
|
||||
in renderRasterific fp (dims2D (fromInteger w) (fromInteger h)) $ bgFrame 1 white $ centerXY dia
|
||||
|
||||
-- |Render a multi-line text to file
|
||||
renderText ∷ FilePath -> RenderOptions-> [String] → IO ()
|
||||
renderText fp RenderOptions { renderWidth=w, renderHeight=h } ss =
|
||||
let dia = multilineText (0.1 :: Float) ss
|
||||
in renderRasterific fp (dims2D (fromInteger w) (fromInteger h)) $ bgFrame 1 white $ centerXY dia
|
||||
|
||||
renderTree :: Bool -> [ProjAttribute] -> RenderModel -> QDiagram B V2 Double Any
|
||||
renderTree colorByP props (Node (_, n) []) = alignL $ renderNode colorByP props n
|
||||
renderTree colorByP props x@(Node (ty, n) ts@(t:_)) =
|
||||
|
Loading…
Reference in New Issue
Block a user