Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hledger-lib/Hledger/Reports/ReportOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ instance Default AccountListMode where def = ALFlat
data Layout = LayoutWide (Maybe Int)
| LayoutTall
| LayoutBare
| LayoutBareWide
| LayoutTidy
deriving (Eq, Show)

Expand Down Expand Up @@ -432,6 +433,7 @@ layoutopt rawopts = fromMaybe (LayoutWide Nothing) $ layout <|> column
, ("tall", LayoutTall)
, ("bare", LayoutBare)
, ("tidy", LayoutTidy)
, ("barewide", LayoutBareWide)
]
-- For `--layout=elided,n`, elide to the given width
(s,n) = break (==',') $ map toLower opt
Expand All @@ -440,7 +442,7 @@ layoutopt rawopts = fromMaybe (LayoutWide Nothing) $ layout <|> column
c | Just w' <- readMay c -> Just w'
_ -> usageError "width in --layout=wide,WIDTH must be an integer"

err = usageError "--layout's argument should be \"wide[,WIDTH]\", \"tall\", \"bare\", or \"tidy\""
err = usageError "--layout's argument should be \"wide[,WIDTH]\", \"tall\", \"bare\", \"barewide\", or \"tidy\""

-- Get the period specified by any -b/--begin, -e/--end and/or -p/--period
-- options appearing in the command line.
Expand Down
10 changes: 6 additions & 4 deletions hledger-lib/Hledger/Write/Html/Blaze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ formatCell cell =
let class_ =
map (HtmlAttr.class_ . Html.textValue) $
filter (not . Text.null) [Spr.textFromClass $ cellClass cell] in
let addSpan spanAttr n attrs =
if n==1
then attrs
else spanAttr (Html.stringValue $ show n) : attrs in
let span_ makeCell attrs =
case Spr.cellSpan cell of
Spr.NoSpan -> foldl (!) makeCell attrs
Spr.Covered -> pure ()
Spr.SpanHorizontal n ->
foldl (!) makeCell
(HtmlAttr.colspan (Html.stringValue $ show n) : attrs)
foldl (!) makeCell (addSpan HtmlAttr.colspan n attrs)
Spr.SpanVertical n ->
foldl (!) makeCell
(HtmlAttr.rowspan (Html.stringValue $ show n) : attrs)
foldl (!) makeCell (addSpan HtmlAttr.rowspan n attrs)
in
case cellStyle cell of
Head -> span_ (Html.th content) (style++class_)
Expand Down
8 changes: 6 additions & 2 deletions hledger-lib/Hledger/Write/Html/Lucid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ formatCell cell =
[filter (not . Text.null) $
Spr.textFromClass (cellClass cell) :
["date" | cellType cell == TypeDate]] in
let addSpan spanAttr n attrs =
if n==1
then attrs
else spanAttr (Text.pack $ show n) : attrs in
let span_ makeCell attrs cont =
case Spr.cellSpan cell of
Spr.NoSpan -> makeCell attrs cont
Spr.Covered -> pure ()
Spr.SpanHorizontal n ->
makeCell (L.colspan_ (Text.pack $ show n) : attrs) cont
makeCell (addSpan L.colspan_ n attrs) cont
Spr.SpanVertical n ->
makeCell (L.rowspan_ (Text.pack $ show n) : attrs) cont
makeCell (addSpan L.rowspan_ n attrs) cont
in
case cellStyle cell of
Head -> span_ L.th_ (style++class_) content
Expand Down
22 changes: 15 additions & 7 deletions hledger-lib/Hledger/Write/Spreadsheet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Hledger.Write.Spreadsheet (
horizontalSpan,
addHeaderBorders,
addRowSpanHeader,
addRowSpanHeaderNE,
rawTableContent,
cellFromMixedAmount,
cellsFromMixedAmount,
Expand All @@ -32,6 +33,8 @@ import Hledger.Data.Amount qualified as Amt
import Hledger.Data.Types (Amount, MixedAmount, acommodity)
import Hledger.Data.Amount (AmountFormat)

import Data.Foldable qualified as Fold
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.List qualified as List
import Data.Maybe (isNothing)
import Data.Text qualified as Text
Expand Down Expand Up @@ -189,9 +192,9 @@ transpose :: [[Cell border text]] -> [[Cell border text]]
transpose = List.transpose . map (map transposeCell)


addHeaderBorders :: [Cell () text] -> [Cell NumLines text]
addHeaderBorders :: (Functor f) => f (Cell () text) -> f (Cell NumLines text)
addHeaderBorders =
map (\c -> c {cellBorder = noBorder {borderBottom = DoubleLine}})
fmap (\c -> c {cellBorder = noBorder {borderBottom = DoubleLine}})

horizontalSpan ::
(Lines border, Monoid text) =>
Expand All @@ -205,18 +208,23 @@ horizontalSpan subCells cell =
addRowSpanHeader ::
Cell border text ->
[[Cell border text]] -> [[Cell border text]]
addRowSpanHeader header rows =
addRowSpanHeader header = map Fold.toList . addRowSpanHeaderNE header

addRowSpanHeaderNE ::
Cell border text ->
[[Cell border text]] -> [NonEmpty (Cell border text)]
addRowSpanHeaderNE header rows =
case rows of
[] -> []
[row] -> [header:row]
[row] -> [header:|row]
_ ->
zipWith (:)
zipWith (:|)
(header{cellSpan = SpanVertical (length rows)} :
repeat header{cellSpan = Covered})
rows

rawTableContent :: [[Cell border text]] -> [[text]]
rawTableContent = map (map cellContent)
rawTableContent :: (Functor f) => [f (Cell border text)] -> [f text]
rawTableContent = map (fmap cellContent)



Expand Down
Loading