From 3714ac0593a35c015b524a71abf4bb160ab1d180 Mon Sep 17 00:00:00 2001 From: Henning Thielemann Date: Mon, 21 Oct 2024 13:23:13 +0200 Subject: [PATCH] lib: Write.Ods.printFods: change type of number of fixed rows/columns from (Maybe Int) to Int 0 is a perfect value for no fixed row or column. --- hledger-lib/Hledger/Write/Ods.hs | 9 +++++---- hledger/Hledger/Cli/Commands/Aregister.hs | 2 +- hledger/Hledger/Cli/Commands/Balance.hs | 8 ++++---- hledger/Hledger/Cli/Commands/Print.hs | 2 +- hledger/Hledger/Cli/Commands/Register.hs | 4 +++- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hledger-lib/Hledger/Write/Ods.hs b/hledger-lib/Hledger/Write/Ods.hs index 4766a7fb4..1c1ad11f4 100644 --- a/hledger-lib/Hledger/Write/Ods.hs +++ b/hledger-lib/Hledger/Write/Ods.hs @@ -13,6 +13,7 @@ module Hledger.Write.Ods ( ) where import Prelude hiding (Applicative(..)) +import Control.Monad (guard) import Control.Applicative (Applicative(..)) import qualified Data.Text.Lazy as TL @@ -38,7 +39,7 @@ import Hledger.Data.Types (acommodity, aquantity, astyle, asprecision) printFods :: IO.TextEncoding -> - Map Text ((Maybe Int, Maybe Int), [[Cell Spr.NumLines Text]]) -> TL.Text + Map Text ((Int, Int), [[Cell Spr.NumLines Text]]) -> TL.Text printFods encoding tables = let fileOpen customStyles = map (map (\c -> case c of '\'' -> '"'; _ -> c)) $ @@ -87,14 +88,14 @@ printFods encoding tables = " " : " " : (fold $ - flip Map.mapWithKey tableNames $ \tableName (mTopRow,mLeftColumn) -> + flip Map.mapWithKey tableNames $ \tableName (topRow,leftColumn) -> printf " " tableName : - (flip foldMap mLeftColumn $ \leftColumn -> + ((guard (leftColumn>0) >>) $ " 2" : printf " %d" leftColumn : printf " %d" leftColumn : []) ++ - (flip foldMap mTopRow $ \topRow -> + ((guard (topRow>0) >>) $ " 2" : printf " %d" topRow : printf " %d" topRow : diff --git a/hledger/Hledger/Cli/Commands/Aregister.hs b/hledger/Hledger/Cli/Commands/Aregister.hs index fac8367e8..3d60f2804 100644 --- a/hledger/Hledger/Cli/Commands/Aregister.hs +++ b/hledger/Hledger/Cli/Commands/Aregister.hs @@ -121,7 +121,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do | fmt=="tsv" = printTSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq | fmt=="fods" = printFods IO.localeEncoding . Map.singleton "Aregister" . - (,) (Just 1, Nothing) . + (,) (1,0) . accountTransactionsReportAsSpreadsheet oneLineNoCostFmt wd (_rsQuery rspec') thisacctq | fmt=="json" = toJsonText | otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL: diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index d5678cde1..f5b718c97 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -394,7 +394,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of "html" -> (<>"\n") . L.renderText . printHtml . map (map (fmap L.toHtml)) . budgetReportAsSpreadsheet ropts "fods" -> printFods IO.localeEncoding . - Map.singleton "Budget Report" . (,) (Just 1, Nothing) . budgetReportAsSpreadsheet ropts + Map.singleton "Budget Report" . (,) (1,0) . budgetReportAsSpreadsheet ropts _ -> error' $ unsupportedOutputFormatError fmt writeOutputLazyText opts $ render budgetreport @@ -420,7 +420,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of "html" -> (<>"\n") . L.renderText . printHtml . map (map (fmap L.toHtml)) . balanceReportAsSpreadsheet ropts "json" -> (<>"\n") . toJsonText - "fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (Just 1, Nothing) . balanceReportAsSpreadsheet ropts + "fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (1,0) . balanceReportAsSpreadsheet ropts _ -> error' $ unsupportedOutputFormatError fmt -- PARTIAL: writeOutputLazyText opts $ render report where @@ -718,12 +718,12 @@ multiBalanceReportAsHtml ropts mbr = -- Returns the heading row, 0 or more body rows, and the totals row if enabled. multiBalanceReportAsSpreadsheet :: ReportOpts -> MultiBalanceReport -> - ((Maybe Int, Maybe Int), [[Ods.Cell Ods.NumLines Text]]) + ((Int, Int), [[Ods.Cell Ods.NumLines Text]]) multiBalanceReportAsSpreadsheet ropts mbr = let (header,body,total) = multiBalanceReportAsSpreadsheetParts oneLineNoCostFmt ropts mbr in (if transpose_ ropts then swap *** Ods.transpose else id) $ - ((Just 1, case layout_ ropts of LayoutWide _ -> Just 1; _ -> Nothing), + ((1, case layout_ ropts of LayoutWide _ -> 1; _ -> 0), header : body ++ total) diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index 7e8c33d72..3c81ebb5c 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -146,7 +146,7 @@ printEntries opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j = styleAmounts styles | fmt=="fods" = printFods IO.localeEncoding . Map.singleton "Print" . - (,) (Just 1, Nothing) . + (,) (1,0) . entriesReportAsSpreadsheet oneLineNoCostFmt baseUrl query . styleAmounts styles | otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL: diff --git a/hledger/Hledger/Cli/Commands/Register.hs b/hledger/Hledger/Cli/Commands/Register.hs index cac67b647..c55805570 100644 --- a/hledger/Hledger/Cli/Commands/Register.hs +++ b/hledger/Hledger/Cli/Commands/Register.hs @@ -108,7 +108,7 @@ register opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query | fmt=="fods" = printFods IO.localeEncoding . Map.singleton "Register" . - (,) (Just 1, Nothing) . + (,) (1,0) . postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query | otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL: where fmt = outputFormatFromOpts opts @@ -119,6 +119,8 @@ postingsReportAsCsv :: PostingsReport -> CSV postingsReportAsCsv = Spr.rawTableContent . postingsReportAsSpreadsheet machineFmt Nothing [] +-- ToDo: --layout=bare etc. +-- ToDo: Text output does not show headers, but Spreadsheet does postingsReportAsSpreadsheet :: AmountFormat -> Maybe Text -> [Text] -> PostingsReport -> [[Spr.Cell Spr.NumLines Text]] diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index cfc7e8d5e..b309be9ed 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -343,7 +343,7 @@ compoundBalanceReportAsHtml ropts cbr = compoundBalanceReportAsSpreadsheet :: AmountFormat -> T.Text -> Maybe T.Text -> ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> - (T.Text, ((Maybe Int, Maybe Int), NonEmpty [Spr.Cell Spr.NumLines T.Text])) + (T.Text, ((Int, Int), NonEmpty [Spr.Cell Spr.NumLines T.Text])) compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr = let CompoundPeriodicReport title colspans subreports totalrow = cbr @@ -397,5 +397,5 @@ compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr = & addTotalBorders -- marking the first row for special styling in (title, - ((Just 1, Just 1), + ((1,1), headerrow :| concatMap subreportrows subreports ++ totalrows))