Permalink
Browse files

WIP

  • Loading branch information...
massysett committed Aug 8, 2012
1 parent ea2a2e4 commit d666164f4d1a65b29faa287e185634b4d77b8908
@@ -50,8 +50,8 @@ import qualified Penny.Cabin.Colors as PC
import qualified Penny.Cabin.Posts.Growers as G
import qualified Penny.Cabin.Posts.Meta as M
import Penny.Cabin.Posts.Meta (Box)
-import qualified Penny.Cabin.Posts.Options as O
import qualified Penny.Cabin.Posts.Spacers as S
+import qualified Penny.Cabin.Posts.Types as Ty
import qualified Penny.Cabin.TextFormat as TF
import qualified Penny.Lincoln as L
import qualified Penny.Lincoln.Queries as Q
@@ -75,7 +75,7 @@ data AllocatedOpts = AllocatedOpts {
, accountAllocation :: A.Allocation
, spacers :: S.Spacers Int
, growerWidths :: G.Fields (Maybe Int)
- , reportWidth :: O.ReportWidth
+ , reportWidth :: Ty.ReportWidth
}
-- | Creates Payee and Account cells. The user must have requested the
@@ -143,9 +143,9 @@ fieldWidth ::
-> A.Allocation -- ^ Accout allocation
-> S.Spacers Int
-> G.Fields (Maybe Int)
- -> O.ReportWidth
+ -> Ty.ReportWidth
-> Fields UnShrunkWidth
-fieldWidth flds pa aa ss fs (O.ReportWidth rw) =
+fieldWidth flds pa aa ss fs (Ty.ReportWidth rw) =
let grownWidth = sumGrowersAndSpacers fs ss
widthForCells = rw - grownWidth - allocSpacerWidth
payeeSpacerWidth = if payee flds then abs (S.payee ss) else 0
@@ -40,8 +40,8 @@ import qualified Penny.Cabin.Posts.Fields as F
import qualified Penny.Cabin.Posts.Growers as G
import qualified Penny.Cabin.Posts.Meta as M
import Penny.Cabin.Posts.Meta (Box)
-import qualified Penny.Cabin.Posts.Options as O
import qualified Penny.Cabin.Posts.Spacers as S
+import qualified Penny.Cabin.Posts.Types as Ty
import qualified Penny.Lincoln as L
import qualified Penny.Lincoln.HasText as HT
import qualified Penny.Lincoln.Queries as Q
@@ -51,7 +51,7 @@ data BottomOpts = BottomOpts {
, allocatedWidths :: A.Fields (Maybe Int)
, fields :: F.Fields Bool
, baseColors :: PC.BaseColors
- , reportWidth :: O.ReportWidth
+ , reportWidth :: Ty.ReportWidth
, spacers :: S.Spacers Int
}
@@ -141,16 +141,16 @@ widthOfTopColumns ts =
widthOfReport ::
- O.ReportWidth
+ Ty.ReportWidth
-> (Box -> Int -> (C.TextSpec, R.ColumnSpec))
-> Box
-> [C.Chunk]
-widthOfReport (O.ReportWidth rw) fn info =
+widthOfReport (Ty.ReportWidth rw) fn info =
makeSpecificWidth rw fn info
chooseProcessor ::
[TopCellSpec]
- -> O.ReportWidth
+ -> Ty.ReportWidth
-> (Box -> Int -> (C.TextSpec, R.ColumnSpec))
-> Box
-> [C.Chunk]
@@ -163,7 +163,7 @@ chooseProcessor specs rw fn = let
infoProcessors ::
[TopCellSpec]
- -> O.ReportWidth
+ -> Ty.ReportWidth
-> Fields (Maybe (Box -> Int -> (C.TextSpec, R.ColumnSpec)))
-> Fields (Maybe (Box -> [C.Chunk]))
infoProcessors specs rw flds = let
@@ -15,8 +15,7 @@ import qualified Penny.Cabin.Colors as PC
import Penny.Cabin.Posts.Meta (Box)
import qualified Penny.Lincoln as L
import qualified Data.Text as X
-import qualified Penny.Cabin.Posts.Options as O
-
+import qualified Penny.Cabin.Posts.Types as Ty
data ChunkOpts = ChunkOpts {
baseColors :: PC.BaseColors
@@ -29,7 +28,7 @@ data ChunkOpts = ChunkOpts {
, payeeAllocation :: Alc.Allocation
, accountAllocation :: Alc.Allocation
, spacers :: S.Spacers Int
- , reportWidth :: O.ReportWidth
+ , reportWidth :: Ty.ReportWidth
}
growOpts :: ChunkOpts -> G.GrowOpts
@@ -17,6 +17,7 @@ import qualified Penny.Cabin.Chunk as CC
import qualified Penny.Cabin.Colors as C
import qualified Penny.Cabin.Options as O
import qualified Penny.Cabin.Posts.Fields as F
+import qualified Penny.Cabin.Posts.Types as T
import Penny.Cabin.Posts.Meta (Box)
import qualified Penny.Cabin.Posts.Spacers as S
import Penny.Copper.DateTime (DefaultTimeZone)
@@ -58,7 +59,7 @@ data Options =
, accountAllocation :: A.Allocation
-- ^ See payeeAllocation above
- , width :: ReportWidth
+ , width :: T.ReportWidth
-- ^ Gives the default report width. This can be
-- overridden on the command line. You can use the
-- information from the Runtime to make this as wide as
@@ -113,6 +114,4 @@ data Options =
, showZeroBalances :: O.ShowZeroBalances
}
-newtype ReportWidth = ReportWidth { unReportWidth :: Int }
- deriving (Eq, Show, Ord)
@@ -11,15 +11,19 @@ import System.Console.MultiArg.Prim (Parser)
import qualified Penny.Cabin.Chunk as CC
import qualified Penny.Cabin.Colors as PC
import qualified Penny.Cabin.Posts.Fields as F
+import Penny.Cabin.Posts.Meta (Box)
import qualified Penny.Cabin.Posts.Options as O
import qualified Penny.Cabin.Posts.Options as Op
+import qualified Penny.Cabin.Posts.Types as Ty
import qualified Penny.Cabin.Colors.DarkBackground as DB
import qualified Penny.Cabin.Colors.LightBackground as LB
import qualified Penny.Cabin.Options as CO
+import qualified Penny.Copper as Cop
import qualified Penny.Liberty as Ly
import qualified Penny.Liberty.Expressions as Exp
import qualified Penny.Lincoln as L
import qualified Penny.Shield as S
+import qualified Text.Matchers.Text as M
data Error = BadColorName String
| BadBackgroundArg String
@@ -31,6 +35,19 @@ data Error = BadColorName String
| BadComparator String
deriving Show
+data State = State {
+ sensitive :: M.CaseSensitive
+ , factory :: L.Factory
+ , tokens :: [Ly.Token (Box -> Bool)]
+ , postFilter :: [Ly.PostFilterFn]
+ , fields :: F.Fields Bool
+ , colorPref :: CC.Colors
+ , drCrColors :: PC.DrCrColors
+ , baseColors :: PC.BaseColors
+ , width :: Ty.ReportWidth
+ , showZeroBalances :: CO.ShowZeroBalances
+ }
+
-- | Parses the command line from the first word remaining up until,
-- but not including, the first non-option argment.
parseOptions ::
@@ -48,18 +65,18 @@ parseOption ::
parseOption =
operand
<|> mkTwoArg boxFilters
- <|> mkTwoArg postFilter
+ <|> mkTwoArg parsePostFilter
<|> mkTwoArg matcherSelect
<|> mkTwoArg caseSelect
<|> mkTwoArg operator
<|> color
<|> mkTwoArg background
- <|> mkTwoArg width
+ <|> mkTwoArg parseWidth
<|> mkTwoArg showField
<|> mkTwoArg hideField
<|> mkTwoArg showAllFields
<|> mkTwoArg hideAllFields
- <|> mkTwoArg showZeroBalances
+ <|> mkTwoArg parseShowZeroBalances
<|> mkTwoArg hideZeroBalances
where
mkTwoArg p = do
@@ -139,8 +156,8 @@ boxFilters =
<|> optRevSortedNum
-postFilter :: Parser (O.Options -> Ex.Exceptional Error O.Options)
-postFilter = f <$> Ly.parsePostFilter
+parsePostFilter :: Parser (O.Options -> Ex.Exceptional Error O.Options)
+parsePostFilter = f <$> Ly.parsePostFilter
where
f ex op =
case ex of
@@ -197,11 +214,11 @@ background = parseOpt ["background"] "" (C.OneArg f)
, Op.baseColors = bc } )
-width :: Parser (O.Options -> Ex.Exceptional Error O.Options)
-width = parseOpt ["width"] "" (C.OneArg f)
+parseWidth :: Parser (O.Options -> Ex.Exceptional Error O.Options)
+parseWidth = parseOpt ["width"] "" (C.OneArg f)
where
f a1 op = case reads a1 of
- (i, ""):[] -> return (op { Op.width = Op.ReportWidth i })
+ (i, ""):[] -> return (op { Op.width = Ty.ReportWidth i })
_ -> Ex.throw . BadWidthArg $ a1
showField :: Parser (O.Options -> Ex.Exceptional Error O.Options)
@@ -230,9 +247,11 @@ hideAllFields = parseOpt ["hide-all"] "" (C.NoArg f)
where
f op = return (op {Op.fields = pure False})
-showZeroBalances :: Parser (O.Options -> Ex.Exceptional a O.Options)
-showZeroBalances = parseOpt ["show-zero-balances"] "" (C.NoArg f)
+parseShowZeroBalances ::
+ Parser (O.Options -> Ex.Exceptional a O.Options)
+parseShowZeroBalances = parseOpt opt "" (C.NoArg f)
where
+ opt = ["show-zero-balances"]
f op =
return (op {Op.showZeroBalances = CO.ShowZeroBalances True })
@@ -0,0 +1,4 @@
+module Penny.Cabin.Posts.Types where
+
+newtype ReportWidth = ReportWidth { unReportWidth :: Int }
+ deriving (Eq, Show, Ord)
View
@@ -213,6 +213,7 @@ Library
Penny.Cabin.Posts.Options,
Penny.Cabin.Posts.Parser,
Penny.Cabin.Posts.Spacers,
+ Penny.Cabin.Posts.Types,
Penny.Cabin.Posts.ZincOpts,
Penny.Cabin.Row,
Penny.Cabin.TextFormat,

0 comments on commit d666164

Please sign in to comment.