hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Data.StringFormat

Description

Parse format strings provided by --format, with awareness of hledger's report item fields. The formats are used by report-specific renderers like renderBalanceReportItem.

Synopsis

- parseStringFormat :: Text -> Either String StringFormat
- defaultStringFormatStyle :: [StringFormatComponent] -> StringFormat
- data StringFormat
  - = OneLine [StringFormatComponent]
  - | TopAligned [StringFormatComponent]
  - | BottomAligned [StringFormatComponent]
- data StringFormatComponent
  - = FormatLiteral Text
  - | FormatField Bool (Maybe Int) (Maybe Int) ReportItemField
- data ReportItemField
  - = AccountField
  - | DefaultDateField
  - | DescriptionField
  - | TotalField
  - | DepthSpacerField
  - | FieldNo Int
- defaultBalanceLineFormat :: StringFormat
- tests_StringFormat :: TestTree

# Documentation

parseStringFormat :: Text -> Either String StringFormat #

Parse a string format specification, or return a parse error.

defaultStringFormatStyle :: [StringFormatComponent] -> StringFormat #

data StringFormat #

A format specification/template to use when rendering a report line item as text.

A format is a sequence of components; each is either a literal string, or a hledger report item field with specified width and justification whose value will be interpolated at render time.

A component's value may be a multi-line string (or a multi-commodity amount), in which case the final string will be either single-line or a top or bottom-aligned multi-line string depending on the StringFormat variant used.

Currently this is only used in the balance command's single-column mode, which provides a limited StringFormat renderer.

Constructors

OneLine [StringFormatComponent] | multi-line values will be rendered on one line, comma-separated
TopAligned [StringFormatComponent] | values will be top-aligned (and bottom-padded to the same height)
BottomAligned [StringFormatComponent] | values will be bottom-aligned (and top-padded)

#### Instances

Instances details

Default StringFormat # |
Instance details Defined in Hledger.Data.StringFormat Methods def :: StringFormat #
Show StringFormat # |
Instance details Defined in Hledger.Data.StringFormat Methods showsPrec :: Int -> StringFormat -> ShowS # show :: StringFormat -> String # showList :: [StringFormat] -> ShowS #
Eq StringFormat # |
Instance details Defined in Hledger.Data.StringFormat Methods (==) :: StringFormat -> StringFormat -> Bool # (/=) :: StringFormat -> StringFormat -> Bool #

data StringFormatComponent #

Constructors

FormatLiteral Text | Literal text to be rendered as-is

FormatField Bool (Maybe Int) (Maybe Int) ReportItemField

A data field to be formatted and interpolated. Parameters:

- Left justify ? Right justified if false
- Minimum width ? Will be space-padded if narrower than this
- Maximum width ? Will be clipped if wider than this
- Which of the standard hledger report item fields to interpolate

#### Instances

Instances details

Show StringFormatComponent # |
Instance details Defined in Hledger.Data.StringFormat Methods showsPrec :: Int -> StringFormatComponent -> ShowS # show :: StringFormatComponent -> String # showList :: [StringFormatComponent] -> ShowS #
Eq StringFormatComponent # |
Instance details Defined in Hledger.Data.StringFormat Methods (==) :: StringFormatComponent -> StringFormatComponent -> Bool # (/=) :: StringFormatComponent -> StringFormatComponent -> Bool #

data ReportItemField #

An id identifying which report item field to interpolate. These are drawn from several hledger report types, so are not all applicable for a given report.

Constructors

AccountField | A posting or balance report item's account name
DefaultDateField | A posting or register or entry report item's date
DescriptionField | A posting or register or entry report item's description
TotalField | A balance or posting report item's balance or running total. Always rendered right-justified.
DepthSpacerField | A balance report item's indent level (which may be different from the account name depth). Rendered as this number of spaces, multiplied by the minimum width spec if any.
FieldNo Int | A report item's nth field. May be unimplemented.

#### Instances

Instances details

Show ReportItemField # |
Instance details Defined in Hledger.Data.StringFormat Methods showsPrec :: Int -> ReportItemField -> ShowS # show :: ReportItemField -> String # showList :: [ReportItemField] -> ShowS #
Eq ReportItemField # |
Instance details Defined in Hledger.Data.StringFormat Methods (==) :: ReportItemField -> ReportItemField -> Bool # (/=) :: ReportItemField -> ReportItemField -> Bool #

defaultBalanceLineFormat :: StringFormat #

Default line format for balance report: "%20(total) %2(depth_spacer)%-(account)"

tests_StringFormat :: TestTree #