hledger-lib
Safe HaskellNone
LanguageGHC2021

Hledger.Write.Chart.Text

Description

Draw a Chart as text, for terminals.

Every chart is drawn as horizontal bars, one row per x position, with an aligned value column before the bars. Several series are drawn as stacked segments, positive values growing right from a zero axis and negative values growing left. Lines are drawn as bars too, since text has no good way to draw lines.

The output is a list of styled lines, so that different frontends can apply the styles in their own way: styledLinesAsText turns them into plain or ANSI-coloured text.

Synopsis

Documentation

data TextChartOpts Source #

Options for drawing a text chart.

Constructors

TextChartOpts 

Fields

  • tcWidth :: Int

    the width to fill, in characters (eg the terminal width)

  • tcUnicode :: Bool

    use unicode block characters (otherwise ASCII)

data Style Source #

How a piece of text should be shown.

Constructors

StylePlain 
StyleSeries Int

the colour of the Nth ordinary series in a panel

StyleType AccountType Int

the colour of a main account type, in its Nth variant

StyleOther (Maybe AccountType)

the colour of a series combining several items ("other"), of this main account type if any

StyleLone

the colour of a chart's only series, when it is not an account

StyleNegative

a negative value

Instances

Instances details
Eq Style Source # 
Instance details

Defined in Hledger.Write.Chart.Text

Methods

(==) :: Style -> Style -> Bool

(/=) :: Style -> Style -> Bool

Show Style Source # 
Instance details

Defined in Hledger.Write.Chart.Text

Methods

showsPrec :: Int -> Style -> ShowS

show :: Style -> String

showList :: [Style] -> ShowS

data ColourMode Source #

How to colour a text chart.

Constructors

NoColour 
BasicColour

with the terminal's basic ANSI colours (whose exact shades depend on its colour theme)

RgbColour Bool

with exact 24-bit colours, the same as SVG charts'; their variants for a dark background if true

Instances

Instances details
Eq ColourMode Source # 
Instance details

Defined in Hledger.Write.Chart.Text

Methods

(==) :: ColourMode -> ColourMode -> Bool

(/=) :: ColourMode -> ColourMode -> Bool

Show ColourMode Source # 
Instance details

Defined in Hledger.Write.Chart.Text

Methods

showsPrec :: Int -> ColourMode -> ShowS

show :: ColourMode -> String

showList :: [ColourMode] -> ShowS

type StyledLine = [(Style, Text)] Source #

A line of text made of styled pieces.

chartAsStyledLines :: TextChartOpts -> Chart -> [StyledLine] Source #

Draw a chart as styled lines of text: the title (if any), then each panel, with a heading naming its commodity when there are several (and it has a commodity symbol), and a legend (see legendListsSeries) listing the series that are visible (a series too small to fill a character cell is not). A chart of dates (eg a register) has a row per date, however many there are. A chart with no panels (nothing to show, eg in an empty period) says so.

styledLinesAsText :: ColourMode -> [StyledLine] -> Text Source #

Render styled lines as text, with ANSI colours or without.