| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Lipstick.Outline
Contents
Description
Lists and trees.
Both are outlines: items with an enumerator (a bullet, a number, a tree
branch) and nested items indented below them. A tree has a root;
forest, list and nestedList do not. By default tree and forest
use tree branches, list and nestedList bullets.
Items are blocks, so anything can go in an outline, tables included.
Examples
>>>let os = Node "." [Node "macOS" [], Node "Linux" [Node "NixOS" [], Node "Arch" []], Node "BSD" []]>>>putBlock (tree mempty os). ├── macOS ├── Linux │ ├── NixOS │ └── Arch └── BSD>>>putBlock (tree (enumerator roundedTreeEnumerator) os). ├── macOS ├── Linux │ ├── NixOS │ ╰── Arch ╰── BSD
>>>let shops = ["Glossier", "Claire's Boutique", "Nyx"]>>>putBlock (list mempty shops)• Glossier • Claire's Boutique • Nyx>>>putBlock (list (enumerator arabic) shops)1. Glossier 2. Claire's Boutique 3. Nyx
Nested lists, with an enumerator for each depth:
>>>let products = [Node "Glossier" [Node "Cloud Paint" [], Node "Boy Brow" []], Node "Nyx" []]>>>putBlock (nestedList (enumerator (byDepth (\d -> if d == 0 then roman else dash))) products)I. Glossier - Cloud Paint - Boy Brow II. Nyx
Items wrap in the width left after their enumerator:
>>>putBlock (fromGrid (layout (Just 16) (list mempty ["A long item that wraps", "short"])))• A long item that wraps • short
Items can be styled by position, and are blocks themselves:
>>>putBlock (list (itemStyleWith (\p -> if isLast p then border roundedBorder else mempty)) ["one", "two", "last"])• one • two • ╭────╮ │last│ ╰────╯
An enumerator of your own:
>>>let arrows = markers (const "→ ")>>>putBlock (list (enumerator arrows) shops)→ Glossier → Claire's Boutique → Nyx
Synopsis
- data Outline
- tree :: Mod Outline -> Tree Block -> Block
- forest :: Mod Outline -> Forest Block -> Block
- list :: Mod Outline -> [Block] -> Block
- nestedList :: Mod Outline -> Forest Block -> Block
- data ItemPos
- rootStyle :: Mod Style -> Mod Outline
- itemStyle :: Mod Style -> Mod Outline
- itemStyleWith :: (ItemPos -> Mod Style) -> Mod Outline
- enumeratorStyle :: Mod Style -> Mod Outline
- enumeratorStyleWith :: (ItemPos -> Mod Style) -> Mod Outline
- indenterStyle :: Mod Style -> Mod Outline
- indenterStyleWith :: (ItemPos -> Mod Style) -> Mod Outline
- itemOffset :: Int -> Int -> Mod Outline
- data Enumerator
- markers :: (ItemPos -> Text) -> Enumerator
- enumerator :: Enumerator -> Mod Outline
- byDepth :: (Int -> Enumerator) -> Enumerator
- isLast :: ItemPos -> Bool
- indenter :: (ItemPos -> Text) -> Mod Outline
- treeEnumerator :: Enumerator
- roundedTreeEnumerator :: Enumerator
- bullet :: Enumerator
- dash :: Enumerator
- asterisk :: Enumerator
- arabic :: Enumerator
- alphabet :: Enumerator
- roman :: Enumerator
Documentation
The settings of a list or tree: its enumerator and indenter, the
styles of the root, items, enumerators and indentation, its size, and
the items it shows. Change them with the passed to
Mod Outlinetree, forest, list or nestedList.
Items are laid out in the width left after their indentation and
enumerator, so their text wraps to fit. width is the width of the
outline when there is room for it, as for a style: items wrap to fit it,
and every line is padded to it with the background of its item's style.
fillWidth pads to the width the outline is given, and height pads
with blank lines up to that many.
tree :: Mod Outline -> Tree Block -> Block Source #
A tree: the root, then its children, with tree branches by default.
forest :: Mod Outline -> Forest Block -> Block Source #
Trees without a common root, with tree branches by default.
nestedList :: Mod Outline -> Forest Block -> Block Source #
A list whose items can have nested items, with bullets by default.
Styling
Where an item is: its depth (0 for the top level), its index among its
siblings (from 0), and how many siblings there are, itself included. At
the top level, only the items that itemOffset shows count.
itemStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #
Style items by position. Successive item styles add up.
enumeratorStyle :: Mod Style -> Mod Outline Source #
Style every enumerator (and the indentation below it).
enumeratorStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #
Style enumerators by position. Successive enumerator styles add up.
indenterStyle :: Mod Style -> Mod Outline Source #
Style the indentation before an item's further lines and its children. Until an indenter style is set, the enumerator style is used.
indenterStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #
Style the indentation by position. Successive indenter styles add up.
itemOffset :: Int -> Int -> Mod Outline Source #
itemOffset start end shows only part of the top-level items, leaving
out start at the beginning and end at the end. Enumerators and
ItemPos count only the items shown.
Enumerators
data Enumerator Source #
How items are marked. Markers of different widths at one level are
right-aligned to the widest. Make one with markers, and change its
fields with record update syntax:
>>>let arrows = (markers (\p -> if isLast p then "└> " else "├> ")) {enumIndent = \p -> Just (if isLast p then " " else "│ ")}>>>putBlock (tree (enumerator arrows) (Node "root" [Node "a" [Node "a.1" []], Node "b" []]))root ├> a │ └> a.1 └> b
markers :: (ItemPos -> Text) -> Enumerator Source #
An enumerator with these markers, and further lines and children indented by spaces as wide as the widest marker at their level.
>>>putBlock (list (enumerator (markers (\p -> if isLast p then "> " else "- "))) ["a", "b", "c"])- a - b > c
enumerator :: Enumerator -> Mod Outline Source #
Mark items with this enumerator.
>>>putBlock (nestedList (enumerator (byDepth (\d -> if d == 0 then roman else bullet))) [Node "one" [Node "two" []]])I. one • two
byDepth :: (Int -> Enumerator) -> Enumerator Source #
An enumerator chosen by depth (0 for the top level).
indenter :: (ItemPos -> Text) -> Mod Outline Source #
What goes before an item's further lines and its children, instead of the enumerator's own indentation.
treeEnumerator :: Enumerator Source #
├── and └── , with │ continuing the branch.
roundedTreeEnumerator :: Enumerator Source #
Like treeEnumerator with a rounded last branch: ╰── .
bullet :: Enumerator Source #
•
dash :: Enumerator Source #
-
asterisk :: Enumerator Source #
*
arabic :: Enumerator Source #
1. , 2. , …
alphabet :: Enumerator Source #
A. , B. , … Z. , AA. , …
roman :: Enumerator Source #
I. , II. , III. , IV. , …