hledger
Safe HaskellNone
LanguageGHC2021

Hledger.Cli.DocFiles

Description

Embedded documentation files in various formats, and helpers for viewing them.

|

Synopsis

Documentation

type Topic = String Source #

data TopicResolution Source #

The result of resolving a user-supplied topic against all the manuals' topics. A found match carries the tool whose manual it belongs to and the heading to scroll to; an ambiguous match carries the matching topic names, each with its manual heading level (for hierarchical listing).

Constructors

TopicNotFound 
TopicFound Tool Topic 
TopicAmbiguous [(Topic, Int)] 

manualTitle :: Tool -> Maybe Topic Source #

This tool's manual title, taken from the top running-header line (eg "HLEDGER(1) hledger User Manuals HLEDGER(1)"), with the "(N)" section number stripped (eg HLEDGER). Nothing if the manual has no such header. Note this title is not itself a line the viewers can scroll to, so callers resolving a topic to it should show the manual from the top.

manualHeadings :: Tool -> [(Topic, Int)] Source #

The section headings in this tool's manual, each with its hierarchy level, usable as help topics. Some heading hierarchy is lost in the rendered plain text, but we recover an approximate level for each: the manual title (see manualTitle) is level 1; an all-caps column-0 heading (eg OPTIONS, PART 1: ...) is level 2; any other column-0 heading (eg Options, Journal) is level 3; and a heading indented three spaces is level 4. Headings are non-blank lines at the left margin or indented exactly three spaces, containing no run of two or more spaces (which would indicate wrapped prose, a table, an option entry, or a running header). The standard man-page headings NAME, SYNOPSIS and DESCRIPTION are dropped, as they aren't useful topics and their generic names could clash with real ones.

manualTopicsMatching :: Topic -> [(Topic, Int)] Source #

The topic names (each with its manual heading level, for hierarchical listing) that contain the given topic as a case-insensitive substring (all topics if the topic is empty). Used by help's -l list mode.

resolveManualTopic :: Topic -> TopicResolution Source #

Resolve a topic to a manual section, searching all the manuals' topic names. A case-insensitive exact match wins; otherwise a unique prefix match is used; otherwise a unique infix match is used. Resolving to a heading (and its tool) lets all viewers (including info and the web anchor) locate the section reliably, and lets callers respond to a bad topic. When the match is ambiguous, all matches of any kind (ie all infix matches) are listed.

printHelpForTopic :: Tool -> Maybe Topic -> IO () Source #

Print plain text help for this tool. This is the fallback "viewer" used for non-interactive output or a dumb terminal, where no pager is available. To avoid dumping the whole (large) manual, when no topic is requested we print only the introduction: everything up to and including the DESCRIPTION section (ie stopping at the first all-caps top-level heading after it, such as PART 1), followed by a note on how to read the rest. If a topic is requested, or there's no DESCRIPTION heading (eg the hledger-ui/hledger-web manuals), the whole manual is printed.

runManForTopic :: Tool -> Maybe Topic -> IO () Source #

Display a man page for this tool, scrolled to the given topic if provided, using "man". When a topic is provided we force man to use "less", ignoring $MANPAGER and $PAGER.

runInfoForTopic :: Tool -> Maybe Topic -> IO () Source #

Display an info manual for this topic, opened at the given topic if provided, using the "info" executable in $PATH. Topic can be an exact heading or a heading prefix; info will favour an exact match.

runPagerForTopic :: Tool -> Maybe Topic -> IO () Source #

Display plain text help for this tool, scrolled to the given topic if any, using the users $PAGER or "less". When a topic is provided we always use less, ignoring $PAGER.

This is less robust than the newer Hledger.Utils.IO.runPager, but that one doesn't yet support scrolling to a topic.

runTldrForPage :: TldrPage -> IO () Source #

Display one of the hledger tldr pages, using "tldr".